From 1c4318331663b152b0b298bd2c9e5c971506a86b Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Sat, 10 Jun 2023 16:44:19 +0100 Subject: Prune some comments and tidy up other minor things --- src/con_.c | 50 +++++++++++++++----------------------------------- 1 file changed, 15 insertions(+), 35 deletions(-) (limited to 'src/con_.c') diff --git a/src/con_.c b/src/con_.c index eafc242..6ae1738 100644 --- a/src/con_.c +++ b/src/con_.c @@ -38,24 +38,13 @@ * Don't get set on fire. * \******************************************************************************/ -// given to us by the engine to unregister cvars in bulk on plugin unload -static int dllid; - -// external spaghetti variable, exists only because valve are bad +static int dllid; // from AllocateDLLIdentifier(), lets us unregister in bulk int con_cmdclient; -// these have to be extern because of varargs nonsense - they get wrapped in a -// macro for the actual api (con_colourmsg) -void *_con_iface; -void (*_con_colourmsgf)(void *this, const struct rgba *c, const char *fmt, - ...) _CON_PRINTF(3, 4); - -// bootstrap hackery, see "GENIUS HACK" comment below :) DECL_VFUNC(void *, FindCommandBase_p2, 13, const char *) DECL_VFUNC(void *, FindCommand_nonp2, 14, const char *) DECL_VFUNC(void *, FindVar_nonp2, 12, const char *) -// rest of these are figured out from gamedata after initial game detection DECL_VFUNC_DYN(int, AllocateDLLIdentifier) DECL_VFUNC_DYN(void, RegisterConCommand, /*ConCommandBase*/ void *) DECL_VFUNC_DYN(void, UnregisterConCommands, int) @@ -71,35 +60,31 @@ DECL_VFUNC_DYN(void, CallGlobalChangeCallbacks, struct con_var *, const char *, typedef void (*ConsoleColorPrintf_func)(void *, const struct rgba *, const char *, ...); +// these have to be extern for con_colourmsg(), due to varargs nonsense +void *_con_iface; +ConsoleColorPrintf_func _con_colourmsgf; + static inline void initval(struct con_var *v) { - // v->strlen is set to defaultval len in _DEF_CVAR so we don't need to call - // strlen() on each string :) - v->strval = extmalloc(v->strlen); + v->strval = extmalloc(v->strlen); // note: strlen is preset in _DEF_CVAR() memcpy(v->strval, v->defaultval, v->strlen); } -// generated by build/codegen.c, defines regcmds() and freevars() -#include +#include // generated by build/codegen.c -// to try and be like the engine even though it's probably not actually -// required, we call the Internal* virtual functions by actual virtual lookup. -// since the vtables are filled dynamically (below), we store this index; other -// indices are just offset from this one since the 3-or-4 functions are all -// right next to each other. the #defines allow us to still use the nice vcall -// stuff. +// to try and match the engine even though it's probably not strictly required, +// we call the Internal* virtual functions via the actual vtable. since vtables +// are built dynamically (below), we store this index; other indices are just +// offset from it since these 3-or-4 functions are all right next to each other. static int vtidx_InternalSetValue; #define vtidx_InternalSetFloatValue (vtidx_InternalSetValue + 1) #define vtidx_InternalSetIntValue (vtidx_InternalSetValue + 2) #define vtidx_InternalSetColorValue (vtidx_InternalSetValue + 3) -// implementation of virtual functions for our vars and commands below... - static void VCALLCONV dtor(void *_) {} // we don't use constructors/destructors static bool VCALLCONV IsCommand_cmd(void *this) { return true; } static bool VCALLCONV IsCommand_var(void *this) { return false; } -// flag stuff static bool VCALLCONV IsFlagSet_cmd(struct con_cmd *this, int flags) { return !!(this->base.flags & flags); } @@ -125,7 +110,6 @@ static int VCALLCONV GetFlags_var(struct con_var *this) { return this->parent->base.flags; } -// basic registration stuff static const char *VCALLCONV GetName_cmd(struct con_cmd *this) { return this->base.name; } @@ -154,9 +138,8 @@ static bool VCALLCONV ClampValue(struct con_var *this, float *f) { return false; } -// command-specific stuff int VCALLCONV AutoCompleteSuggest(void *this, const char *partial, - /* CUtlVector */ void *commands) { + /*CUtlVector*/ void *commands) { // TODO(autocomplete): implement this if needed later return 0; } @@ -164,11 +147,10 @@ bool VCALLCONV CanAutoComplete(void *this) { return false; } void VCALLCONV Dispatch(struct con_cmd *this, const struct con_cmdargs *args) { - // only try cb, cbv1 and iface should never get used by us + // only try cb; cbv1 and iface should never get used by us if (this->use_newcb && this->cb) this->cb(args); } -// var-specific stuff static void VCALLCONV ChangeStringValue(struct con_var *this, const char *s, float oldf) { char *old = alloca(this->strlen); @@ -232,8 +214,7 @@ DECL_VFUNC_DYN(void, InternalSetFloatValue, float) DECL_VFUNC_DYN(void, InternalSetIntValue, int) DECL_VFUNC_DYN(void, InternalSetColorValue, struct rgba) -// Hack: IConVar things get this-adjusted pointers, we just reverse the offset -// to get the top pointer. +// IConVar calls get this-adjusted pointers, so just subtract the offset static void VCALLCONV SetValue_str_thunk(void *thisoff, const char *v) { struct con_var *this = mem_offset(thisoff, -offsetof(struct con_var, vtable_iconvar)); @@ -379,8 +360,7 @@ void con_init(void) { *pv++ = (void *)&InternalSetFloatValue_impl; *pv++ = (void *)&InternalSetIntValue_impl; if (GAMETYPE_MATCHES(L4D2x) || GAMETYPE_MATCHES(Portal2)) { // ugh, annoying - // This is InternalSetColorValue, but that's basically the same thing, - // when you think about it. + // InternalSetColorValue, literally the same machine instructions as int *pv++ = (void *)&InternalSetIntValue_impl; } *pv++ = (void *)&ClampValue;; -- cgit v1.2.3