From 352a926ddf85d733c4352ee189c7f49b476281b8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 12 Oct 2010 07:14:31 +0000 Subject: [PATCH] - made all references to the GameNames array an inline function call to allow easier modification later - changed all parsers that check for the current game to use the same function for the game check. - fixed: The TEAMINFO parser handled 'game Any' incorrectly. SVN r2934 (trunk) --- src/d_main.cpp | 8 ++++---- src/g_shared/a_keys.cpp | 23 +++-------------------- src/gi.h | 12 ++++++++++++ src/keysections.cpp | 4 ++-- src/m_misc.cpp | 6 +++--- src/menu/menu.cpp | 2 +- src/menu/menudef.cpp | 10 +++------- src/p_terrain.cpp | 23 +---------------------- src/p_udmf.cpp | 2 +- src/s_advsound.cpp | 23 +---------------------- src/stringtable.cpp | 2 +- src/teaminfo.cpp | 25 +++++-------------------- src/teaminfo.h | 1 - 13 files changed, 37 insertions(+), 104 deletions(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index 10d58fd2b..9c4c6b13b 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -1877,7 +1877,7 @@ void D_DoomMain (void) gameinfo.gametype = iwad_info->gametype; gameinfo.flags = iwad_info->flags; - GameConfig->DoGameSetup (GameNames[gameinfo.gametype]); + GameConfig->DoGameSetup (GameName()); if (!(gameinfo.flags & GI_SHAREWARE) && !Args->CheckParm("-noautoload")) { @@ -1910,7 +1910,7 @@ void D_DoomMain (void) D_AddConfigWads (allwads, "Global.Autoload"); // Add game-specific wads - file = GameNames[gameinfo.gametype]; + file = GameName(); file += ".Autoload"; D_AddConfigWads (allwads, file); @@ -1925,7 +1925,7 @@ void D_DoomMain (void) // Run automatically executed files execFiles = new DArgs; - GameConfig->AddAutoexec (execFiles, GameNames[gameinfo.gametype]); + GameConfig->AddAutoexec (execFiles, GameName()); D_MultiExec (execFiles, true); // Run .cfg files at the start of the command line. @@ -2145,7 +2145,7 @@ void D_DoomMain (void) StartScreen->Progress (); - Printf ("R_Init: Init %s refresh subsystem.\n", GameNames[gameinfo.gametype]); + Printf ("R_Init: Init %s refresh subsystem.\n", GameName()); StartScreen->LoadingStatus ("Loading graphics", 0x3f); R_Init (); diff --git a/src/g_shared/a_keys.cpp b/src/g_shared/a_keys.cpp index aaddb9084..e7f1b286b 100644 --- a/src/g_shared/a_keys.cpp +++ b/src/g_shared/a_keys.cpp @@ -199,27 +199,11 @@ static void ParseLock(FScanner &sc) keynum = sc.Number; sc.MustGetString(); - if (sc.Compare("DOOM")) + if (!sc.Compare("{")) { - if (gameinfo.gametype != GAME_Doom) keynum=-1; + if (!CheckGame(sc.String, false)) keynum = -1; + sc.MustGetStringName("{"); } - else if (sc.Compare("HERETIC")) - { - if (gameinfo.gametype != GAME_Heretic) keynum=-1; - } - else if (sc.Compare("HEXEN")) - { - if (gameinfo.gametype != GAME_Hexen) keynum=-1; - } - else if (sc.Compare("STRIFE")) - { - if (gameinfo.gametype != GAME_Strife) keynum=-1; - } - else if (sc.Compare("CHEX")) - { - if (gameinfo.gametype != GAME_Chex) keynum=-1; - } - else sc.UnGet(); ignorekey = true; if (keynum > 0 && keynum < 255) @@ -239,7 +223,6 @@ static void ParseLock(FScanner &sc) sc.ScriptError("Lock index %d out of range", keynum); } - sc.MustGetStringName("{"); while (!sc.CheckString("}")) { sc.MustGetString(); diff --git a/src/gi.h b/src/gi.h index e71b0f783..b65926881 100644 --- a/src/gi.h +++ b/src/gi.h @@ -135,4 +135,16 @@ struct gameinfo_t extern gameinfo_t gameinfo; +inline const char *GameName() +{ + return GameNames[gameinfo.gametype]; +} + +inline bool CheckGame(const char *string, bool chexisdoom) +{ + int test = gameinfo.gametype; + if (test == GAME_Chex && chexisdoom) test = GAME_Doom; + return !stricmp(string, GameNames[test]); +} + #endif //__GI_H__ diff --git a/src/keysections.cpp b/src/keysections.cpp index fc0e668ba..5f8f12ea7 100644 --- a/src/keysections.cpp +++ b/src/keysections.cpp @@ -48,10 +48,10 @@ static void LoadKeys (const char *modname, bool dbl) { char section[64]; - if (GameNames[gameinfo.gametype] == NULL) + if (GameName() == NULL) return; - mysnprintf (section, countof(section), "%s.%s%sBindings", GameNames[gameinfo.gametype], modname, + mysnprintf (section, countof(section), "%s.%s%sBindings", GameName(), modname, dbl ? ".Double" : "."); FKeyBindings *bindings = dbl? &DoubleBindings : &Bindings; diff --git a/src/m_misc.cpp b/src/m_misc.cpp index d070fdd52..3762691b1 100644 --- a/src/m_misc.cpp +++ b/src/m_misc.cpp @@ -375,9 +375,9 @@ bool M_SaveDefaults (const char *filename) GameConfig->ChangePathName (filename); } GameConfig->ArchiveGlobalData (); - if (GameNames[gameinfo.gametype] != NULL) + if (GameName() != NULL) { - GameConfig->ArchiveGameData (GameNames[gameinfo.gametype]); + GameConfig->ArchiveGameData (GameName()); } success = GameConfig->WriteConfigFile (); if (filename != NULL) @@ -619,7 +619,7 @@ static bool FindFreeName (FString &fullname, const char *extension) for (i = 0; i <= 9999; i++) { - const char *gamename = GameNames[gameinfo.gametype]; + const char *gamename = GameName(); time_t now; tm *tm; diff --git a/src/menu/menu.cpp b/src/menu/menu.cpp index 686ed12f6..1d6184437 100644 --- a/src/menu/menu.cpp +++ b/src/menu/menu.cpp @@ -960,6 +960,6 @@ CCMD(reset2defaults) CCMD(reset2saved) { GameConfig->DoGlobalSetup (); - GameConfig->DoGameSetup (GameNames[gameinfo.gametype]); + GameConfig->DoGameSetup (GameName()); R_SetViewSize (screenblocks); } diff --git a/src/menu/menudef.cpp b/src/menu/menudef.cpp index d30e35ee7..a751caf5c 100644 --- a/src/menu/menudef.cpp +++ b/src/menu/menudef.cpp @@ -112,20 +112,16 @@ static void SkipSubBlock(FScanner &sc) static bool CheckSkipGameBlock(FScanner &sc) { - int filter = 0; + bool filter = false; sc.MustGetStringName("("); do { sc.MustGetString(); - if (sc.Compare("Doom")) filter |= GAME_Doom; - if (sc.Compare("Heretic")) filter |= GAME_Heretic; - if (sc.Compare("Hexen")) filter |= GAME_Hexen; - if (sc.Compare("Strife")) filter |= GAME_Strife; - if (sc.Compare("Chex")) filter |= GAME_Chex; + filter |= CheckGame(sc.String, false); } while (sc.CheckString(",")); sc.MustGetStringName(")"); - if (!(gameinfo.gametype & filter)) + if (!filter) { SkipSubBlock(sc); return true; diff --git a/src/p_terrain.cpp b/src/p_terrain.cpp index a2750fbea..14d2bb3df 100644 --- a/src/p_terrain.cpp +++ b/src/p_terrain.cpp @@ -332,31 +332,10 @@ static void ParseOuter (FScanner &sc) break; case OUT_IFDOOM: - if (!(gameinfo.gametype & GAME_DoomChex)) - { - ifskip = true; - } - break; - case OUT_IFHERETIC: - if (gameinfo.gametype != GAME_Heretic) - { - ifskip = true; - } - break; - case OUT_IFHEXEN: - if (gameinfo.gametype != GAME_Hexen) - { - ifskip = true; - } - break; - case OUT_IFSTRIFE: - if (gameinfo.gametype != GAME_Strife) - { - ifskip = true; - } + ifskip = !CheckGame(sc.String+2, true); break; case OUT_ENDIF: diff --git a/src/p_udmf.cpp b/src/p_udmf.cpp index 2dd3c770e..263022501 100644 --- a/src/p_udmf.cpp +++ b/src/p_udmf.cpp @@ -1449,7 +1449,7 @@ public: floordrop = true; break; default: - Printf("Unknown namespace %s. Using defaults for %s\n", sc.String, GameNames[gameinfo.gametype]); + Printf("Unknown namespace %s. Using defaults for %s\n", sc.String, GameName()); switch (gameinfo.gametype) { default: // Shh, GCC diff --git a/src/s_advsound.cpp b/src/s_advsound.cpp index e6e7ce2a8..240498f0c 100644 --- a/src/s_advsound.cpp +++ b/src/s_advsound.cpp @@ -1301,31 +1301,10 @@ static void S_AddSNDINFO (int lump) break; case SI_IfDoom: //also Chex - if (!(gameinfo.gametype & GAME_DoomChex)) - { - skipToEndIf = true; - } - break; - case SI_IfStrife: - if (gameinfo.gametype != GAME_Strife) - { - skipToEndIf = true; - } - break; - case SI_IfHeretic: - if (gameinfo.gametype != GAME_Heretic) - { - skipToEndIf = true; - } - break; - case SI_IfHexen: - if (gameinfo.gametype != GAME_Hexen) - { - skipToEndIf = true; - } + skipToEndIf = !CheckGame(sc.String+3, true); break; } } diff --git a/src/stringtable.cpp b/src/stringtable.cpp index 450ab45c7..1746a29d8 100644 --- a/src/stringtable.cpp +++ b/src/stringtable.cpp @@ -231,7 +231,7 @@ void FStringTable::LoadLanguage (int lumpnum, DWORD code, bool exactMatch, int p sc.MustGetStringName("ifgame"); sc.MustGetStringName("("); sc.MustGetString(); - skip |= !sc.Compare(GameNames[gameinfo.gametype]); + skip |= !sc.Compare(GameName()); sc.MustGetStringName(")"); sc.MustGetString(); diff --git a/src/teaminfo.cpp b/src/teaminfo.cpp index 90dfb2c93..c54b2f9d6 100644 --- a/src/teaminfo.cpp +++ b/src/teaminfo.cpp @@ -113,7 +113,6 @@ enum ETeamOptions FTeam::FTeam () { - m_GameFilter = 0; m_iPlayerColor = 0; m_iPlayerCount = 0; m_iScore = 0; @@ -162,6 +161,7 @@ void FTeam::ParseTeamInfo () void FTeam::ParseTeamDefinition (FScanner &Scan) { FTeam Team; + int valid = -1; Scan.MustGetString (); Team.m_Name = Scan.String; Scan.MustGetStringName ("{"); @@ -174,23 +174,9 @@ void FTeam::ParseTeamDefinition (FScanner &Scan) { case TEAMINFO_Game: Scan.MustGetString (); - - if (!stricmp (Scan.String, "Doom")) - Team.m_GameFilter |= GAME_Doom; - else if (!stricmp (Scan.String, "Heretic")) - Team.m_GameFilter |= GAME_Heretic; - else if (!stricmp (Scan.String, "Hexen")) - Team.m_GameFilter |= GAME_Hexen; - else if (!stricmp (Scan.String, "Raven")) - Team.m_GameFilter |= GAME_Raven; - else if (!stricmp (Scan.String, "Strife")) - Team.m_GameFilter |= GAME_Strife; - else if (!stricmp (Scan.String, "Chex")) - Team.m_GameFilter |= GAME_Chex; - else if (!stricmp (Scan.String, "Any")) - Team.m_GameFilter |= GAME_Any; - else - Scan.ScriptError ("ParseTeamDefinition: Unknown game type '%s'.\n", Scan.String); + if (Scan.Compare("Any")) valid = 1; + else if (CheckGame(Scan.String, false)) valid = 1; + else if (valid == -1) valid = 0; break; case TEAMINFO_PlayerColor: @@ -236,8 +222,7 @@ void FTeam::ParseTeamDefinition (FScanner &Scan) } } - if (Team.m_GameFilter == 0 || Team.m_GameFilter & gameinfo.gametype) - Teams.Push (Team); + if (valid) Teams.Push (Team); } //========================================================================== diff --git a/src/teaminfo.h b/src/teaminfo.h index f18d63d0d..06f19c7fa 100644 --- a/src/teaminfo.h +++ b/src/teaminfo.h @@ -64,7 +64,6 @@ private: void ClearTeams (); FString m_Name; - BYTE m_GameFilter; int m_iPlayerColor; FString m_TextColor; FString m_Logo;