summaryrefslogtreecommitdiff
path: root/src/l4dwarp.c
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/l4dwarp.c
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/l4dwarp.c')
-rw-r--r--src/l4dwarp.c31
1 files changed, 12 insertions, 19 deletions
diff --git a/src/l4dwarp.c b/src/l4dwarp.c
index b9e019d..eb638e4 100644
--- a/src/l4dwarp.c
+++ b/src/l4dwarp.c
@@ -1,5 +1,5 @@
/*
- * Copyright © 2024 Michael Smith <mikesmiffy128@gmail.com>
+ * Copyright © 2025 Michael Smith <mikesmiffy128@gmail.com>
* Copyright © 2023 Willian Henrique <wsimanbrazil@yahoo.com.br>
*
* Permission to use, copy, modify, and/or distribute this software for any
@@ -36,12 +36,15 @@
#include "x86util.h"
FEATURE("Left 4 Dead warp testing")
+GAMESPECIFIC(L4D)
REQUIRE(clientcon)
REQUIRE(ent)
REQUIRE(trace)
REQUIRE_GAMEDATA(off_entpos)
REQUIRE_GAMEDATA(off_eyeang)
REQUIRE_GAMEDATA(off_teamnum)
+REQUIRE_GAMEDATA(vtidx_AddBoxOverlay2)
+REQUIRE_GAMEDATA(vtidx_AddLineOverlay)
REQUIRE_GAMEDATA(vtidx_Teleport)
DECL_VFUNC_DYN(void, Teleport, const struct vec3f */*pos*/,
@@ -99,7 +102,7 @@ static struct vec3f warptarget(void *ent) {
};
}
-DEF_CCMD_HERE_UNREG(sst_l4d_testwarp, "Simulate a bot warping to you "
+DEF_FEAT_CCMD_HERE(sst_l4d_testwarp, "Simulate a bot warping to you "
"(specify \"staystuck\" to skip take-control simulation)",
CON_SERVERSIDE | CON_CHEAT) {
bool staystuck = false;
@@ -167,9 +170,9 @@ static bool draw_testpos(struct vec3f start, struct vec3f testpos,
return false;
}
+// note: UNREG because testwarp can still work without this
DEF_CCMD_HERE_UNREG(sst_l4d_previewwarp, "Visualise bot warp unstuck logic "
- "(use clear_debug_overlays to remove)",
- CON_SERVERSIDE | CON_CHEAT) {
+ "(use clear_debug_overlays to remove)", CON_SERVERSIDE | CON_CHEAT) {
struct edict *ed = ent_getedict(con_cmdclient + 1);
if_cold (!ed || !ed->ent_unknown) {
errmsg_errorx("couldn't access player entity");
@@ -306,26 +309,16 @@ static bool init_filter(void) {
return false;
}
-PREINIT {
- return GAMETYPE_MATCHES(L4D);
-}
-
INIT {
struct con_cmd *z_add = con_findcmd("z_add");
if (!z_add || !find_EntityPlacementTest(z_add->cb)) {
errmsg_errorx("couldn't find EntityPlacementTest function");
- return false;
+ return FEAT_INCOMPAT;
}
if (!init_filter()) {
- errmsg_errorx("couldn't init trace filter for EntityPlacementTest");
- return false;
+ errmsg_errorx("couldn't find trace filter ctor for EntityPlacementTest");
+ return FEAT_INCOMPAT;
}
- con_reg(sst_l4d_testwarp);
- // NOTE: assuming has_vtidx_AddLineOverlay && has_vtidx_AddBoxOverlay2
- // since those are specified for L4D.
- // TODO(opt): add some zero-cost/compile-time way to make sure gamedata
- // exists in a game-specific scenario? (probably requires declarative
- // game-specific features in codegen, which hasn't been high-priority)
if_cold (!has_off_collision) {
errmsg_warnx("missing m_Collision gamedata - warp preview unavailable");
}
@@ -334,9 +327,9 @@ INIT {
"warp preview unavailable");
}
else {
- con_reg(sst_l4d_previewwarp);
+ con_regcmd(sst_l4d_previewwarp);
}
- return true;
+ return FEAT_OK;
}
// vi: sw=4 ts=4 noet tw=80 cc=80