diff options
author | Michael Smith <mikesmiffy128@gmail.com> | 2022-07-31 16:02:10 +0100 |
---|---|---|
committer | Michael Smith <mikesmiffy128@gmail.com> | 2022-08-10 22:40:52 +0100 |
commit | 5e921bf59373d79d27c322ff86e8b5a37b151e45 (patch) | |
tree | 4d40e39543b085ce4c8cb9b1a7b3c0108de680c0 /src/nosleep.c | |
parent | c8d7588251fd4fe63ac6afe2a90ca7066c786609 (diff) |
Add magical feature codegen system, at long last
Diffstat (limited to 'src/nosleep.c')
-rw-r--r-- | src/nosleep.c | 27 |
1 files changed, 12 insertions, 15 deletions
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 <stdbool.h> - #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); } |