From 3f54daeaa3acf590569cb397eee24731f7de6c17 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Fri, 2 May 2008 18:48:43 +0000 Subject: Add W_CacheLumpNum,Name API to WAD code for releasing a lump back to cache when it is no longer needed. Switch existing code to use the new API instead of Z_ChangeTag. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1134 --- src/w_wad.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/w_wad.c') diff --git a/src/w_wad.c b/src/w_wad.c index becdcf71..8960bb92 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -457,6 +457,15 @@ void W_ReadLump(unsigned int lump, void *dest) // // W_CacheLumpNum // +// Load a lump into memory and return a pointer to a buffer containing +// the lump data. +// +// 'tag' is the type of zone memory buffer to allocate for the lump +// (usually PU_STATIC or PU_CACHE). If the lump is loaded as +// PU_STATIC, it should be released back using W_ReleaseLumpNum +// when no longer needed (do not use Z_ChangeTag). +// + void *W_CacheLumpNum(int lump, int tag) { byte* ptr; @@ -491,6 +500,31 @@ void *W_CacheLumpName(char *name, int tag) return W_CacheLumpNum(W_GetNumForName(name), tag); } +// +// Release a lump back to the cache, so that it can be reused later +// without having to read from disk again, or alternatively, discarded +// if we run out of memory. +// +// Back in Vanilla Doom, this was just done using Z_ChangeTag +// directly, but now that we have WAD mmap, things are a bit more +// complicated ... +// + +void W_ReleaseLumpNum(int lump) +{ + if ((unsigned)lump >= numlumps) + { + I_Error ("W_ReleaseLumpNum: %i >= numlumps", lump); + } + + Z_ChangeTag(lumpinfo[lump].cache, PU_CACHE); +} + +void W_ReleaseLumpName(char *name) +{ + W_ReleaseLumpNum(W_GetNumForName(name)); +} + #if 0 // -- cgit v1.2.3