Skip to content

Commit 13ec015

Browse files
committed
Add per-game archived cvars
Keep engine-level archived cvars in the global user config while writing controls and game-specific settings to the current game config. Introduce CVAR_ARCHIVE_GAME as a mutually exclusive archive domain and load the global config before the game config when executing the legacy config entry point.
1 parent 282cdc7 commit 13ec015

15 files changed

Lines changed: 112 additions & 85 deletions

File tree

Quake/bgmusic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#define MUSIC_DIRNAME "music"
3030

3131
static qboolean bgmloop;
32-
cvar_t bgm_extmusic = {"bgm_extmusic", "1", CVAR_ARCHIVE};
32+
cvar_t bgm_extmusic = {"bgm_extmusic", "1", CVAR_ARCHIVE_GAME};
3333

3434
static qboolean no_extmusic = false;
3535
static float old_volume = -1.0f;

Quake/cl_input.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,8 @@ float CL_KeyState (kbutton_t *key)
321321
//==========================================================================
322322

323323
cvar_t cl_upspeed = {"cl_upspeed", "200", CVAR_NONE};
324-
cvar_t cl_forwardspeed = {"cl_forwardspeed", "200", CVAR_ARCHIVE};
325-
cvar_t cl_backspeed = {"cl_backspeed", "200", CVAR_ARCHIVE};
324+
cvar_t cl_forwardspeed = {"cl_forwardspeed", "200", CVAR_ARCHIVE_GAME};
325+
cvar_t cl_backspeed = {"cl_backspeed", "200", CVAR_ARCHIVE_GAME};
326326
cvar_t cl_sidespeed = {"cl_sidespeed", "350", CVAR_NONE};
327327

328328
cvar_t cl_movespeedkey = {"cl_movespeedkey", "2.0", CVAR_NONE};
@@ -332,7 +332,7 @@ cvar_t cl_pitchspeed = {"cl_pitchspeed", "150", CVAR_NONE};
332332

333333
cvar_t cl_anglespeedkey = {"cl_anglespeedkey", "1.5", CVAR_NONE};
334334

335-
cvar_t cl_alwaysrun = {"cl_alwaysrun", "1", CVAR_ARCHIVE}; // QuakeSpasm -- new always run
335+
cvar_t cl_alwaysrun = {"cl_alwaysrun", "1", CVAR_ARCHIVE_GAME}; // QuakeSpasm -- new always run
336336

