mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-12-12 13:42:53 +00:00
- split defcvars parser into its own file
This commit is contained in:
parent
3102640210
commit
79cbaf5d4f
3 changed files with 133 additions and 93 deletions
|
@ -810,6 +810,7 @@ set (PCH_SOURCES
|
|||
ct_chat.cpp
|
||||
d_iwad.cpp
|
||||
d_main.cpp
|
||||
d_defcvars.cpp
|
||||
d_anonstats.cpp
|
||||
d_net.cpp
|
||||
d_netinfo.cpp
|
||||
|
|
131
src/d_defcvars.cpp
Normal file
131
src/d_defcvars.cpp
Normal file
|
@ -0,0 +1,131 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright 1993-1996 id Software
|
||||
// Copyright 1999-2016 Randy Heit
|
||||
// Copyright 2002-2016 Christoph Oelckers
|
||||
// Copyright 2019-2021 Rachael Alexanderson
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see http://www.gnu.org/licenses/
|
||||
//
|
||||
//
|
||||
// DESCRIPTION:
|
||||
// defcvars loader split from d_main.cpp
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// HEADER FILES ------------------------------------------------------------
|
||||
|
||||
#include "doomdef.h"
|
||||
#include "doomstat.h"
|
||||
#include "gstrings.h"
|
||||
#include "filesystem.h"
|
||||
#include "menu.h"
|
||||
#include "doommenu.h"
|
||||
#include "c_console.h"
|
||||
#include "d_main.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
void D_GrabCVarDefaults()
|
||||
{
|
||||
int lump, lastlump = 0;
|
||||
int lumpversion, gamelastrunversion;
|
||||
gamelastrunversion = atoi(LASTRUNVERSION);
|
||||
|
||||
while ((lump = fileSystem.FindLump("DEFCVARS", &lastlump)) != -1)
|
||||
{
|
||||
// don't parse from wads
|
||||
if (lastlump > fileSystem.GetLastEntry(fileSystem.GetMaxIwadNum()))
|
||||
{
|
||||
// would rather put this in a modal of some sort, but this will have to do.
|
||||
Printf(TEXTCOLOR_RED "Cannot load DEFCVARS from a wadfile!\n");
|
||||
break;
|
||||
}
|
||||
|
||||
FScanner sc(lump);
|
||||
|
||||
sc.MustGetString();
|
||||
if (!sc.Compare("version"))
|
||||
sc.ScriptError("Must declare version for defcvars! (currently: %i)", gamelastrunversion);
|
||||
sc.MustGetNumber();
|
||||
lumpversion = sc.Number;
|
||||
if (lumpversion > gamelastrunversion)
|
||||
sc.ScriptError("Unsupported version %i (%i supported)", lumpversion, gamelastrunversion);
|
||||
if (lumpversion < 219)
|
||||
sc.ScriptError("Version must be at least 219 (current version %i)", gamelastrunversion);
|
||||
|
||||
FBaseCVar* var;
|
||||
FString CurrentFindCVar;
|
||||
|
||||
while (sc.GetString())
|
||||
{
|
||||
if (sc.Compare("set"))
|
||||
{
|
||||
sc.MustGetString();
|
||||
}
|
||||
|
||||
CurrentFindCVar = sc.String;
|
||||
if (lumpversion < 220)
|
||||
{
|
||||
CurrentFindCVar.ToLower();
|
||||
|
||||
// these two got renamed
|
||||
if (strcmp(CurrentFindCVar, "gamma") == 0)
|
||||
{
|
||||
CurrentFindCVar = "vid_gamma";
|
||||
}
|
||||
if (strcmp(CurrentFindCVar, "fullscreen") == 0)
|
||||
{
|
||||
CurrentFindCVar = "vid_fullscreen";
|
||||
}
|
||||
|
||||
// this was removed
|
||||
if (strcmp(CurrentFindCVar, "cd_drive") == 0)
|
||||
break;
|
||||
}
|
||||
if (lumpversion < 221)
|
||||
{
|
||||
// removed cvar
|
||||
// this one doesn't matter as much, since it depended on platform-specific values,
|
||||
// and is something the user should change anyhow, so, let's just throw this value
|
||||
// out.
|
||||
if (strcmp(CurrentFindCVar, "mouse_sensitivity") == 0)
|
||||
break;
|
||||
if (strcmp(CurrentFindCVar, "m_noprescale") == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
var = FindCVar(CurrentFindCVar, NULL);
|
||||
if (var != NULL)
|
||||
{
|
||||
if (var->GetFlags() & CVAR_ARCHIVE)
|
||||
{
|
||||
UCVarValue val;
|
||||
|
||||
sc.MustGetString();
|
||||
val.String = const_cast<char*>(sc.String);
|
||||
var->SetGenericRepDefault(val, CVAR_String);
|
||||
}
|
||||
else
|
||||
{
|
||||
sc.ScriptError("Cannot set cvar default for non-config cvar '%s'", sc.String);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sc.ScriptError("Unknown cvar '%s'", sc.String);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -169,6 +169,7 @@ void D_Cleanup();
|
|||
void FreeSBarInfoScript();
|
||||
void I_UpdateWindowTitle();
|
||||
void S_ParseMusInfo();
|
||||
void D_GrabCVarDefaults();
|
||||
|
||||
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
|
||||
|
||||
|
@ -331,99 +332,6 @@ static int pagetic;
|
|||
|
||||
// CODE --------------------------------------------------------------------
|
||||
|
||||
void D_GrabCVarDefaults()
|
||||
{
|
||||
int lump, lastlump = 0;
|
||||
int lumpversion, gamelastrunversion;
|
||||
gamelastrunversion = atoi(LASTRUNVERSION);
|
||||
|
||||
while ((lump = fileSystem.FindLump("DEFCVARS", &lastlump)) != -1)
|
||||
{
|
||||
// don't parse from wads
|
||||
if (lastlump > fileSystem.GetLastEntry(fileSystem.GetMaxIwadNum()))
|
||||
{
|
||||
// would rather put this in a modal of some sort, but this will have to do.
|
||||
Printf(TEXTCOLOR_RED "Cannot load DEFCVARS from a wadfile!\n");
|
||||
break;
|
||||
}
|
||||
|
||||
FScanner sc(lump);
|
||||
|
||||
sc.MustGetString();
|
||||
if (!sc.Compare("version"))
|
||||
sc.ScriptError("Must declare version for defcvars! (currently: %i)", gamelastrunversion);
|
||||
sc.MustGetNumber();
|
||||
lumpversion = sc.Number;
|
||||
if (lumpversion > gamelastrunversion)
|
||||
sc.ScriptError("Unsupported version %i (%i supported)", lumpversion, gamelastrunversion);
|
||||
if (lumpversion < 219)
|
||||
sc.ScriptError("Version must be at least 219 (current version %i)", gamelastrunversion);
|
||||
|
||||
FBaseCVar* var;
|
||||
FString CurrentFindCVar;
|
||||
|
||||
while (sc.GetString())
|
||||
{
|
||||
if (sc.Compare("set"))
|
||||
{
|
||||
sc.MustGetString();
|
||||
}
|
||||
|
||||
CurrentFindCVar = sc.String;
|
||||
if (lumpversion < 220)
|
||||
{
|
||||
CurrentFindCVar.ToLower();
|
||||
|
||||
// these two got renamed
|
||||
if (strcmp(CurrentFindCVar, "gamma") == 0)
|
||||
{
|
||||
CurrentFindCVar = "vid_gamma";
|
||||
}
|
||||
if (strcmp(CurrentFindCVar, "fullscreen") == 0)
|
||||
{
|
||||
CurrentFindCVar = "vid_fullscreen";
|
||||
}
|
||||
|
||||
// this was removed
|
||||
if (strcmp(CurrentFindCVar, "cd_drive") == 0)
|
||||
break;
|
||||
}
|
||||
if (lumpversion < 221)
|
||||
{
|
||||
// removed cvar
|
||||
// this one doesn't matter as much, since it depended on platform-specific values,
|
||||
// and is something the user should change anyhow, so, let's just throw this value
|
||||
// out.
|
||||
if (strcmp(CurrentFindCVar, "mouse_sensitivity") == 0)
|
||||
break;
|
||||
if (strcmp(CurrentFindCVar, "m_noprescale") == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
var = FindCVar(CurrentFindCVar, NULL);
|
||||
if (var != NULL)
|
||||
{
|
||||
if (var->GetFlags() & CVAR_ARCHIVE)
|
||||
{
|
||||
UCVarValue val;
|
||||
|
||||
sc.MustGetString();
|
||||
val.String = const_cast<char*>(sc.String);
|
||||
var->SetGenericRepDefault(val, CVAR_String);
|
||||
}
|
||||
else
|
||||
{
|
||||
sc.ScriptError("Cannot set cvar default for non-config cvar '%s'", sc.String);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sc.ScriptError("Unknown cvar '%s'", sc.String);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// D_ToggleHud
|
||||
|
|
Loading…
Reference in a new issue