diff --git a/source/blood/src/actor.h b/source/blood/src/actor.h index df20f107b..453f5e6eb 100644 --- a/source/blood/src/actor.h +++ b/source/blood/src/actor.h @@ -289,3 +289,5 @@ extern short gProxySpritesCount; extern short gSightSpritesCount; extern short gPhysSpritesCount; //extern short gQavPlayerIndex; + +END_BLD_NS diff --git a/source/blood/src/config.cpp b/source/blood/src/config.cpp index 7785c6629..9c0fe412c 100644 --- a/source/blood/src/config.cpp +++ b/source/blood/src/config.cpp @@ -449,7 +449,6 @@ int CONFIG_ReadSetup(void) { char tempbuf[1024]; - CONTROL_ClearAssignments(); CONFIG_SetDefaults(); setupread = 1; diff --git a/source/build/include/cache1d.h b/source/build/include/cache1d.h index 1223e9c01..380f91742 100644 --- a/source/build/include/cache1d.h +++ b/source/build/include/cache1d.h @@ -150,7 +150,7 @@ FileReader openFromBaseResource(const char* name); inline FileReader kopenFileReader(const char* name, int where) { int handle = where == 0 ? kopen4loadfrommod(name, 0) : kopen4load(name, where); - if (handle != buildvfs_kfd_invalid) FileReader(new KFileReaderInterface(handle)); + if (handle != buildvfs_kfd_invalid) return FileReader(new KFileReaderInterface(handle)); return openFromBaseResource(name); } diff --git a/source/build/src/sdlayer.cpp b/source/build/src/sdlayer.cpp index 629db06b5..cf56b562c 100644 --- a/source/build/src/sdlayer.cpp +++ b/source/build/src/sdlayer.cpp @@ -23,7 +23,10 @@ #include "mmulti.h" #include "scriptfile.h" #include "zstring.h" -#include "gamecvars.h" +#include "gameconfigfile.h" +#include "gamecontrol.h" +#include "resourcefile.h" +#include "sc_man.h" #include "../../glbackend/glbackend.h" #ifdef USE_OPENGL @@ -474,21 +477,28 @@ void ChooseGame() std::vector wgames; TArray buttons; char* token; - auto script = scriptfile_fromfile("./games.list"); - int id = 1000; - while (!scriptfile_eof(script)) + + FileReader fr; + if (fr.OpenFile("./games.list")) { - scriptfile_getstring(script, &token); - if (scriptfile_eof(script)) + auto filedata = fr.ReadPadded(1); + + auto script = scriptfile_fromstring((char*)filedata.Data()); + int id = 1000; + while (!scriptfile_eof(script)) { - break; + scriptfile_getstring(script, &token); + if (scriptfile_eof(script)) + { + break; + } + FString game = token; + scriptfile_getstring(script, &token); + paths.Push(token); + FStringf display("%s\n%s", game.GetChars(), token); + wgames.push_back(display.WideString()); + buttons.Push({ id++, wgames.back().c_str() }); } - FString game = token; - scriptfile_getstring(script, &token); - paths.Push(token); - FStringf display("%s\n%s", game.GetChars(), token); - wgames.push_back(display.WideString()); - buttons.Push({ id++, wgames.back().c_str() }); } if (paths.Size() == 0) { @@ -596,8 +606,9 @@ int main(int argc, char *argv[]) try { - + // Startup dialog must be presented here so that everything can be set up before reading the keybinds. G_LoadConfig(currentGame); + CONFIG_Init(); r = gi->app_main(buildargc, (const char**)buildargv); } catch (const std::runtime_error & err) @@ -621,6 +632,41 @@ int main(int argc, char *argv[]) } +std::unique_ptr engine_res; + +// The resourge manager in cache1d is far too broken to add some arbitrary file without some adjustment. +// For now, keep this file here, until the resource management can be redone in a more workable fashion. +extern FString progdir; + +void InitBaseRes() +{ + if (!engine_res) + { + // If we get here for the first time, load the engine-internal data. + FString baseres = progdir + "demolition.pk3"; + engine_res.reset(FResourceFile::OpenResourceFile(baseres, true, true)); + if (!engine_res) + { + I_Error("Engine resources (%s) not found", baseres.GetChars()); + } + } +} + +extern FString currentGame; +FileReader openFromBaseResource(const char* fn) +{ + InitBaseRes(); + auto lump = engine_res->FindLump(fn); + if (lump) return lump->NewReader(); + // Also look in game filtered directories. + FStringf filtername("filter/game-%s/%s", currentGame.GetChars(), fn); + lump = engine_res->FindLump(filtername); + if (lump) return lump->NewReader(); + return FileReader(nullptr); + +} + + #if SDL_MAJOR_VERSION != 1 int32_t videoSetVsync(int32_t newSync) { diff --git a/source/common/gameconfigfile.cpp b/source/common/gameconfigfile.cpp index e92830fb6..f0bd1cf90 100644 --- a/source/common/gameconfigfile.cpp +++ b/source/common/gameconfigfile.cpp @@ -486,3 +486,24 @@ CCMD (whereisini) Printf ("%s\n", path.GetChars()); } */ + +FGameConfigFile* GameConfig; +static FString GameName; + +void G_LoadConfig(const char* game) +{ + GameConfig = new FGameConfigFile(); + GameConfig->DoGlobalSetup(); + GameConfig->DoGameSetup(game); + FBaseCVar::EnableCallbacks(); + GameName = game; +} + +void G_SaveConfig() +{ + GameConfig->ArchiveGameData(GameName); + GameConfig->WriteConfigFile(); + delete GameConfig; + GameConfig = nullptr; +} + diff --git a/source/common/gameconfigfile.h b/source/common/gameconfigfile.h index 9b09fe676..1a52dc890 100644 --- a/source/common/gameconfigfile.h +++ b/source/common/gameconfigfile.h @@ -72,5 +72,7 @@ private: }; extern FGameConfigFile *GameConfig; +void G_LoadConfig(const char*); +void G_SaveConfig(); #endif //__GAMECONFIGFILE_H__ diff --git a/source/common/gamecontrol.cpp b/source/common/gamecontrol.cpp index a5377dfd1..c9c18b758 100644 --- a/source/common/gamecontrol.cpp +++ b/source/common/gamecontrol.cpp @@ -5,6 +5,8 @@ #include "control.h" #include "keyboard.h" #include "sc_man.h" +#include "c_cvars.h" +#include "build.h" struct GameFuncNameDesc { @@ -73,8 +75,7 @@ static const GameFuncNameDesc gamefuncs[] = { { gamefunc_Last_Weapon, "Last_Used_Weapon"}, { gamefunc_Quick_Save, "Quick_Save"}, { gamefunc_Quick_Load, "Quick_Load"}, - { gamefunc_Alt_Weapon, "Alternate_Weapon"}, // Name in RedNukem - { gamefunc_Alt_Weapon, "Alt_Weapon"}, // Name in EDuke32 + { gamefunc_Alt_Weapon, "Alt_Weapon"}, { gamefunc_Third_Person_View, "Third_Person_View"}, { gamefunc_Toggle_Crouch, "Toggle_Crouch"}, { gamefunc_See_Chase_View, "See_Chase_View"}, // the following were added by Blood @@ -84,31 +85,78 @@ static const GameFuncNameDesc gamefuncs[] = { { gamefunc_Aim_Center, "Aim_Center"}, { gamefunc_Tilt_Left, "Tilt_Left"}, { gamefunc_Tilt_Right, "Tilt_Right"}, - { gamefunc_Inventory_Use, "Inventory_Use"}, - { gamefunc_Map_Toggle, "Map_Toggle"}, { gamefunc_Send_Message, "Send_Message"}, { gamefunc_BeastVision, "BeastVision"}, { gamefunc_CrystalBall, "CrystalBall"}, { gamefunc_JumpBoots, "JumpBoots"}, { gamefunc_ProximityBombs, "ProximityBombs"}, { gamefunc_RemoteBombs, "RemoteBombs"}, + { gamefunc_Smoke_Bomb, "Smoke_Bomb" }, + { gamefunc_Gas_Bomb, "Gas_Bomb" }, + { gamefunc_Flash_Bomb, "Flash_Bomb" }, + { gamefunc_Caltrops, "Calitrops" }, + }; static TMap GF_NameToNum; -static TArray GF_NumToName; // This one will preserve the original name for writing to the config (which must be loaded before CON scripts can hack around with the alias array.) -static TArray GF_NumToAlias; // This is for CON scripts to hack apart. +static FString GF_NumToName[NUMGAMEFUNCTIONS]; // This one will preserve the original name for writing to the config (which must be loaded before CON scripts can hack around with the alias array.) +static FString GF_NumToAlias[NUMGAMEFUNCTIONS]; // This is for CON scripts to hack apart. uint8_t KeyboardKeys[NUMGAMEFUNCTIONS][2]; +static FString stringStore[2 * NUMGAMEFUNCTIONS]; // toss all persistent strings from the OSDCMDs in here so that they stick around until shutdown. -static void InitNameToNum() +CVAR(Int, cl_defaultconfiguration, 2, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) + +static int osdcmd_button(osdcmdptr_t parm) { - GF_NumToName.Resize(NUMGAMEFUNCTIONS); - GF_NumToAlias.Resize(NUMGAMEFUNCTIONS); + static char const s_gamefunc_[] = "gamefunc_"; + int constexpr strlen_gamefunc_ = ARRAY_SIZE(s_gamefunc_) - 1; + + char const* p = parm->name + strlen_gamefunc_; + + //if (gInputMode == kInputGame) // only trigger these if in game (fixme: Ensure it works for all games!) + CONTROL_ButtonFlags[CONFIG_FunctionNameToNum(p)] = 1; // FIXME + + return OSDCMD_OK; +} + +void SetupButtonFunctions() +{ + unsigned index = 0; + // Note: This must run after the CON scripts had a chance to mess around with the game function name array. + for (auto& func : GF_NumToAlias) + { + if (func[0] == '\0') + continue; + + } + +} + +void CONFIG_Init() +{ + // This must be done before initializing any data, so doing it late in the startup process won't work. + if (CONTROL_Startup(controltype_keyboardandmouse, BGetTime, gi->TicRate)) + { + exit(1); + } + + int index = 0; for(auto &gf : gamefuncs) { GF_NameToNum.Insert(gf.name, gf.index); GF_NumToAlias[gf.index] = GF_NumToName[gf.index] = gf.name; + + stringStore[index].Format("gamefunc_%s", gf.name); + stringStore[index].ToLower(); + stringStore[index + 1] = stringStore[index]; + stringStore[index + 1] += ": game button"; + OSD_RegisterFunction(stringStore[index], stringStore[index + 1], osdcmd_button); + index += 2; + } + CONTROL_ClearAssignments(); + CONFIG_SetDefaultKeys(cl_defaultconfiguration == 1 ? "demolition/origbinds.txt" : cl_defaultconfiguration == 2 ? "demolition/leftbinds.txt" : "demolition/defbinds.txt"); } int32_t CONFIG_FunctionNameToNum(const char *func) @@ -256,36 +304,3 @@ void CONFIG_SetDefaultKeys(const char *defbinds, bool lazy/*=false*/) } } - -static int osdcmd_button(osdcmdptr_t parm) -{ - static char const s_gamefunc_[] = "gamefunc_"; - int constexpr strlen_gamefunc_ = ARRAY_SIZE(s_gamefunc_) - 1; - - char const *p = parm->name + strlen_gamefunc_; - - //if (gInputMode == kInputGame) // only trigger these if in game (fixme: Ensure it works for all games!) - CONTROL_ButtonFlags[CONFIG_FunctionNameToNum(p)] = 1; // FIXME - - return OSDCMD_OK; -} - -static FString stringStore[2*NUMGAMEFUNCTIONS]; // toss all persistent strings in here so that they stick around until shutdown. -void SetupButtonFunctions() -{ - unsigned index = 0; - // Note: This must run after the CON scripts had a chance to mess around with the game function name array. - for (auto & func : GF_NumToAlias) - { - if (func[0] == '\0') - continue; - - stringStore[index].Format("gamefunc_%s", func); - stringStore[index].ToLower(); - stringStore[index+1] = stringStore[index]; - stringStore[index+1] += ": game button"; - OSD_RegisterFunction(stringStore[index], stringStore[index+1], osdcmd_button); - index += 2; - } - -} \ No newline at end of file diff --git a/source/common/gamecontrol.h b/source/common/gamecontrol.h index b233c5c6d..9a8be7ddd 100644 --- a/source/common/gamecontrol.h +++ b/source/common/gamecontrol.h @@ -2,7 +2,7 @@ #include "keyboard.h" -// Order is that of EDuke32 by necessity because it exposes this array to scripting. +// Order is that of EDuke32 by necessity because it exposes the key binds to scripting by index instead of by name. enum GameFunction_t { gamefunc_Move_Forward, @@ -35,6 +35,7 @@ enum GameFunction_t gamefunc_Weapon_9, gamefunc_Weapon_10, gamefunc_Inventory, + gamefunc_Inventory_Use = gamefunc_Inventory, gamefunc_Inventory_Left, gamefunc_Inventory_Right, gamefunc_Holo_Duke, @@ -46,6 +47,7 @@ enum GameFunction_t gamefunc_TurnAround, gamefunc_SendMessage, gamefunc_Map, + gamefunc_Map_Toggle = gamefunc_Map, gamefunc_Shrink_Screen, gamefunc_Enlarge_Screen, gamefunc_Center_View, @@ -78,15 +80,13 @@ enum GameFunction_t gamefunc_Aim_Center, gamefunc_Tilt_Left, gamefunc_Tilt_Right, - gamefunc_Inventory_Use, - gamefunc_Map_Toggle, gamefunc_Send_Message, gamefunc_BeastVision, gamefunc_CrystalBall, gamefunc_JumpBoots, gamefunc_ProximityBombs, gamefunc_RemoteBombs, - gamefunc_Smoke_Bomb, + gamefunc_Smoke_Bomb, // and these by ShadowWarrior (todo: There's quite a bit of potential for consolidation here - is it worth it?) gamefunc_Gas_Bomb, gamefunc_Flash_Bomb, gamefunc_Caltrops, @@ -96,6 +96,7 @@ enum GameFunction_t extern uint8_t KeyboardKeys[NUMGAMEFUNCTIONS][2]; +void CONFIG_Init(); void CONFIG_SetDefaultKeys(const char *defbinds, bool lazy=false); int32_t CONFIG_FunctionNameToNum(const char* func); const char* CONFIG_FunctionNumToName(int32_t func); diff --git a/source/common/gamecvars.cpp b/source/common/gamecvars.cpp index f130f27f4..300cfd6d4 100644 --- a/source/common/gamecvars.cpp +++ b/source/common/gamecvars.cpp @@ -43,7 +43,6 @@ #include "control.h" #include "_control.h" #include "gamecontrol.h" -#include "build.h" /* Notes @@ -53,35 +52,6 @@ */ -CVAR(Int, cl_defaultconfiguration, 2, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) - -FGameConfigFile* GameConfig; -static FString GameName; - -void G_LoadConfig(const char *game) -{ - // This must be done before initializing any data, so doing it late in the startup process won't work. - if (CONTROL_Startup(controltype_keyboardandmouse, BGetTime, gi->TicRate )) - { - exit(1); - } - - CONFIG_SetDefaultKeys(cl_defaultconfiguration == 1 ? "demolition/origbinds.txt" : cl_defaultconfiguration == 2 ? "demolition/leftbinds.txt" : "demolition/defbinds.txt"); - GameConfig = new FGameConfigFile(); - GameConfig->DoGlobalSetup(); - GameConfig->DoGameSetup(game); - FBaseCVar::EnableCallbacks(); - GameName = game; -} - -void G_SaveConfig() -{ - GameConfig->ArchiveGameData(GameName); - GameConfig->WriteConfigFile(); - delete GameConfig; - GameConfig = nullptr; -} - CVARD(Bool, cl_crosshair, true, CVAR_ARCHIVE, "enable/disable crosshair"); CVARD(Bool, cl_automsg, false, CVAR_ARCHIVE, "enable/disable automatically sending messages to all players") // Not implemented for Blood CVARD(Bool, cl_autorun, true, CVAR_ARCHIVE, "enable/disable autorun") @@ -295,7 +265,7 @@ CUSTOM_CVARD(Int, hud_weaponscale, 100, CVAR_ARCHIVE|CVAR_FRONTEND_DUKELIKE, "ch CUSTOM_CVARD(Int, r_fov, 90, CVAR_ARCHIVE|CVAR_GLOBALCONFIG, "change the field of view") { if (self < 60) self = 60; - else if (self < 140) self = 140; + else if (self > 140) self = 140; } CVARD(Bool, r_horizcenter, false, CVAR_ARCHIVE|CVAR_FRONTEND_BLOOD, "enable/disable centered horizon line") // only present in Blood, maybe add to others? diff --git a/source/common/gamecvars.h b/source/common/gamecvars.h index 2c5f16df6..a3ff9a0a5 100644 --- a/source/common/gamecvars.h +++ b/source/common/gamecvars.h @@ -98,6 +98,4 @@ extern float r_ambientlightrecip; extern int hud_statusbarrange; // will be set by the game's configuration setup. bool G_ChangeHudLayout(int direction); bool G_CheckAutorun(bool button); -void G_LoadConfig(const char*); -void G_SaveConfig(); int G_FPSLimit(void); diff --git a/source/duke3d/src/config.cpp b/source/duke3d/src/config.cpp index ad28ff9e0..8db7c4a43 100644 --- a/source/duke3d/src/config.cpp +++ b/source/duke3d/src/config.cpp @@ -606,7 +606,6 @@ int CONFIG_ReadSetup(void) { char tempbuf[1024]; - CONTROL_ClearAssignments(); CONFIG_SetDefaults(); ud.config.setupread = 1; diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index 3ad34cf54..46a16b755 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -41,42 +41,7 @@ #include "palette.h" #include "baselayer.h" -#include "resourcefile.h" -std::unique_ptr engine_res; - -// The resourge manager in cache1d is far too broken to add some arbitrary file without some adjustment. -// For now, keep this file here, until the resource management can be redone in a more workable fashion. -extern FString progdir; - -void InitBaseRes() -{ - if (!engine_res) - { - // If we get here for the first time, load the engine-internal data. - FString baseres = progdir + "demolition.pk3"; - engine_res.reset(FResourceFile::OpenResourceFile(baseres, true, true)); - if (!engine_res) - { - FStringf msg("Engine resources (%s) not found", baseres.GetChars()); - wm_msgbox("Fatal error", msg.GetChars()); - exit(-1); - } - } -} - -extern FString currentGame; -FileReader openFromBaseResource(const char* fn) -{ - auto lump = engine_res->FindLump(fn); - if (lump) return lump->NewReader(); - // Also look in game filtered directories. - FStringf filtername("filter/%s/%s", currentGame.GetChars(), fn); - lump = engine_res->FindLump(fn); - if (lump) return lump->NewReader(); - return FileReader(nullptr); - -} FileReader GetResource(const char* fn) { @@ -99,7 +64,6 @@ GLInstance::GLInstance() void GLInstance::Init() { - InitBaseRes(); if (!mSamplers) { mSamplers = new FSamplerManager; diff --git a/source/rr/src/config.cpp b/source/rr/src/config.cpp index afc720288..7821cc49e 100644 --- a/source/rr/src/config.cpp +++ b/source/rr/src/config.cpp @@ -411,7 +411,6 @@ int32_t CONFIG_ReadSetup(void) char commmacro[] = "CommbatMacro# "; char tempbuf[1024]; - CONTROL_ClearAssignments(); CONFIG_SetDefaults(); ud.config.setupread = 1; diff --git a/source/sw/src/config.cpp b/source/sw/src/config.cpp index d0b3c2ef8..387deefe8 100644 --- a/source/sw/src/config.cpp +++ b/source/sw/src/config.cpp @@ -498,7 +498,6 @@ int32_t CONFIG_ReadSetup(void) char waveformtrackname[MAXWAVEFORMTRACKLENGTH] = {0}; - CONTROL_ClearAssignments(); CONFIG_SetDefaults(); if (buildvfs_exists(setupfilename)) diff --git a/wadsrc/static/filter/game-blood/demolition/defbinds.txt b/wadsrc/static/filter/game-blood/demolition/defbinds.txt index 10080633f..b98b05a24 100644 --- a/wadsrc/static/filter/game-blood/demolition/defbinds.txt +++ b/wadsrc/static/filter/game-blood/demolition/defbinds.txt @@ -33,7 +33,7 @@ "Inventory", "Enter", "KpdEnt" "Inventory_Left", "[" "Inventory_Right", "]" -"Map_Toggle", "Tab" +"Map", "Tab" "Map_Follow_Mode", "F" "Shrink_Screen", "-", "Kpad-" "Enlarge_Screen", "=", "Kpad+" diff --git a/wadsrc/static/filter/game-blood/demolition/leftbinds.txt b/wadsrc/static/filter/game-blood/demolition/leftbinds.txt index 9ad35fad2..a7b60d0ae 100644 --- a/wadsrc/static/filter/game-blood/demolition/leftbinds.txt +++ b/wadsrc/static/filter/game-blood/demolition/leftbinds.txt @@ -33,7 +33,7 @@ "Inventory", "Enter", "KpdEnt" "Inventory_Left", "[" "Inventory_Right", "]" -"Map_Toggle", "Tab" +"Map", "Tab" "Map_Follow_Mode", "F" "Shrink_Screen", "-" "Enlarge_Screen", "=" diff --git a/wadsrc/static/filter/game-blood/demolition/origbinds.txt b/wadsrc/static/filter/game-blood/demolition/origbinds.txt index cb76b302b..a8a36da7d 100644 --- a/wadsrc/static/filter/game-blood/demolition/origbinds.txt +++ b/wadsrc/static/filter/game-blood/demolition/origbinds.txt @@ -33,7 +33,7 @@ "Inventory", "Enter", "KpdEnt" "Inventory_Left", "[" "Inventory_Right", "]" -"Map_Toggle", "Tab" +"Map", "Tab" "Map_Follow_Mode", "F" "Shrink_Screen", "-", "Kpad-" "Enlarge_Screen", "=", "Kpad+"