- game starts again.

This commit is contained in:
Christoph Oelckers 2019-10-26 13:16:32 +02:00
parent f1cdaf6054
commit 1e0d49f947
17 changed files with 152 additions and 137 deletions

View file

@ -289,3 +289,5 @@ extern short gProxySpritesCount;
extern short gSightSpritesCount;
extern short gPhysSpritesCount;
//extern short gQavPlayerIndex;
END_BLD_NS

View file

@ -449,7 +449,6 @@ int CONFIG_ReadSetup(void)
{
char tempbuf[1024];
CONTROL_ClearAssignments();
CONFIG_SetDefaults();
setupread = 1;

View file

@ -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);
}

View file

@ -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<std::wstring> wgames;
TArray<TASKDIALOG_BUTTON> 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<FResourceFile> 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)
{

View file

@ -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;
}

View file

@ -72,5 +72,7 @@ private:
};
extern FGameConfigFile *GameConfig;
void G_LoadConfig(const char*);
void G_SaveConfig();
#endif //__GAMECONFIGFILE_H__

View file

@ -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<FName, int> GF_NameToNum;
static TArray<FString> 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<FString> 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;
}
}

View file

@ -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);

View file

@ -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?

View file

@ -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);

View file

@ -606,7 +606,6 @@ int CONFIG_ReadSetup(void)
{
char tempbuf[1024];
CONTROL_ClearAssignments();
CONFIG_SetDefaults();
ud.config.setupread = 1;

View file

@ -41,42 +41,7 @@
#include "palette.h"
#include "baselayer.h"
#include "resourcefile.h"
std::unique_ptr<FResourceFile> 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;

View file

@ -411,7 +411,6 @@ int32_t CONFIG_ReadSetup(void)
char commmacro[] = "CommbatMacro# ";
char tempbuf[1024];
CONTROL_ClearAssignments();
CONFIG_SetDefaults();
ud.config.setupread = 1;

View file

@ -498,7 +498,6 @@ int32_t CONFIG_ReadSetup(void)
char waveformtrackname[MAXWAVEFORMTRACKLENGTH] = {0};
CONTROL_ClearAssignments();
CONFIG_SetDefaults();
if (buildvfs_exists(setupfilename))

View file

@ -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+"

View file

@ -33,7 +33,7 @@
"Inventory", "Enter", "KpdEnt"
"Inventory_Left", "["
"Inventory_Right", "]"
"Map_Toggle", "Tab"
"Map", "Tab"
"Map_Follow_Mode", "F"
"Shrink_Screen", "-"
"Enlarge_Screen", "="

View file

@ -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+"