diff --git a/src/d_main.c b/src/d_main.c index d10ba05ab..87596ca1c 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1812,7 +1812,7 @@ void D_SRB2Main(void) { name = lumpinfo->name; - if (name[0] == 'M' && name[1] == 'A' && name[2] == 'P') // Ignore the headers + if (memcmp(name, "MAP", 3) == 0) // Ignore the headers { INT16 num; if (name[5] != '\0') @@ -1842,7 +1842,7 @@ void D_SRB2Main(void) { name = lumpinfo->name; - if (name[0] == 'M' && name[1] == 'A' && name[2] == 'P') // Ignore the headers + if (memcmp(name, "MAP", 3) == 0) // Ignore the headers { INT16 num; if (name[5] != '\0') diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 2821c4021..b7d0c10d9 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -259,8 +259,6 @@ INT32 HU_FallBackFrSpecialLetter(INT32 key) } } - - static char cechotext[1024]; static tic_t cechotimer = 0; static tic_t cechoduration = 5*TICRATE; diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index d1dce0ae0..ff10a34c1 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -1260,15 +1260,10 @@ extern int lib_hudadd(lua_State *L); static int lib_hudsetvotebackground(lua_State *L) { + memset(VoteScreen.luaPrefix, 0, sizeof(VoteScreen.luaPrefix)); + if (lua_isnoneornil(L, 1)) { - if (luaVoteScreen) - { - free(luaVoteScreen); - } - - luaVoteScreen = NULL; - return 0; } @@ -1279,15 +1274,8 @@ static int lib_hudsetvotebackground(lua_State *L) return luaL_argerror(L, 1, "prefix should 4 characters wide"); } - if (!luaVoteScreen) - { - luaVoteScreen = (char*)malloc(5); - luaVoteScreen[4] = 0; - } - - strncpy(luaVoteScreen, prefix, 4); - - strupr(luaVoteScreen); + strncpy(VoteScreen.luaPrefix, prefix, 4); + strupr(VoteScreen.luaPrefix); return 0; } diff --git a/src/p_setup.c b/src/p_setup.c index 0459a03f5..3ab1f8816 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -67,6 +67,8 @@ #include "lua_script.h" #include "lua_hook.h" +#include "y_inter.h" + #if !defined (UNDER_CE) #include #endif @@ -3106,11 +3108,128 @@ boolean P_AddWadFile(const char *wadfilename, boolean local) return true; } -// check for replacement votescreen backgrounds -boolean wideracereplaced = false; -boolean racereplaced = false; -boolean widebattlereplaced = false; -boolean battlereplaced = false; +static size_t sreplaces = 0, mreplaces = 0, digmreplaces = 0; + +// +// search for sound replacements +// +static boolean P_CheckSoundReplacements(UINT16 wadnum, char *name, size_t i) +{ + size_t j; + lumpnum_t lumpnum = (i|(wadnum<<16)); + + if (name[0] == 'D') + { + if (name[1] == 'S') + { + for (j = 1; j < NUMSFX; j++) + { + if (S_sfx[j].name && !strnicmp(S_sfx[j].name, name + 2, 6) + && (S_sfx[j].lumpnum != lumpnum) && (S_sfx[j].lumpnum != LUMPERROR)) + { + // the sound will be reloaded when needed, + // since sfx->data will be NULL + CONS_Debug(DBG_SETUP, "Sound %.8s replaced\n", name); + + I_FreeSfx(&S_sfx[j]); + + // Re-cache it + if (S_PrecacheSound()) + S_sfx[j].data = I_GetSfx(&S_sfx[j]); + + sreplaces++; + return true; + } + } + } + else if (name[1] == '_') + { + CONS_Debug(DBG_SETUP, "Music %.8s ignored\n", name); + mreplaces++; + return true; + } + } + else if (name[0] == 'O' && name[1] == '_') + { + CONS_Debug(DBG_SETUP, "Music %.8s replaced\n", name); + digmreplaces++; + return true; + } + + return false; +} + +// +// search for maps +// +static boolean P_CheckMapReplacements(char *name) +{ + if (memcmp(name, "MAP", 3) == 0) // Ignore the headers + { + INT16 num; + + if (name[5] != '\0') + return false; + + num = (INT16)M_MapNumber(name[3], name[4]); + + // we want to record whether this map exists. if it doesn't have a header, we can assume it's not relephant + if (num <= NUMMAPS && mapheaderinfo[num-1]) + { + if (mapheaderinfo[num-1]->menuflags & LF2_EXISTSHACK) + G_SetGameModified(multiplayer, true); // oops, double-defined - no record attack privileges for you + mapheaderinfo[num-1]->menuflags |= LF2_EXISTSHACK; + } + + if (num == gamemap) + partadd_replacescurrentmap = true; + + CONS_Printf("%s\n", name); + return true; + } + + return false; +} + +// +// check for non Lua votescreen replacements +// +static boolean P_CheckVoteReplacements(char *name) +{ + // widescreen patch Race + if (!VoteScreen.replaced.widerace && !memcmp(name, "INTERSCW", 8)) + { + VoteScreen.replaced.widerace = true; + return false; + } + + if (!VoteScreen.replaced.race && !memcmp(name, "INTERSCR", 8)) + { + VoteScreen.replaced.race = true; + return false; + } + + // widescreen patch Battle + if (!VoteScreen.replaced.widebattle && !memcmp(name, "BATTLSCW", 8)) + { + VoteScreen.replaced.widebattle = true; + return false; + } + + if (!VoteScreen.replaced.battle && !memcmp(name, "BATTLSCR", 8)) + { + VoteScreen.replaced.battle = true; + return false; + } + + if (VoteScreen.replaced.widerace && VoteScreen.replaced.race + && VoteScreen.replaced.widebattle && VoteScreen.replaced.battle) + { + return true; + } + + return false; +} // // Add a WAD file and do the per-WAD setup stages. @@ -3118,12 +3237,15 @@ boolean battlereplaced = false; // UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local) { - size_t i, j, sreplaces = 0, mreplaces = 0, digmreplaces = 0; + size_t i; UINT16 numlumps, wadnum; char *name; boolean mapsadded = false; + static boolean allvotereplaced = false; lumpinfo_t *lumpinfo; + sreplaces = mreplaces = digmreplaces = 0; + if ((numlumps = W_InitFile(wadfilename, local)) == INT16_MAX) { refreshdirmenu |= REFRESHDIR_NOTLOADED; @@ -3138,46 +3260,24 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local) wadfiles[wadnum]->localfile = local; - // - // search for sound replacements - // lumpinfo = wadfiles[wadnum]->lumpinfo; for (i = 0; i < numlumps; i++, lumpinfo++) { name = lumpinfo->name; - lumpnum_t lumpnum = i|(wadnum<<16); - if (name[0] == 'D') + if (P_CheckSoundReplacements(wadnum, name, i)) + continue; + + if (P_CheckMapReplacements(name)) { - if (name[1] == 'S') for (j = 1; j < NUMSFX; j++) - { - if (S_sfx[j].name && !strnicmp(S_sfx[j].name, name + 2, 6) && S_sfx[j].lumpnum != lumpnum && S_sfx[j].lumpnum != LUMPERROR) - { - // the sound will be reloaded when needed, - // since sfx->data will be NULL - CONS_Debug(DBG_SETUP, "Sound %.8s replaced\n", name); - - I_FreeSfx(&S_sfx[j]); - - // Re-cache it - if (S_PrecacheSound()) - S_sfx[j].data = I_GetSfx(&S_sfx[j]); - - sreplaces++; - } - } - else if (name[1] == '_') - { - CONS_Debug(DBG_SETUP, "Music %.8s ignored\n", name); - mreplaces++; - } - } - else if (name[0] == 'O' && name[1] == '_') - { - CONS_Debug(DBG_SETUP, "Music %.8s replaced\n", name); - digmreplaces++; + mapsadded = true; + continue; } + + if (!allvotereplaced && P_CheckVoteReplacements(name)) + allvotereplaced = true; } + if (!devparm && sreplaces) CONS_Printf(M_GetText("%s sounds replaced\n"), sizeu1(sreplaces)); if (!devparm && mreplaces) @@ -3185,6 +3285,9 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local) if (!devparm && digmreplaces) CONS_Printf(M_GetText("%s digital musics replaced\n"), sizeu1(digmreplaces)); + if (!mapsadded) + CONS_Printf(M_GetText("No maps added\n")); + // // search for sprite replacements // @@ -3209,80 +3312,9 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local) // S_LoadMusicDefs(wadnum); - // - // search for maps - // - lumpinfo = wadfiles[wadnum]->lumpinfo; - for (i = 0; i < numlumps; i++, lumpinfo++) - { - name = lumpinfo->name; - - if (name[0] == 'M' && name[1] == 'A' && name[2] == 'P') // Ignore the headers - { - INT16 num; - if (name[5]!='\0') - continue; - num = (INT16)M_MapNumber(name[3], name[4]); - - // we want to record whether this map exists. if it doesn't have a header, we can assume it's not relephant - if (num <= NUMMAPS && mapheaderinfo[num-1]) - { - if (mapheaderinfo[num-1]->menuflags & LF2_EXISTSHACK) - G_SetGameModified(multiplayer, true); // oops, double-defined - no record attack privileges for you - mapheaderinfo[num-1]->menuflags |= LF2_EXISTSHACK; - } - - if (num == gamemap) - partadd_replacescurrentmap = true; - - CONS_Printf("%s\n", name); - mapsadded = true; - } - } - if (!mapsadded) - CONS_Printf(M_GetText("No maps added\n")); - // TODO: Experimental SPRTINFO support, test first R_LoadSpriteInfoLumps(wadnum, wadfiles[wadnum]->numlumps); - // - // check for votescreen replacements - // - if (!wideracereplaced && !racereplaced && !widebattlereplaced && !battlereplaced) - { - lumpinfo = wadfiles[wadnum]->lumpinfo; - for (i = 0; i < numlumps; i++, lumpinfo++) - { - name = lumpinfo->name; - - // widescreen patch Race - if (!wideracereplaced && !strncmp(name, "INTERSCW", 8)) - { - wideracereplaced = true; - continue; - } - - if (!racereplaced && !strncmp(name, "INTERSCR", 8)) - { - racereplaced = true; - continue; - } - - // widescreen patch Battle - if (!widebattlereplaced && !strncmp(name, "BATTLSCW", 8)) - { - widebattlereplaced = true; - continue; - } - - if (!battlereplaced && !strncmp(name, "BATTLSCR", 8)) - { - battlereplaced = true; - continue; - } - } - } - refreshdirmenu &= ~REFRESHDIR_GAMEDATA; // Under usual circumstances we'd wait for REFRESHDIR_GAMEDATA to disappear the next frame, but it's a bit too dangerous for that... partadd_stage = 0; return wadnum; diff --git a/src/p_setup.h b/src/p_setup.h index 97209e154..1a437a778 100644 --- a/src/p_setup.h +++ b/src/p_setup.h @@ -68,11 +68,6 @@ void HWR_LoadLevel(boolean reloadinggamestate); boolean P_AddWadFile(const char *wadfilename, boolean local); -extern boolean wideracereplaced; -extern boolean racereplaced; -extern boolean widebattlereplaced; -extern boolean battlereplaced; - // WARNING: The following functions should be grouped as follows: // any amount of PartialAdds followed by MultiSetups until returned true, // as soon as possible. diff --git a/src/y_inter.c b/src/y_inter.c index 3c0a77ac1..3a69b06de 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -57,30 +57,15 @@ typedef struct static y_data_t data; - // graphics -static patch_t *bgpatch = NULL; // INTERSCR -static patch_t *widebgpatch = NULL; // INTERSCW static patch_t *bgtile = NULL; // SPECTILE/SRB2BACK + static INT32 timer; static INT32 intertic; static INT32 endtic = -1; static INT32 sorttic = -1; -patch_t *animVoteFramesPatches = NULL; -// VEXTRN - Vote (V) Extra (EXT) Race (R) Normal (N - Normal sized patch) -// VEXTBN - Vote (V) Extra (EXT) Battle (B) Normal (N - Normal sized patch) -// VEXTBW - Vote (V) Extra (EXT) Battle (B) Normal (W - Wide patch used in software) -// VEXTRW - Vote (V) Extra (EXT) Race (R) Normal (W - Wide patch used in software) -char animPrefix[] = "INTSC"; -char animWidePrefix[] = "INTSW"; -char *luaVoteScreen = NULL; - -INT32 currentAnimFrame = 0; -static INT32 foundAnimVoteFrames = 0; -static INT32 foundAnimVoteWideFrames = 0; - intertype_t intertype = int_none; static huddrawlist_h luahuddrawlist_intermission = NULL; @@ -118,17 +103,13 @@ typedef struct boolean loaded; } y_voteclient; +// votescreen stuff +votescreen_t VoteScreen = {0}; + static y_votelvlinfo levelinfo[5]; static y_voteclient voteclient; static INT32 votetic; static INT32 voteendtic = -1; -static patch_t *cursor = NULL; -static patch_t *cursor1 = NULL; -static patch_t *cursor2 = NULL; -static patch_t *cursor3 = NULL; -static patch_t *cursor4 = NULL; -static patch_t *randomlvl = NULL; -static patch_t *rubyicon = NULL; static void Y_UnloadVoteData(void); @@ -287,49 +268,6 @@ static void Y_CalculateMatchData(UINT8 rankingsmode, void (*comparison)(INT32)) } } -// -// Y_AnimatedVoteScreenCheck -// -// Check if the lumps exist (checking for VEXTR(N|W)xx for race and VEXTRB(N|W)xx for battle) -static void Y_AnimatedVoteScreenCheck(void) -{ - char tmpPrefix[] = "INTS"; - - if (luaVoteScreen) - strncpy(tmpPrefix, luaVoteScreen, 4); - else if (G_BattleGametype()) - strcpy(tmpPrefix, "BTLS"); - - strncpy(animPrefix, tmpPrefix, 4); - animPrefix[4] = 'C'; - strncpy(animWidePrefix, tmpPrefix, 4); - animWidePrefix[4] = 'W'; - - foundAnimVoteFrames = foundAnimVoteWideFrames = 0; - currentAnimFrame = 0; - - INT32 i = 1; - - for (;;) - { - boolean normalLumpExists = W_LumpExists(va("%sC%d", tmpPrefix, i)); - boolean wideLumpExists = W_LumpExists(va("%sW%d", tmpPrefix, i)); - - if (normalLumpExists || wideLumpExists) - { - if (normalLumpExists) - foundAnimVoteFrames++; - - if (wideLumpExists) - foundAnimVoteWideFrames++; - } - else // If we don't find at least frame 1 (e.g VEXTRN1), let's just stop looking - break; - - i++; - } -} - // Y_PlayerStandingsDrawer // // Handles drawing the center-of-screen player standings. @@ -863,7 +801,8 @@ void Y_StartIntermission(void) // void Y_EndIntermission(void) { - Y_UnloadData(); + if (!dedicated) + Y_UnloadData(); endtic = -1; sorttic = -1; @@ -881,28 +820,72 @@ static void Y_FollowIntermission(void) G_AfterIntermission(); } -#define UNLOAD(x) if (x) {Patch_Free(x);} x = NULL; +#define UNLOAD(x) {if ((x) != NULL) {Patch_Free(x);} x = NULL;} // // Y_UnloadData // static void Y_UnloadData(void) { - // In hardware mode, don't Z_ChangeTag a pointer returned by W_CachePatchName(). - // It doesn't work and is unnecessary. - if (rendermode != render_soft) - return; - // unload the background patches - UNLOAD(bgpatch); - UNLOAD(widebgpatch); + UNLOAD(VoteScreen.bgpatch); + UNLOAD(VoteScreen.widebgpatch); UNLOAD(bgtile); //UNLOAD(interpic); } // SRB2Kart: Voting! -static void Y_DrawVoteBackground(patch_t *patch) +// +// Y_VoteScreenCheck +// +static void Y_VoteScreenCheck(void) +{ + strcpy(VoteScreen.Prefix, "INTS"); + + if (VoteScreen.luaPrefix[0] != 0) + strlcpy(VoteScreen.Prefix, VoteScreen.luaPrefix, sizeof(VoteScreen.Prefix)); + else if (G_BattleGametype()) + strcpy(VoteScreen.Prefix, "BTLS"); + + VoteScreen.foundLuaVoteFrames = VoteScreen.foundLuaVoteWideFrames = 0; + VoteScreen.currentAnimFrame = 0; + + INT32 i = 1; + + // check for lua vote background replacements + for (;;) + { + // Check if the lumps exist (checking for VEXTR(N|W)xx for race and VEXTRB(N|W)xx for battle) + boolean normalLumpExists = W_LumpExists(va("%sC%d", VoteScreen.Prefix, i)); + boolean wideLumpExists = W_LumpExists(va("%sW%d", VoteScreen.Prefix, i)); + + if (normalLumpExists || wideLumpExists) + { + if (normalLumpExists) + VoteScreen.foundLuaVoteFrames++; + + if (wideLumpExists) + VoteScreen.foundLuaVoteWideFrames++; + } + else // If we don't find at least frame 1 (e.g VEXTRN1), let's just stop looking + break; + + i++; + } + + // non lua vote background handling + boolean prefbattletype = ((votelevels[0][1] & ~0x80) == GT_MATCH); + VoteScreen.widebgpatch = W_CachePatchName((prefbattletype ? "BATTLSCW" : "INTERSCW"), PU_PATCH); + VoteScreen.bgpatch = W_CachePatchName((prefbattletype ? "BATTLSCR" : "INTERSCR"), PU_PATCH); +} + +// +// Y_VoteBackgroundDrawer +// +// Determines which patch drawer to use for scaling +// +static void Y_VoteBackgroundDrawer(patch_t *patch) { switch (cv_votebgscaling.value) { @@ -924,57 +907,74 @@ static void Y_DrawVoteBackground(patch_t *patch) } } -// Y_DrawAnimatedVoteScreenPatch // -// Draw animated patch based on frame counter on vote screen +// Y_DrawLuaVoteScreenPatch // -static void Y_DrawAnimatedVoteScreenPatch(boolean widePatch) +// Handles votebackgrounds set by "setVoteBackground" +// Aswell as animated patches +// +static void Y_DrawLuaVoteScreenPatch(boolean widePatch) { INT32 nextframe = 0; patch_t *votebg = NULL; - char tempAnimPrefix[7]; - const INT32 tempFoundAnimVoteFrames = ((widePatch ? foundAnimVoteWideFrames : foundAnimVoteFrames) - 1); + char tempPrefix[6]; + const INT32 tempfoundAnimLuaVoteFrames = ((widePatch ? VoteScreen.foundLuaVoteWideFrames : VoteScreen.foundLuaVoteFrames) - 1); - strcpy(tempAnimPrefix, (widePatch ? animWidePrefix : animPrefix)); + strcpy(tempPrefix, va("%s%s", VoteScreen.Prefix, (widePatch ? "W" : "C"))); + + // Draw non animated patch + if (!tempfoundAnimLuaVoteFrames) + { + votebg = W_CachePatchName(va("%s1", tempPrefix), PU_PATCH); + Y_VoteBackgroundDrawer(votebg); + return; + } + + // Draw animated patch based on frame counter on vote screen // Just in case someone provides LESS widescreen frames than normal frames or vice versa, reset the frame counter to 0 - if (currentAnimFrame > tempFoundAnimVoteFrames) - currentAnimFrame = 0; + if (VoteScreen.currentAnimFrame > tempfoundAnimLuaVoteFrames) + VoteScreen.currentAnimFrame = 0; - nextframe = (currentAnimFrame + 1); + nextframe = (VoteScreen.currentAnimFrame + 1); - votebg = W_CachePatchName(va("%s%d", (widePatch ? animWidePrefix : animPrefix), nextframe), PU_PATCH); + votebg = W_CachePatchName(va("%s%d", tempPrefix, nextframe), PU_PATCH); - Y_DrawVoteBackground(votebg); + Y_VoteBackgroundDrawer(votebg); if (renderisnewtic && (votetic % 2 == 0) && !paused) - currentAnimFrame = (nextframe > tempFoundAnimVoteFrames) ? 0 : nextframe; + VoteScreen.currentAnimFrame = (nextframe > tempfoundAnimLuaVoteFrames) ? 0 : nextframe; } +// +// Y_DrawVoteScreenPatch +// static void Y_DrawVoteScreenPatch(void) { patch_t *votebg = NULL; const boolean widescreen = (vid.width / vid.dupx > 320); - if (foundAnimVoteWideFrames || foundAnimVoteFrames) + if (VoteScreen.foundLuaVoteWideFrames || VoteScreen.foundLuaVoteFrames) { - Y_DrawAnimatedVoteScreenPatch((foundAnimVoteWideFrames && widescreen)); + Y_DrawLuaVoteScreenPatch(((widescreen && VoteScreen.foundLuaVoteWideFrames) || !VoteScreen.foundLuaVoteFrames)); return; } - votebg = bgpatch; // non widescreen patch + // non widescreen patch + votebg = VoteScreen.bgpatch; UINT8 prefgametype = (votelevels[0][1] & ~0x80); - const boolean widebgreplaced = (prefgametype == GT_MATCH) ? widebattlereplaced : wideracereplaced; - const boolean bgreplaced = (prefgametype == GT_MATCH) ? battlereplaced : racereplaced; + const boolean widebgreplaced = (prefgametype == GT_MATCH) ? VoteScreen.replaced.widebattle : VoteScreen.replaced.widerace; + const boolean bgreplaced = (prefgametype == GT_MATCH) ? VoteScreen.replaced.battle : VoteScreen.replaced.race; + // we check a bunch of stuff to always have a "valid" fallback if ((widescreen && (widebgreplaced || !bgreplaced)) || (!widescreen && (widebgreplaced && !bgreplaced))) { - votebg = widebgpatch; + votebg = VoteScreen.widebgpatch; // widescreen patch } - Y_DrawVoteBackground(votebg); + Y_VoteBackgroundDrawer(votebg); } // @@ -1037,7 +1037,7 @@ void Y_VoteDrawer(void) if (i == 3) { str = "RANDOM"; - pic = randomlvl; + pic = VoteScreen.randomlvl; } else { @@ -1061,7 +1061,7 @@ void Y_VoteDrawer(void) if (!splitscreen) { - thiscurs = cursor; + thiscurs = VoteScreen.cursor[0]; p = consoleplayer; color = levelinfo[i].gtc; colormap = NULL; @@ -1071,19 +1071,19 @@ void Y_VoteDrawer(void) switch (j) { case 1: - thiscurs = cursor2; + thiscurs = VoteScreen.cursor[2]; p = displayplayers[1]; break; case 2: - thiscurs = cursor3; + thiscurs = VoteScreen.cursor[3]; p = displayplayers[2]; break; case 3: - thiscurs = cursor4; + thiscurs = VoteScreen.cursor[4]; p = displayplayers[3]; break; default: - thiscurs = cursor1; + thiscurs = VoteScreen.cursor[1]; p = displayplayers[0]; break; } @@ -1111,7 +1111,7 @@ void Y_VoteDrawer(void) else { V_DrawFixedPatch((BASEVIDWIDTH-20)<= 3 && (i != pickedvote || voteendtic == -1)) - pic = randomlvl; + pic = VoteScreen.randomlvl; else pic = levelinfo[votes[i]].pic; if (!timer && i == voteclient.ranim) { - V_DrawScaledPatch(x-18, y+9, V_SNAPTOLEFT, cursor); + V_DrawScaledPatch(x-18, y+9, V_SNAPTOLEFT, VoteScreen.cursor[0]); if (voteendtic != -1 && !(votetic % 4)) V_DrawFill(x-1, y-1, 42, 27, 120|V_SNAPTOLEFT); else @@ -1182,7 +1182,7 @@ void Y_VoteDrawer(void) else { V_DrawFixedPatch((x+40)<