aboutsummaryrefslogtreecommitdiff
path: root/src/con_.h
diff options
context:
space:
mode:
authorGravatar Michael Smith <mikesmiffy128@gmail.com> 2025-03-10 02:37:19 +0000
committerGravatar Michael Smith <mikesmiffy128@gmail.com> 2025-04-06 16:41:13 +0100
commit244fea664121acf12871ab5858a5fe95a2606b52 (patch)
treee42b1990ef97adc0f0ab48b9be7e11de7fee0558 /src/con_.h
parentd86b7b41453c69b3854baa7cdc05a79a3cdfe092 (diff)
downloadsst-244fea664121acf12871ab5858a5fe95a2606b52.tar.gz
sst-244fea664121acf12871ab5858a5fe95a2606b52.zip
Rewrite and redesign codegen and feature system
Also switch to somewhat proper C23 flags while we're at it. This is a huge change. It took me forever, in between being really busy. Sorry about that. But the good news is I'm now free to start integrating the various patches that have accumulated since last release. Well, at least in between still being really busy. Gotta manage expectations. The main benefit of introducing GAMESPECIFIC() is that features that don't apply to a particular game no longer show up *at all*, and less time is wasted on init. It also enables a cool optimisation wherein unnecessary REQUIRE_GAMEDATA() checks can elided at compile time whenever the gamedata is known up-front to always exist in supported games. The DEF_FEAT_CVAR macro family meanwhile makes it easier to manage the lifecycle of cvars/ccmds, with less manual registering, unhiding and such. Originally I was going to try and just hack these features into the existing codegen abomination, but it just got too terrible. This rewrite should make it easier to continue tweaking codegen behaviour in future. It also has slightly better error messages.
Diffstat (limited to 'src/con_.h')
-rw-r--r--src/con_.h46
1 files changed, 39 insertions, 7 deletions
diff --git a/src/con_.h b/src/con_.h
index 0e6efef..dc06335 100644
--- a/src/con_.h
+++ b/src/con_.h
@@ -1,6 +1,6 @@
/* THIS FILE SHOULD BE CALLED `con.h` BUT WINDOWS IS STUPID */
/*
- * Copyright © 2024 Michael Smith <mikesmiffy128@gmail.com>
+ * Copyright © 2025 Michael Smith <mikesmiffy128@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -74,7 +74,7 @@ typedef void (*con_cmdcbv1)(void);
/*
* This is an autocompletion callback for suggesting arguments to a command.
- * XXX: Autocompletion isn't really totally figured out or implemented yet.
+ * TODO(autocomplete): Autocompletion isn't really implemented yet.
*/
typedef int (*con_complcb)(const char *part,
char cmds[CON_CMD_MAXCOMPLETE][CON_CMD_MAXCOMPLLEN]);
@@ -286,7 +286,8 @@ extern struct _con_vtab_iconvar_wrap {
/*
* Defines a console command with the handler function body immediately
- * following the macro (like in Source itself).
+ * following the macro (like in Source itself). The function takes the argument
+ * `struct con_cmdargs *cmd` for command arguments.
*/
#define DEF_CCMD_HERE(name, desc, flags) \
static void _cmdf_##name(const struct con_cmdargs *cmd); \
@@ -295,8 +296,35 @@ extern struct _con_vtab_iconvar_wrap {
/* { body here } */
/*
+ * These are exactly the same as the above macros, but instead of
+ * unconditionally registering things, they have the following conditions:
+ *
+ * - Variables are always registered, but get hidden if a feature fails to
+ * initialise.
+ * - If a feature specifies GAMESPECIFIC(), its cvars will remain unregistered
+ * unless the game matches.
+ * - Commands are only registered if the feature successfully initialises.
+ *
+ * In situations where exact control over initialisation is not required, these
+ * macros ought to make life a lot easier and are generally recommended.
+ *
+ * Obviously, these should only be used inside of a feature (see feature.h). The
+ * code generator will produce an error otherwise.
+ */
+#define DEF_FEAT_CVAR DEF_CVAR
+#define DEF_FEAT_CVAR_MIN DEF_CVAR_MIN
+#define DEF_FEAT_CVAR_MAX DEF_CVAR_MAX
+#define DEF_FEAT_CVAR_MINMAX DEF_CVAR_MINMAX
+#define DEF_FEAT_CCMD DEF_CCMD
+#define DEF_FEAT_CCMD_HERE DEF_CCMD_HERE
+#define DEF_FEAT_CCMD_PLUSMINUS DEF_CCMD_PLUSMINUS
+
+/*
* These are exactly the same as the above macros, but they don't cause the
- * commands or variables to be registered on plugin load.
+ * commands or variables to be registered on plugin load or feature
+ * initialisation. Registration must be done manually. These are generally not
+ * recommended but may be needed in specific cases such as conditionally
+ * reimplementing a built-in engine feature.
*/
#define DEF_CVAR_UNREG DEF_CVAR
#define DEF_CVAR_MIN_UNREG DEF_CVAR_MIN
@@ -307,10 +335,14 @@ extern struct _con_vtab_iconvar_wrap {
#define DEF_CCMD_PLUSMINUS_UNREG DEF_CCMD_PLUSMINUS
/*
- * Registers a command or variable defined with the _UNREG variants of the above
- * macros. Can be used to conditionally register things.
+ * These functions register a command or variable, respectively, defined with
+ * the _UNREG variants of the above macros. These can be used to conditionally
+ * register things. Wherever possible, it is advised to use the DEF_FEAT_*
+ * macros instead for conditional registration, as they handle the common cases
+ * automatically.
*/
-void con_reg(void *cmd_or_var);
+void con_regvar(struct con_var *v);
+void con_regcmd(struct con_cmd *c);
#endif