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/wi_stuff.c | 194 ++++++++++++++++++++++++++------------------------------- 1 file changed, 87 insertions(+), 107 deletions(-) (limited to 'src/wi_stuff.c') diff --git a/src/wi_stuff.c b/src/wi_stuff.c index c6e5c359..bea7054f 100644 --- a/src/wi_stuff.c +++ b/src/wi_stuff.c @@ -346,9 +346,6 @@ static int NUMCMAPS; // GRAPHICS // -// background (map of levels). -static patch_t* bg; - // You Are Here graphic static patch_t* yah[2]; @@ -1547,29 +1544,18 @@ void WI_Ticker(void) } -void WI_loadData(void) +typedef void (*load_callback_t)(char *lumpname, patch_t **variable); + +// Common load/unload function. Iterates over all the graphics +// lumps to be loaded/unloaded into memory. + +static void WI_loadUnloadData(load_callback_t callback) { int i; int j; char name[9]; anim_t* a; - if (gamemode == commercial) - strcpy(name, DEH_String("INTERPIC")); - else - sprintf(name, DEH_String("WIMAP%d"), wbs->epsd); - - if ( gamemode == retail ) - { - if (wbs->epsd == 3) - strcpy(name, DEH_String("INTERPIC")); - } - - // background - bg = W_CacheLumpName(name, PU_CACHE); - V_DrawPatch(0, 0, 1, bg); - - // UNUSED unsigned char *pic = screens[1]; // if (gamemode == commercial) // { @@ -1583,33 +1569,28 @@ void WI_loadData(void) if (gamemode == commercial) { - NUMCMAPS = 32; - lnames = (patch_t **) Z_Malloc(sizeof(patch_t*) * NUMCMAPS, - PU_STATIC, 0); for (i=0 ; iepsd, i); - lnames[i] = W_CacheLumpName(name, PU_STATIC); + callback(name, &lnames[i]); } // you are here - yah[0] = W_CacheLumpName(DEH_String("WIURH0"), PU_STATIC); + callback(DEH_String("WIURH0"), &yah[0]); // you are here (alt.) - yah[1] = W_CacheLumpName(DEH_String("WIURH1"), PU_STATIC); + callback(DEH_String("WIURH1"), &yah[1]); // splat - splat = W_CacheLumpName(DEH_String("WISPLAT"), PU_STATIC); + callback(DEH_String("WISPLAT"), &splat); if (wbs->epsd < 3) { @@ -1624,7 +1605,7 @@ void WI_loadData(void) // animations sprintf(name, DEH_String("WIA%d%.2d%.2d"), wbs->epsd, j, i); - a->p[i] = W_CacheLumpName(name, PU_STATIC); + callback(name, &a->p[i]); } else { @@ -1637,150 +1618,149 @@ void WI_loadData(void) } // More hacks on minus sign. - wiminus = W_CacheLumpName(DEH_String("WIMINUS"), PU_STATIC); + callback(DEH_String("WIMINUS"), &wiminus); for (i=0;i<10;i++) { // numbers 0-9 sprintf(name, DEH_String("WINUM%d"), i); - num[i] = W_CacheLumpName(name, PU_STATIC); + callback(name, &num[i]); } // percent sign - percent = W_CacheLumpName(DEH_String("WIPCNT"), PU_STATIC); + callback(DEH_String("WIPCNT"), &percent); // "finished" - finished = W_CacheLumpName(DEH_String("WIF"), PU_STATIC); + callback(DEH_String("WIF"), &finished); // "entering" - entering = W_CacheLumpName(DEH_String("WIENTER"), PU_STATIC); + callback(DEH_String("WIENTER"), &entering); // "kills" - kills = W_CacheLumpName(DEH_String("WIOSTK"), PU_STATIC); + callback(DEH_String("WIOSTK"), &kills); // "scrt" - secret = W_CacheLumpName(DEH_String("WIOSTS"), PU_STATIC); + callback(DEH_String("WIOSTS"), &secret); // "secret" - sp_secret = W_CacheLumpName(DEH_String("WISCRT2"), PU_STATIC); + callback(DEH_String("WISCRT2"), &sp_secret); // french wad uses WIOBJ (?) if (W_CheckNumForName(DEH_String("WIOBJ")) >= 0) { // "items" if (netgame && !deathmatch) - items = W_CacheLumpName(DEH_String("WIOBJ"), PU_STATIC); + callback(DEH_String("WIOBJ"), &items); else - items = W_CacheLumpName(DEH_String("WIOSTI"), PU_STATIC); + callback(DEH_String("WIOSTI"), &items); } else { - items = W_CacheLumpName(DEH_String("WIOSTI"), PU_STATIC); + callback(DEH_String("WIOSTI"), &items); } // "frgs" - frags = W_CacheLumpName(DEH_String("WIFRGS"), PU_STATIC); + callback(DEH_String("WIFRGS"), &frags); // ":" - colon = W_CacheLumpName(DEH_String("WICOLON"), PU_STATIC); + callback(DEH_String("WICOLON"), &colon); // "time" - timepatch = W_CacheLumpName(DEH_String("WITIME"), PU_STATIC); + callback(DEH_String("WITIME"), &timepatch); // "sucks" - sucks = W_CacheLumpName(DEH_String("WISUCKS"), PU_STATIC); + callback(DEH_String("WISUCKS"), &sucks); // "par" - par = W_CacheLumpName(DEH_String("WIPAR"), PU_STATIC); + callback(DEH_String("WIPAR"), &par); // "killers" (vertical) - killers = W_CacheLumpName(DEH_String("WIKILRS"), PU_STATIC); + callback(DEH_String("WIKILRS"), &killers); // "victims" (horiz) - victims = W_CacheLumpName(DEH_String("WIVCTMS"), PU_STATIC); + callback(DEH_String("WIVCTMS"), &victims); // "total" - total = W_CacheLumpName(DEH_String("WIMSTT"), PU_STATIC); - - // your face - star = W_CacheLumpName(DEH_String("STFST01"), PU_STATIC); - - // dead face - bstar = W_CacheLumpName(DEH_String("STFDEAD0"), PU_STATIC); + callback(DEH_String("WIMSTT"), &total); for (i=0 ; iepsd < 3) - { - for (j=0;jepsd];j++) - { - if (wbs->epsd != 1 || j != 8) - for (i=0;iepsd][j].nanims;i++) - Z_ChangeTag(anims[wbs->epsd][j].p[i], PU_CACHE); - } - } + // These two graphics are special cased because we're sharing + // them with the status bar code + + // your face + star = W_CacheLumpName(DEH_String("STFST01"), PU_STATIC); + + // dead face + bstar = W_CacheLumpName(DEH_String("STFDEAD0"), PU_STATIC); + + // Background image + + if (gamemode == commercial) + { + strcpy(bg_lumpname, DEH_String("INTERPIC")); + } + else if (gamemode == retail && wbs->epsd == 3) + { + strcpy(bg_lumpname, DEH_String("INTERPIC")); + } + else + { + sprintf(bg_lumpname, DEH_String("WIMAP%d"), wbs->epsd); } - Z_Free(lnames); - - Z_ChangeTag(percent, PU_CACHE); - Z_ChangeTag(colon, PU_CACHE); - Z_ChangeTag(finished, PU_CACHE); - Z_ChangeTag(entering, PU_CACHE); - Z_ChangeTag(kills, PU_CACHE); - Z_ChangeTag(secret, PU_CACHE); - Z_ChangeTag(sp_secret, PU_CACHE); - Z_ChangeTag(items, PU_CACHE); - Z_ChangeTag(frags, PU_CACHE); - Z_ChangeTag(timepatch, PU_CACHE); - Z_ChangeTag(sucks, PU_CACHE); - Z_ChangeTag(par, PU_CACHE); - - Z_ChangeTag(victims, PU_CACHE); - Z_ChangeTag(killers, PU_CACHE); - Z_ChangeTag(total, PU_CACHE); - // Z_ChangeTag(star, PU_CACHE); - // Z_ChangeTag(bstar, PU_CACHE); - - for (i=0 ; i