mirror of
https://github.com/blendogames/thirtyflightsofloving.git
synced 2025-02-21 11:10:58 +00:00
Added support for cvar descriptions.
This commit is contained in:
parent
562b6c816c
commit
f38b767fc1
5 changed files with 152 additions and 0 deletions
|
@ -67,30 +67,40 @@ typedef enum {false, true} qboolean;
|
|||
#ifdef _WIN32
|
||||
# ifndef __GNUC__ // MSVC/Borland
|
||||
typedef __int64 qint64;
|
||||
typedef unsigned __int64 uint64;
|
||||
# else // Cygwin
|
||||
# include <_G_config.h>
|
||||
typedef _G_int64_t qint64;
|
||||
typedef unsigned _G_int64_t uint64;
|
||||
# endif
|
||||
#elif defined(__MACOS__)
|
||||
# include <sys/types.h>
|
||||
typedef SInt64 qint64;
|
||||
typedef UInt64 uint64;
|
||||
#elif defined(__APPLE__) || defined(MACOSX) // MacOS X Framework build
|
||||
# include <sys/types.h>
|
||||
typedef int64_t qint64;
|
||||
typedef unsigned int64_t uint64;
|
||||
#elif defined(__linux__) // Linux
|
||||
# include <_G_config.h>
|
||||
typedef _G_int64_t qint64;
|
||||
typedef unsigned _G_int64_t uint64;
|
||||
#elif defined(__BEOS__) // Be
|
||||
# include <inttypes.h>
|
||||
typedef int64_t qint64;
|
||||
typedef unsigned int64_t uint64;
|
||||
#elif defined (__EMX__) // OS/2 GCC
|
||||
typedef long long qint64;
|
||||
typedef unsigned long long uint64;
|
||||
#elif defined (DJGPP) // DJGPP
|
||||
typedef long long qint64;
|
||||
typedef unsigned long long uint64;
|
||||
#elif defined(R5900) // PS2 EE
|
||||
typedef long qint64;
|
||||
typedef unsigned long uint64;
|
||||
#elif defined(linux)
|
||||
typedef int64_t qint64;
|
||||
typedef unsigned int64_t uint64;
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
|
@ -571,6 +581,7 @@ typedef struct cvar_s
|
|||
#ifdef KMQUAKE2_ENGINE_MOD
|
||||
char *default_string;
|
||||
int integer;
|
||||
char *description;
|
||||
#endif
|
||||
} cvar_t;
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ cvar_t *timescale;
|
|||
cvar_t *fixedtime;
|
||||
cvar_t *logfile_active; // 1 = buffer log, 2 = flush after each print
|
||||
cvar_t *showtrace;
|
||||
cvar_t *con_show_description; // Knightmare added
|
||||
cvar_t *dedicated;
|
||||
|
||||
// Knightmare- for the game DLL to tell what engine it's running under
|
||||
|
@ -1676,6 +1677,9 @@ void Qcommon_Init (int argc, char **argv)
|
|||
fixedtime = Cvar_Get ("fixedtime", "0", CVAR_CHEAT);
|
||||
logfile_active = Cvar_Get ("logfile", "0", 0);
|
||||
showtrace = Cvar_Get ("showtrace", "0", 0);
|
||||
con_show_description = Cvar_Get ("con_show_description", "1", CVAR_ARCHIVE); // Knightmare added
|
||||
Cvar_SetDescription ("con_show_description", "Toggles output of descriptions for cvars. This cvar will always show its description.");
|
||||
|
||||
#ifdef DEDICATED_ONLY
|
||||
dedicated = Cvar_Get ("dedicated", "1", CVAR_NOSET);
|
||||
#else
|
||||
|
|
123
qcommon/cvar.c
123
qcommon/cvar.c
|
@ -238,6 +238,7 @@ cvar_t *Cvar_Get (char *var_name, char *var_value, int flags)
|
|||
var->modified = true;
|
||||
var->value = atof (var->string);
|
||||
var->integer = atoi(var->string);
|
||||
var->description = NULL; // Knightmare- added descriptions from From Maraa'kate's cvar code
|
||||
|
||||
// link the variable in
|
||||
var->next = cvar_vars;
|
||||
|
@ -378,6 +379,50 @@ cvar_t *Cvar_SetToDefault (char *var_name)
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
============
|
||||
Cvar_SetDescription
|
||||
Knightmare added
|
||||
From Maraa'kate's cvar code
|
||||
============
|
||||
*/
|
||||
void Cvar_SetDescription (char *var_name, char *description)
|
||||
{
|
||||
cvar_t *var;
|
||||
|
||||
var = Cvar_FindVar (var_name);
|
||||
if (!var) {
|
||||
Com_DPrintf ("Cvar_SetDescription: cvar %s is invalid, can't set description!\n", var_name);
|
||||
return;
|
||||
}
|
||||
if (var->description) {
|
||||
free(var->description);
|
||||
}
|
||||
if ( description && (strlen(description) > 1) ) {
|
||||
var->description = strdup(description);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
============
|
||||
Cvar_SetModified
|
||||
Knightmare added
|
||||
Used to force the modified field of a cvar on.
|
||||
Used mainly for vid_ref, to force a vid_restart.
|
||||
============
|
||||
*/
|
||||
void Cvar_SetModified (char *var_name, qboolean value)
|
||||
{
|
||||
cvar_t *var;
|
||||
|
||||
var = Cvar_FindVar (var_name);
|
||||
if (!var)
|
||||
return;
|
||||
var->modified = value;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
============
|
||||
Cvar_FullSet
|
||||
|
@ -440,6 +485,70 @@ void Cvar_SetInteger (char *var_name, int integer)
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
=================
|
||||
Cvar_ClampValue
|
||||
|
||||
From Q2Pro
|
||||
=================
|
||||
*/
|
||||
float Cvar_ClampValue (cvar_t *var, float min, float max)
|
||||
{
|
||||
char val[32];
|
||||
|
||||
if (var->value < min)
|
||||
{
|
||||
if (min == (int)min) {
|
||||
Com_sprintf (val, sizeof(val), "%i", (int)min);
|
||||
}
|
||||
else {
|
||||
Com_sprintf (val, sizeof(val), "%f", min);
|
||||
}
|
||||
Cvar_Set (var->name, val);
|
||||
return min;
|
||||
}
|
||||
if (var->value > max)
|
||||
{
|
||||
if (max == (int)max) {
|
||||
Com_sprintf (val, sizeof(val), "%i", (int)max);
|
||||
}
|
||||
else {
|
||||
Com_sprintf (val, sizeof(val), "%f", max);
|
||||
}
|
||||
Cvar_Set (var->name, val);
|
||||
return max;
|
||||
}
|
||||
return var->value;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
=================
|
||||
Cvar_ClampInteger
|
||||
|
||||
From Q2Pro
|
||||
=================
|
||||
*/
|
||||
int Cvar_ClampInteger (cvar_t *var, int min, int max)
|
||||
{
|
||||
char val[32];
|
||||
|
||||
if (var->integer < min)
|
||||
{
|
||||
Com_sprintf (val, sizeof(val), "%i", min);
|
||||
Cvar_Set (var->name, val);
|
||||
return min;
|
||||
}
|
||||
if (var->integer > max)
|
||||
{
|
||||
Com_sprintf (val, sizeof(val), "%i", max);
|
||||
Cvar_Set (var->name, val);
|
||||
return max;
|
||||
}
|
||||
return var->integer;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
============
|
||||
Cvar_GetLatchedVars
|
||||
|
@ -525,6 +634,13 @@ qboolean Cvar_Command (void)
|
|||
else
|
||||
Com_Printf ("\"%s\" is \"%s\" : default is \"%s\"\n", v->name, v->string, v->default_string);
|
||||
|
||||
// Knightmare- added descriptions from From Maraa'kate's cvar code
|
||||
if ( (v->description != NULL) && (con_show_description->integer || !strcmp(v->name, "con_show_description")) )
|
||||
Com_Printf ("Description: %s\n", v->description);
|
||||
// else if ( (v->description != NULL) && !strcmp(v->name, "con_show_description") ) // Always show description for con_show_description
|
||||
// Com_Printf ("Description: %s\n", v->description);
|
||||
// end Knightmare
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -709,6 +825,12 @@ void Cvar_List_f (void)
|
|||
else
|
||||
Com_Printf(" ");
|
||||
|
||||
// Knightmare- added descriptions from From Maraa'kate's cvar code
|
||||
if (var->description != NULL)
|
||||
Com_Printf("D");
|
||||
else
|
||||
Com_Printf(" ");
|
||||
|
||||
// show latched value if applicable
|
||||
if ((var->flags & CVAR_LATCH) && var->latched_string)
|
||||
Com_Printf (" %s \"%s\" - default: \"%s\" - latched: \"%s\"\n", var->name, var->string, var->default_string, var->latched_string);
|
||||
|
@ -716,6 +838,7 @@ void Cvar_List_f (void)
|
|||
Com_Printf (" %s \"%s\" - default: \"%s\"\n", var->name, var->string, var->default_string);
|
||||
}
|
||||
}
|
||||
Com_Printf ("Legend: \'A\'=Archive \'U\'=Userinfo \'S\'=Serverinfo \'-\'=Write Protected \'L\'=Latched \'C\'=Cheat \'D\'=Has Description\n");
|
||||
Com_Printf (" %i cvars, %i matching\n", i, j);
|
||||
}
|
||||
|
||||
|
|
|
@ -526,6 +526,15 @@ void Cvar_SetValue (char *var_name, float value);
|
|||
void Cvar_SetInteger (char *var_name, int integer);
|
||||
// expands value to a string and calls Cvar_Set
|
||||
|
||||
void Cvar_SetModified (char *var_name, qboolean value);
|
||||
// sets modified attribute of cvar
|
||||
|
||||
float Cvar_ClampValue (cvar_t *var, float min, float max);
|
||||
// clamps cvar to range, expands value to a string and calls Cvar_Set
|
||||
|
||||
int Cvar_ClampInteger (cvar_t *var, int min, int max);
|
||||
// clamps cvar to range, expands value to a string and calls Cvar_Set
|
||||
|
||||
float Cvar_VariableValue (char *var_name);
|
||||
// returns 0 if not defined or non numeric
|
||||
|
||||
|
@ -889,6 +898,7 @@ extern cvar_t *developer;
|
|||
extern cvar_t *dedicated;
|
||||
extern cvar_t *host_speeds;
|
||||
extern cvar_t *log_stats;
|
||||
extern cvar_t *con_show_description; // Knightmare added
|
||||
|
||||
// Knightmare- for the game DLL to tell what engine it's running under
|
||||
extern cvar_t *sv_engine;
|
||||
|
|
|
@ -1074,7 +1074,9 @@ void R_Register (void)
|
|||
Cmd_AddCommand ("screenshot_silent", R_ScreenShot_Silent_f);
|
||||
Cmd_AddCommand ("screenshot_tga", R_ScreenShot_TGA_f);
|
||||
Cmd_AddCommand ("screenshot_jpg", R_ScreenShot_JPG_f);
|
||||
#ifdef PNG_SUPPORT
|
||||
Cmd_AddCommand ("screenshot_png", R_ScreenShot_PNG_f);
|
||||
#endif // PNG_SUPPORT
|
||||
Cmd_AddCommand ("modellist", Mod_Modellist_f);
|
||||
Cmd_AddCommand ("gl_strings", GL_Strings_f);
|
||||
// Cmd_AddCommand ("resetvertexlights", R_ResetVertextLights_f);
|
||||
|
@ -1944,7 +1946,9 @@ void R_Shutdown (void)
|
|||
Cmd_RemoveCommand ("screenshot_silent");
|
||||
Cmd_RemoveCommand ("screenshot_tga");
|
||||
Cmd_RemoveCommand ("screenshot_jpg");
|
||||
#ifdef PNG_SUPPORT
|
||||
Cmd_RemoveCommand ("screenshot_png");
|
||||
#endif // PNG_SUPPORT
|
||||
Cmd_RemoveCommand ("imagelist");
|
||||
Cmd_RemoveCommand ("gl_strings");
|
||||
// Cmd_RemoveCommand ("resetvertexlights");
|
||||
|
|
Loading…
Reference in a new issue