From 5e921bf59373d79d27c322ff86e8b5a37b151e45 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Sun, 31 Jul 2022 16:02:10 +0100 Subject: Add magical feature codegen system, at long last --- src/nosleep.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'src/nosleep.c') diff --git a/src/nosleep.c b/src/nosleep.c index 5618ba9..07a5500 100644 --- a/src/nosleep.c +++ b/src/nosleep.c @@ -14,16 +14,19 @@ * PERFORMANCE OF THIS SOFTWARE. */ -#include - #include "con_.h" #include "engineapi.h" #include "errmsg.h" +#include "feature.h" #include "gamedata.h" #include "hook.h" #include "os.h" #include "vcall.h" +FEATURE("inactive window sleep adjustment") +REQUIRE_GAMEDATA(vtidx_SleepUntilInput) +REQUIRE_GLOBAL(factory_inputsystem) + DEF_CVAR_UNREG(engine_no_focus_sleep, "Delay while tabbed out (SST reimplementation)", 50, CON_ARCHIVE | CON_HIDDEN) @@ -36,19 +39,13 @@ static void VCALLCONV hook_SleepUntilInput(void *this, int timeout) { orig_SleepUntilInput(this, con_getvari(engine_no_focus_sleep)); } -bool nosleep_init(void) { - struct con_var *v = con_findvar("engine_no_focus_sleep"); - if (v) return false; // no need! +PREINIT { + if (con_findvar("engine_no_focus_sleep")) return false; con_reg(engine_no_focus_sleep); - // TODO(featgen): auto-check these factories - if (!factory_inputsystem) { - errmsg_errorx("missing required factories"); - return false; - } - if (!has_vtidx_SleepUntilInput) { - errmsg_errorx("missing gamedata entries for this engine"); - return false; - } + return true; +} + +INIT { void *insys = factory_inputsystem("InputSystemVersion001", 0); if (!insys) { errmsg_errorx("couldn't get input system interface"); @@ -66,7 +63,7 @@ bool nosleep_init(void) { return true; } -void nosleep_end(void) { +END { unhook_vtable(vtable, vtidx_SleepUntilInput, (void *)orig_SleepUntilInput); } -- cgit v1.2.3