337337
/*
338338
==============

Quake/cl_main.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,27 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2828
// references them even when on a unix system.
2929

3030
// these two are not intended to be set directly
31-
cvar_t cl_name = {"_cl_name", "player", CVAR_ARCHIVE | CVAR_USERINFO};
31+
cvar_t cl_name = {"_cl_name", "player", CVAR_ARCHIVE_GAME | CVAR_USERINFO};
3232

33-
cvar_t cl_topcolor = {"topcolor", "0", CVAR_ARCHIVE | CVAR_USERINFO};
34-
cvar_t cl_bottomcolor = {"bottomcolor", "0", CVAR_ARCHIVE | CVAR_USERINFO};
33+
cvar_t cl_topcolor = {"topcolor", "0", CVAR_ARCHIVE_GAME | CVAR_USERINFO};
34+
cvar_t cl_bottomcolor = {"bottomcolor", "0", CVAR_ARCHIVE_GAME | CVAR_USERINFO};
3535

3636
cvar_t cl_shownet = {"cl_shownet", "0", CVAR_NONE}; // can be 0, 1, or 2
3737
cvar_t cl_nolerp = {"cl_nolerp", "0", CVAR_NONE};
3838

39-
cvar_t cfg_unbindall = {"cfg_unbindall", "1", CVAR_ARCHIVE};
39+
cvar_t cfg_unbindall = {"cfg_unbindall", "1", CVAR_ARCHIVE_GAME};
4040

4141
cvar_t lookspring = {"lookspring", "0", CVAR_NONE};
4242
cvar_t lookstrafe = {"lookstrafe", "0", CVAR_NONE};
43-
cvar_t sensitivity = {"sensitivity", "3", CVAR_ARCHIVE};
43+
cvar_t sensitivity = {"sensitivity", "3", CVAR_ARCHIVE_GAME};
4444

45-
cvar_t m_pitch = {"m_pitch", "0.022", CVAR_ARCHIVE};
46-
cvar_t m_yaw = {"m_yaw", "0.022", CVAR_ARCHIVE};
47-
cvar_t m_forward = {"m_forward", "1", CVAR_ARCHIVE};
48-
cvar_t m_side = {"m_side", "0.8", CVAR_ARCHIVE};
45+
cvar_t m_pitch = {"m_pitch", "0.022", CVAR_ARCHIVE_GAME};
46+
cvar_t m_yaw = {"m_yaw", "0.022", CVAR_ARCHIVE_GAME};
47+
cvar_t m_forward = {"m_forward", "1", CVAR_ARCHIVE_GAME};
48+
cvar_t m_side = {"m_side", "0.8", CVAR_ARCHIVE_GAME};
4949

50-
cvar_t cl_maxpitch = {"cl_maxpitch", "90", CVAR_ARCHIVE}; // johnfitz -- variable pitch clamping
51-
cvar_t cl_minpitch = {"cl_minpitch", "-90", CVAR_ARCHIVE}; // johnfitz -- variable pitch clamping
50+
cvar_t cl_maxpitch = {"cl_maxpitch", "90", CVAR_ARCHIVE_GAME}; // johnfitz -- variable pitch clamping
51+
cvar_t cl_minpitch = {"cl_minpitch", "-90", CVAR_ARCHIVE_GAME}; // johnfitz -- variable pitch clamping
5252

5353
cvar_t cl_startdemos = {"cl_startdemos", "1", CVAR_ARCHIVE};
5454
cvar_t cl_confirmquit = {"cl_confirmquit", "0", CVAR_ARCHIVE};

Quake/cmd.c

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,6 @@ void Cmd_StuffCmds_f (void)
263263
Cbuf_InsertText (cmds);
264264
}
265265

266-
/*
267-
===============
268-
Cmd_Exec_f
269-
===============
270-
*/
271266
void Cmd_Exec_f (void)
272267
{
273268
char *buf = NULL;
@@ -288,9 +283,9 @@ void Cmd_Exec_f (void)
288283
if (legacy_config_alias)
289284
{
290285
FILE *f;
286+
char *game_buf;
291287
qfilesize_t length;
292288

293-
// "exec config.cfg" executes vkQuake.cfg from the user config directory.
294289
f = COM_FOpenPrefFile (CONFIG_NAME, "rb");
295290
if (f)
296291
{
@@ -302,12 +297,34 @@ void Cmd_Exec_f (void)
302297
buf = NULL;
303298
}
304299
else
305-
{
306300
buf[length] = 0;
307-
display_path = CONFIG_NAME;
308-
}
309301
fclose (f);
310302
}
303+
game_buf = (char *)COM_LoadFile (path, NULL);
304+
if (!buf && !game_buf)
305+
{
306+
if (cmd_warncmd.value)
307+
Con_Printf ("couldn't exec %s\n", path);
308+
return;
309+
}
310+
311+
if (cmd_warncmd.value)
312+
{
313+
if (buf)
314+
Con_Printf ("execing %s\n", CONFIG_NAME);
315+
if (game_buf)
316+
Con_Printf ("execing %s\n", path);
317+
}
318+
319+
Cbuf_InsertText ("\n"); // just in case there was no trailing \n.
320+
if (game_buf)
321+
Cbuf_InsertText (game_buf);
322+
if (buf)
323+
Cbuf_InsertText (buf);
324+
325+
Mem_Free (game_buf);
326+
Mem_Free (buf);
327+
return;
311328
}
312329
else
313330
buf = (char *)COM_LoadFile (path, NULL);

Quake/cvar.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ void Cvar_List_f (void)
6363
{
6464
continue;
6565
}
66-
Con_SafePrintf ("%s%s %s \"%s\"\n", (cvar->flags & CVAR_ARCHIVE) ? "*" : " ", (cvar->flags & CVAR_NOTIFY) ? "s" : " ", cvar->name, cvar->string);
66+
Con_SafePrintf (
67+
"%s%s %s \"%s\"\n", (cvar->flags & (CVAR_ARCHIVE | CVAR_ARCHIVE_GAME)) ? "*" : " ", (cvar->flags & CVAR_NOTIFY) ? "s" : " ", cvar->name,
68+
cvar->string);
6769
count++;
6870
}
6971

@@ -283,7 +285,7 @@ void Cvar_ResetCfg_f (void)
283285
cvar_t *var;
284286

285287
for (var = cvar_vars; var; var = var->next)
286-
if (var->flags & CVAR_ARCHIVE)
288+
if (var->flags & (CVAR_ARCHIVE | CVAR_ARCHIVE_GAME))
287289
Cvar_Reset (var->name);
288290
}
289291

