foxygit / doom Log in
commit 968c30b02484585d03ed757b317a39b2f6a15556
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Sat Oct 8 18:22:46 2005 +0000
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Sat Oct 8 18:22:46 2005 +0000

    Store the cache as part of the lumpinfo_t struct. Add W_AddFile prototype
    to header.

    Subversion-branch: /trunk/chocolate-doom
    Subversion-revision: 167
---
 src/w_wad.c | 37 +++++++++++++++----------------------
 src/w_wad.h |  8 +++++++-
 2 files changed, 22 insertions(+), 23 deletions(-)

diff --git a/src/w_wad.c b/src/w_wad.c
index 1d169f6c..40cefef3 100644
--- a/src/w_wad.c
+++ b/src/w_wad.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*-
 //-----------------------------------------------------------------------------
 //
-// $Id: w_wad.c 58 2005-08-30 22:15:11Z fraggle $
+// $Id: w_wad.c 167 2005-10-08 18:22:46Z fraggle $
 //
 // Copyright(C) 1993-1996 Id Software, Inc.
 // Copyright(C) 2005 Simon Howard
@@ -22,6 +22,10 @@
 // 02111-1307, USA.
 //
 // $Log$
+// Revision 1.8  2005/10/08 18:22:46  fraggle
+// Store the cache as part of the lumpinfo_t struct.  Add W_AddFile prototype
+// to header.
+//
 // Revision 1.7  2005/08/30 22:15:11  fraggle
 // More Windows fixes
 //
@@ -51,7 +55,7 @@


 static const char
-rcsid[] = "$Id: w_wad.c 58 2005-08-30 22:15:11Z fraggle $";
+rcsid[] = "$Id: w_wad.c 167 2005-10-08 18:22:46Z fraggle $";


 #include <ctype.h>
@@ -80,9 +84,6 @@ rcsid[] = "$Id: w_wad.c 58 2005-08-30 22:15:11Z fraggle $";
 lumpinfo_t*		lumpinfo;
 int			numlumps;

-void**			lumpcache;
-
-
 #define strcmpi	strcasecmp

 void string_to_upper (char* s)
@@ -244,6 +245,7 @@ void W_AddFile (char *filename)
 	lump_p->handle = storehandle;
 	lump_p->position = LONG(filerover->filepos);
 	lump_p->size = LONG(filerover->size);
+        lump_p->cache = NULL;
 	strncpy (lump_p->name, filerover->name, 8);
     }

@@ -292,8 +294,8 @@ void W_Reload (void)
 	 i<reloadlump+lumpcount ;
 	 i++,lump_p++, fileinfo++)
     {
-	if (lumpcache[i])
-	    Z_Free (lumpcache[i]);
+	if (lumpinfo[i].cache)
+	    Z_Free (lumpinfo[i].cache);

 	lump_p->position = LONG(fileinfo->filepos);
 	lump_p->size = LONG(fileinfo->size);
@@ -334,15 +336,6 @@ void W_InitMultipleFiles (char** filenames)

     if (!numlumps)
 	I_Error ("W_InitFiles: no files found");
-
-    // set up caching
-    size = numlumps * sizeof(*lumpcache);
-    lumpcache = malloc (size);
-
-    if (!lumpcache)
-	I_Error ("Couldn't allocate lumpcache");
-
-    memset (lumpcache,0, size);
 }


@@ -512,21 +505,21 @@ W_CacheLumpNum
     if ((unsigned)lump >= numlumps)
 	I_Error ("W_CacheLumpNum: %i >= numlumps",lump);

-    if (!lumpcache[lump])
+    if (!lumpinfo[lump].cache)
     {
 	// read the lump in

 	//printf ("cache miss on lump %i\n",lump);
-	ptr = Z_Malloc (W_LumpLength (lump), tag, &lumpcache[lump]);
-	W_ReadLump (lump, lumpcache[lump]);
+	ptr = Z_Malloc (W_LumpLength (lump), tag, &lumpinfo[lump].cache);
+	W_ReadLump (lump, lumpinfo[lump].cache);
     }
     else
     {
 	//printf ("cache hit on lump %i\n",lump);
-	Z_ChangeTag (lumpcache[lump],tag);
+	Z_ChangeTag (lumpinfo[lump].cache,tag);
     }

-    return lumpcache[lump];
+    return lumpinfo[lump].cache;
 }


@@ -562,7 +555,7 @@ void W_Profile (void)

     for (i=0 ; i<numlumps ; i++)
     {
-	ptr = lumpcache[i];
+	ptr = lumpinfo[i].cache;
 	if (!ptr)
 	{
 	    ch = ' ';
diff --git a/src/w_wad.h b/src/w_wad.h
index f0c31391..2fa4117b 100644
--- a/src/w_wad.h
+++ b/src/w_wad.h
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*-
 //-----------------------------------------------------------------------------
 //
-// $Id: w_wad.h 16 2005-07-23 18:54:06Z fraggle $
+// $Id: w_wad.h 167 2005-10-08 18:22:46Z fraggle $
 //
 // Copyright(C) 1993-1996 Id Software, Inc.
 // Copyright(C) 2005 Simon Howard
@@ -64,6 +64,7 @@ typedef struct
     FILE       *handle;
     int		position;
     int		size;
+    void       *cache;
 } lumpinfo_t;


@@ -71,6 +72,7 @@ extern	void**		lumpcache;
 extern	lumpinfo_t*	lumpinfo;
 extern	int		numlumps;

+void    W_AddFile (char *filename);
 void    W_InitMultipleFiles (char** filenames);
 void    W_Reload (void);

@@ -90,6 +92,10 @@ void*	W_CacheLumpName (char* name, int tag);
 //-----------------------------------------------------------------------------
 //
 // $Log$
+// Revision 1.4  2005/10/08 18:22:46  fraggle
+// Store the cache as part of the lumpinfo_t struct.  Add W_AddFile prototype
+// to header.
+//
 // Revision 1.3  2005/07/23 18:54:06  fraggle
 // Use standard C functions for WAD code
 //