From cbac5da0b7e2dc6f8d16361996f23a5559775cb2 Mon Sep 17 00:00:00 2001 From: jeefo Date: Tue, 8 Mar 2016 17:22:44 +0300 Subject: [PATCH] user Cvar_DirectSet for Convar::SetString --- include/engine.h | 7 ++++--- include/engine/eiface.h | 2 +- source/basecode.cpp | 2 +- source/engine.cpp | 15 ++++++++++----- source/support.cpp | 10 ++-------- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/engine.h b/include/engine.h index c7004c7..24b56f0 100644 --- a/include/engine.h +++ b/include/engine.h @@ -46,12 +46,13 @@ private: { VarType type; cvar_t reg; + bool regMissing; class ConVar *self; }; Array m_regs; public: - void RegisterVariable (const char *variable, const char *value, VarType varType, ConVar *self); + void RegisterVariable (const char *variable, const char *value, VarType varType, bool regMissing, ConVar *self); void PushRegisteredConVarsToEngine (bool gameVars = false); }; @@ -205,7 +206,7 @@ public: cvar_t *m_eptr; public: - ConVar (const char *name, const char *initval, VarType type = VT_NOSERVER); + ConVar (const char *name, const char *initval, VarType type = VT_NOSERVER, bool regMissing = false); inline bool GetBool (void) { return m_eptr->value > 0.0f; } inline int GetInt (void) { return static_cast (m_eptr->value); } @@ -213,5 +214,5 @@ public: inline const char *GetString (void) { return m_eptr->string; } inline void SetFloat (float val) { m_eptr->value = val; } inline void SetInt (int val) { SetFloat (static_cast (val)); } - inline void SetString (const char *val) { g_engfuncs.pfnCVarSetString (m_eptr->name, val); } + inline void SetString (const char *val) { g_engfuncs.pfnCvar_DirectSet (m_eptr, const_cast (val)); } }; diff --git a/include/engine/eiface.h b/include/engine/eiface.h index 48c924f..31ed7ca 100644 --- a/include/engine/eiface.h +++ b/include/engine/eiface.h @@ -246,7 +246,7 @@ typedef struct enginefuncs_s void (*pfnDeltaUnsetFieldByIndex) (struct delta_s *pFields, int fieldNumber); void (*pfnSetGroupMask) (int mask, int op); int (*pfnCreateInstancedBaseline) (int classname, struct entity_state_s *baseline); - void (*pfnCvar_DirectSet) (struct cvar_s *var, char *value); + void (*pfnCvar_DirectSet) (struct cvar_t *var, char *value); void (*pfnForceUnmodified) (FORCE_TYPE type, float *mins, float *maxs, const char *szFilename); void (*pfnGetPlayerStats) (const edict_t *client, int *ping, int *packet_loss); void (*pfnAddServerCommand) (char *cmd_name, void (*function) (void)); diff --git a/source/basecode.cpp b/source/basecode.cpp index 0390379..1a3cca1 100644 --- a/source/basecode.cpp +++ b/source/basecode.cpp @@ -2284,7 +2284,7 @@ bool Bot::LastEnemyShootable (void) void Bot::CheckRadioCommands (void) { - // this function handling radio and reactings to it + // this function handling radio and reacting to it float distance = (m_radioEntity->v.origin - pev->origin).GetLength (); diff --git a/source/engine.cpp b/source/engine.cpp index 31a47a0..13ff960 100644 --- a/source/engine.cpp +++ b/source/engine.cpp @@ -453,7 +453,7 @@ void Engine::IssueCmd (const char *fmt, ...) g_engfuncs.pfnServerCommand (string); } -void ConVarWrapper::RegisterVariable (const char *variable, const char *value, VarType varType, ConVar *self) +void ConVarWrapper::RegisterVariable(const char *variable, const char *value, VarType varType, bool regMissing, ConVar *self) { // this function adds globally defined variable to registration stack @@ -462,6 +462,7 @@ void ConVarWrapper::RegisterVariable (const char *variable, const char *value, V pair.reg.name = const_cast (variable); pair.reg.string = const_cast (value); + pair.regMissing = regMissing; int engineFlags = FCVAR_EXTDLL; @@ -501,13 +502,17 @@ void ConVarWrapper::PushRegisteredConVarsToEngine (bool gameVars) { ptr->self->m_eptr = g_engfuncs.pfnCVarGetPointer (ptr->reg.name); - // ensure game cvar exists - InternalAssert (ptr->self->m_eptr != NULL); + if (ptr->regMissing && ptr->self->m_eptr == NULL) + { + g_engfuncs.pfnCVarRegister (&ptr->reg); + ptr->self->m_eptr = g_engfuncs.pfnCVarGetPointer (ptr->reg.name); + } + InternalAssert (ptr->self->m_eptr != NULL); // ensure game var exists } } } -ConVar::ConVar (const char *name, const char *initval, VarType type) : m_eptr (NULL) +ConVar::ConVar (const char *name, const char *initval, VarType type, bool regMissing) : m_eptr (NULL) { - ConVarWrapper::GetReference ().RegisterVariable (name, initval, type, this); + ConVarWrapper::GetReference ().RegisterVariable (name, initval, type, regMissing, this); } diff --git a/source/support.cpp b/source/support.cpp index a3fe8b5..d3acd20 100644 --- a/source/support.cpp +++ b/source/support.cpp @@ -12,12 +12,7 @@ ConVar yb_display_menu_text ("yb_display_menu_text", "1"); ConVar mp_roundtime ("mp_roundtime", NULL, VT_NOREGISTER); - -#ifndef XASH_CSDM -ConVar mp_freezetime ("mp_freezetime", NULL, VT_NOREGISTER); -#else -ConVar mp_freezetime ("mp_freezetime", "0", VT_NOSERVER); -#endif +ConVar mp_freezetime ("mp_freezetime", NULL, VT_NOREGISTER, true); uint16 FixedUnsigned16 (float value, float scale) { @@ -424,7 +419,6 @@ int GetWeaponPenetrationPower (int id) return 0; } - bool IsValidPlayer (edict_t *ent) { if (engine.IsNullEntity (ent)) @@ -716,7 +710,7 @@ bool FindNearestPlayer (void **pvHolder, edict_t *to, float searchDistance, bool // team, live status, search distance etc. if needBot is true, then pvHolder, will // be filled with bot pointer, else with edict pointer(!). - edict_t *survive = NULL; // pointer to temporaly & survive entity + edict_t *survive = NULL; // pointer to temporally & survive entity float nearestPlayer = 4096.0f; // nearest player int toTeam = engine.GetTeam (to);