summaryrefslogtreecommitdiff
path: root/src/con_.c
diff options
context:
space:
mode:
authorGravatar Michael Smith <mikesmiffy128@gmail.com> 2026-04-03 21:45:17 +0100
committerGravatar Michael Smith <mikesmiffy128@gmail.com> 2026-04-04 01:37:54 +0100
commit2ee93c3f46f8e948d2331eab46c95322a88874ee (patch)
treeb3a39f8e79ef725579b569748ac4be28b82b1266 /src/con_.c
parente174011b5e7390dc8714910185aaa40d0a44702f (diff)
downloadsst-2ee93c3f46f8e948d2331eab46c95322a88874ee.tar.gz
sst-2ee93c3f46f8e948d2331eab46c95322a88874ee.zip
Size-optimise cvar value cleanup
Put all the cvars together contiguously; then we don't need to generate lots of individual calls to extfree() and can instead simply iterate a fixed-sized array.
Diffstat (limited to 'src/con_.c')
-rw-r--r--src/con_.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/con_.c b/src/con_.c
index 54574bc..1d7d06e 100644
--- a/src/con_.c
+++ b/src/con_.c
@@ -22,6 +22,7 @@
#include <string.h>
#include "abi.h"
+#include "asm.h"
#include "chunklets/x86.h"
#include "con_.h"
#include "engineapi.h" // for factories and rgba - XXX: is this a bit circular?
@@ -503,6 +504,16 @@ static inline void badver() {
con_warn("sst: error: this engine version is not yet supported\n");
}
+extern struct con_var _con_vars_start, _con_vars_end; // con_.S
+
+static inline void shuntvars() {
+#ifdef _WIN32
+ for (struct con_var *v = &_con_vars_start; v != &_con_vars_end; ++v) {
+ __builtin_memmove(&v->v1, &v->v2, sizeof(struct con_var_common));
+ }
+#endif
+}
+
bool con_detect(int pluginver) {
if (_con_iface = factory_engine("VEngineCvar007", 0)) {
// GENIUS HACK (BUT STILL BAD): Portal 2 has everything in ICvar shifted
@@ -574,6 +585,7 @@ bool con_detect(int pluginver) {
}
if (_con_iface = factory_engine("VEngineCvar003", 0)) {
#ifdef _WIN32 // there's no OE on linux!
+ shuntvars(); // just doing this as early as possible atm, it's fine
_gametype_tag |= _gametype_tag_OE;
// for deletion/unlinking on unload, we need an indirect linked list
// pointer. calling GetCommands gives us a direct pointer. so we have to
@@ -733,6 +745,12 @@ void con_init() {
*pi++ = (void *)&GetSplitScreenPlayerSlot;
}
+static inline void freevars() {
+ for (struct con_var *v = &_con_vars_start; v != &_con_vars_end; ++v) {
+ extfree(con_getvarcommon(v)->strval);
+ }
+}
+
void con_disconnect() {
#ifdef _WIN32
if (linkedlist) {
@@ -749,10 +767,11 @@ void con_disconnect() {
pp = next;
}
}
- return;
+ goto f;
}
#endif
UnregisterConCommands(_con_iface, dllid);
+f: freevars();
}
struct con_var *con_findvar(const char *name) {