@@ -788,13 +790,13 @@ Writes lines containing "set variable value" for all variables
788790
with the archive flag set to true.
789791
============
790792
*/
791-
void Cvar_WriteVariables (FILE *f)
793+
void Cvar_WriteVariables (FILE *f, cvarflags_t archive_flag)
792794
{
793795
cvar_t *var;
794796

795797
for (var = cvar_vars; var; var = var->next)
796798
{
797-
if (var->flags & CVAR_ARCHIVE)
799+
if (var->flags & archive_flag)
798800
{
799801
if (var->flags & (CVAR_USERDEFINED | CVAR_SETA))
800802
fprintf (f, "seta ");

Quake/cvar.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,12 @@ interface from being ambiguous.
6666
typedef enum
6767
{
6868
CVAR_NONE = 0,
69-
CVAR_ARCHIVE = (1U << 0), // if set, causes it to be saved to config
70-
CVAR_NOTIFY = (1U << 1), // changes will be broadcasted to all players (q1)
71-
CVAR_SERVERINFO = (1U << 2), // added to serverinfo will be sent to clients (q1/net_dgrm.c and qwsv)
72-
CVAR_USERINFO = (1U << 3), // added to userinfo, will be sent to server (qwcl)
73-
CVAR_CHANGED = (1U << 4),
69+
CVAR_ARCHIVE = (1U << 0), // saved to the global config
70+
CVAR_ARCHIVE_GAME = (1U << 1), // saved to the current game config
71+
CVAR_NOTIFY = (1U << 2), // changes will be broadcasted to all players (q1)
72+
CVAR_SERVERINFO = (1U << 3), // added to serverinfo will be sent to clients (q1/net_dgrm.c and qwsv)
73+
CVAR_USERINFO = (1U << 4), // added to userinfo, will be sent to server (qwcl)
74+
CVAR_CHANGED = (1U << 5),
7475
CVAR_ROM = (1U << 6),
7576
CVAR_LOCKED = (1U << 8), // locked temporarily
7677
CVAR_REGISTERED = (1U << 10), // the var is added to the list of variables
@@ -136,9 +137,9 @@ qboolean Cvar_Command (void);
136137
// command. Returns true if the command was a variable reference that
137138
// was handled. (print or change)
138139

139-
void Cvar_WriteVariables (FILE *f);
140+
void Cvar_WriteVariables (FILE *f, cvarflags_t archive_flag);
140141
// Writes lines containing "set variable value" for all variables
141-
// with the CVAR_ARCHIVE flag set
142+
// with the requested archive flag set
142143

143144
cvar_t *Cvar_FindVar (const char *var_name);
144145
cvar_t *Cvar_FindVarAfter (const char *prev_name, unsigned int with_flags);

Quake/gl_model.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ static void Mod_LoadMD3Model (qmodel_t *mod, const void *buffer);
3434
static qmodel_t *Mod_LoadModel (qmodel_t *mod, qboolean crash);
3535
static void Mod_FreeModelMemory (qmodel_t *mod);
3636

37-
cvar_t external_ents = {"external_ents", "1", CVAR_ARCHIVE};
38-
cvar_t external_vis = {"external_vis", "1", CVAR_ARCHIVE};
37+
cvar_t external_ents = {"external_ents", "1", CVAR_ARCHIVE_GAME};
38+
cvar_t external_vis = {"external_vis", "1", CVAR_ARCHIVE_GAME};
3939

4040
// wad_external_textures = 1 enable loading of external WAD textures, 0 to forbid it for debug purposes.
4141
cvar_t wad_external_textures = {"wad_external_textures", "1", CVAR_NONE};
@@ -49,7 +49,7 @@ cvar_t r_allow_replacement_md5models = {"r_allow_replacement_md5models", "1", CV
4949
// r_allow_replacement_md3models = 1 allow loading of MD3 replacement models if available, 0 to forbid it for debug purposes.
5050
cvar_t r_allow_replacement_md3models = {"r_allow_replacement_md3models", "1", CVAR_NONE};
5151

52-
cvar_t r_enhancedmodels = {"r_enhancedmodels", "1", CVAR_ARCHIVE}; // controlled in Menu with Models: enhanced (1) / classic (0)
52+
cvar_t r_enhancedmodels = {"r_enhancedmodels", "1", CVAR_ARCHIVE_GAME}; // controlled in Menu with Models: enhanced (1) / classic (0)
5353

5454
static byte *mod_novis;
5555
static int mod_novis_capacity;

Quake/gl_screen.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,22 @@ cvar_t scr_showfps = {"scr_showfps", "0", CVAR_ARCHIVE};
9292
cvar_t scr_clock = {"scr_clock", "0", CVAR_NONE};
9393
cvar_t scr_autoclock = {"scr_autoclock", "1", CVAR_ARCHIVE};
9494
cvar_t scr_usekfont = {"scr_usekfont", "0", CVAR_NONE}; // 2021 re-release
95-
cvar_t scr_style = {"scr_style", "0", CVAR_ARCHIVE};
96-
97-
cvar_t scr_viewsize = {"viewsize", "100", CVAR_ARCHIVE};
98-
cvar_t scr_viewsize_allow_shrinking = {"viewsize_allow_shrinking", "0", CVAR_ARCHIVE};
99-
cvar_t scr_fov = {"fov", "90", CVAR_ARCHIVE}; // 10 - 170
100-
cvar_t scr_fov_adapt = {"fov_adapt", "1", CVAR_ARCHIVE};
101-
cvar_t scr_zoomfov = {"zoom_fov", "30", CVAR_ARCHIVE}; // 10 - 170
102-
cvar_t scr_zoomspeed = {"zoom_speed", "8", CVAR_ARCHIVE};
95+
cvar_t scr_style = {"scr_style", "0", CVAR_ARCHIVE_GAME};
96+
97+
cvar_t scr_viewsize = {"viewsize", "100", CVAR_ARCHIVE_GAME};
98+
cvar_t scr_viewsize_allow_shrinking = {"viewsize_allow_shrinking", "0", CVAR_ARCHIVE_GAME};
99+
cvar_t scr_fov = {"fov", "90", CVAR_ARCHIVE_GAME}; // 10 - 170
100+
cvar_t scr_fov_adapt = {"fov_adapt", "1", CVAR_ARCHIVE_GAME};
101+
cvar_t scr_zoomfov = {"zoom_fov", "30", CVAR_ARCHIVE_GAME}; // 10 - 170
102+
cvar_t scr_zoomspeed = {"zoom_speed", "8", CVAR_ARCHIVE_GAME};
103103
cvar_t scr_conspeed = {"scr_conspeed", "500", CVAR_ARCHIVE};
104104
cvar_t scr_conanim = {"scr_conanim", "0", CVAR_ARCHIVE};
105105
cvar_t scr_centertime = {"scr_centertime", "2", CVAR_NONE};
106106
cvar_t scr_showturtle = {"showturtle", "0", CVAR_NONE};
107107
cvar_t scr_showpause = {"showpause", "1", CVAR_NONE};
108108
cvar_t scr_printspeed = {"scr_printspeed", "8", CVAR_NONE};
109109

110-
cvar_t cl_gun_fovscale = {"cl_gun_fovscale", "1", CVAR_ARCHIVE}; // Qrack
110+
cvar_t cl_gun_fovscale = {"cl_gun_fovscale", "1", CVAR_ARCHIVE_GAME}; // Qrack
111111

112112
// All scaling is done relative to resolution with scr_relativescale
113113
cvar_t scr_relativescale = {"scr_relativescale", "2", CVAR_ARCHIVE};

Quake/host.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ cvar_t coop = {"coop", "0", CVAR_NONE}; // 0 or 1
8787

8888
cvar_t pausable = {"pausable", "1", CVAR_NONE};
8989

90-
cvar_t autoload = {"autoload", "1", CVAR_ARCHIVE};
91-
cvar_t autofastload = {"autofastload", "0", CVAR_ARCHIVE};
90+
cvar_t autoload = {"autoload", "1", CVAR_ARCHIVE_GAME};
91+
cvar_t autofastload = {"autofastload", "0", CVAR_ARCHIVE_GAME};
9292

9393
cvar_t developer = {"developer", "0", CVAR_NONE};
9494
cvar_t map_checks = {"map_checks", "0", CVAR_NONE};
@@ -409,33 +409,40 @@ void Host_InitLocal (void)
409409
===============
410410
Host_WriteConfiguration
411411
412-
Writes key bindings and archived cvars to the user config
412+
Writes archived cvars to the global config and game-local state to the
413+
current game config
413414
===============
414415
*/
415416
void Host_WriteConfiguration (void)
416417
{
417-
FILE *f = NULL;
418+
FILE *f;
418419

419420
// dedicated servers initialize the host but don't parse and set the config cvars
420421
if (host_initialized && !isDedicated && !host_parms->errstate)
421422
{
422423
f = COM_FOpenPrefFile (CONFIG_NAME, "w");
423424
if (!f)
424425
{
425-
Con_Printf ("Couldn't write " CONFIG_NAME ".\n");
426+
Con_Printf ("Couldn't write global " CONFIG_NAME ".\n");
426427
return;
427428
}
428429

429430
// VID_SyncCvars (); //johnfitz -- write actual current mode to config file, in case cvars were messed with
430431

431-
Key_WriteBindings (f);
432-
Cvar_WriteVariables (f);
433-
434-
// johnfitz -- extra commands to preserve state
432+
Cvar_WriteVariables (f, CVAR_ARCHIVE);
435433
fprintf (f, "vid_restart\n");
436-
fprintf (f, "+mlook\n"); // always enable mouse look on config, can be overriden by -mlook in autoexec.cfg
437-
// johnfitz
434+
fclose (f);
438435

436+
f = Sys_fopen (va ("%s/" CONFIG_NAME, com_gamedir), "w");
437+
if (!f)
438+
{
439+
Con_Printf ("Couldn't write game " CONFIG_NAME ".\n");
440+
return;
441+
}
442+
443+
Key_WriteBindings (f);
444+
Cvar_WriteVariables (f, CVAR_ARCHIVE_GAME);
445+
fprintf (f, "+mlook\n"); // always enable mouse look on config, can be overriden by -mlook in autoexec.cfg
439446
fclose (f);
440447
}
441448
}

Quake/in_sdl.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ static qboolean textmode;
2929
cvar_t in_debugkeys = {"in_debugkeys", "0", CVAR_NONE};
3030

3131
// SDL Game Controller cvars
32-
static cvar_t joy_deadzone_look = {"joy_deadzone_look", "0.175", CVAR_ARCHIVE};
33-
static cvar_t joy_deadzone_move = {"joy_deadzone_move", "0.175", CVAR_ARCHIVE};
34-
static cvar_t joy_outer_threshold_look = {"joy_outer_threshold_look", "0.02", CVAR_ARCHIVE};
35-
static cvar_t joy_outer_threshold_move = {"joy_outer_threshold_move", "0.02", CVAR_ARCHIVE};
36-
static cvar_t joy_deadzone_trigger = {"joy_deadzone_trigger", "0.2", CVAR_ARCHIVE};
37-
static cvar_t joy_sensitivity_yaw = {"joy_sensitivity_yaw", "240", CVAR_ARCHIVE};
38-
static cvar_t joy_sensitivity_pitch = {"joy_sensitivity_pitch", "130", CVAR_ARCHIVE};
39-
static cvar_t joy_invert = {"joy_invert", "0", CVAR_ARCHIVE};
40-
static cvar_t joy_exponent = {"joy_exponent", "2", CVAR_ARCHIVE};
41-
static cvar_t joy_exponent_move = {"joy_exponent_move", "2", CVAR_ARCHIVE};
42-
static cvar_t joy_swapmovelook = {"joy_swapmovelook", "0", CVAR_ARCHIVE};
43-
static cvar_t joy_enable = {"joy_enable", "1", CVAR_ARCHIVE};
32+
static cvar_t joy_deadzone_look = {"joy_deadzone_look", "0.175", CVAR_ARCHIVE_GAME};
33+
static cvar_t joy_deadzone_move = {"joy_deadzone_move", "0.175", CVAR_ARCHIVE_GAME};
34+
static cvar_t joy_outer_threshold_look = {"joy_outer_threshold_look", "0.02", CVAR_ARCHIVE_GAME};
35+
static cvar_t joy_outer_threshold_move = {"joy_outer_threshold_move", "0.02", CVAR_ARCHIVE_GAME};
36+
static cvar_t joy_deadzone_trigger = {"joy_deadzone_trigger", "0.2", CVAR_ARCHIVE_GAME};
37+
static cvar_t joy_sensitivity_yaw = {"joy_sensitivity_yaw", "240", CVAR_ARCHIVE_GAME};
38+
static cvar_t joy_sensitivity_pitch = {"joy_sensitivity_pitch", "130", CVAR_ARCHIVE_GAME};
39+
static cvar_t joy_invert = {"joy_invert", "0", CVAR_ARCHIVE_GAME};
40+
static cvar_t joy_exponent = {"joy_exponent", "2", CVAR_ARCHIVE_GAME};
41+
static cvar_t joy_exponent_move = {"joy_exponent_move", "2", CVAR_ARCHIVE_GAME};
42+
static cvar_t joy_swapmovelook = {"joy_swapmovelook", "0", CVAR_ARCHIVE_GAME};
43+
static cvar_t joy_enable = {"joy_enable", "1", CVAR_ARCHIVE_GAME};
4444

4545
#ifdef USE_SDL3
4646
#define SDL3_GET_WINDOW (SDL_Window *)VID_GetWindow ()

0 commit comments

Comments
 (0)