From 16dc54db4ef9da8fadd1681868796090cfbc773a Mon Sep 17 00:00:00 2001 From: BenCat07 Date: Fri, 22 May 2020 14:10:33 +0200 Subject: [PATCH] Remove nightmode jank --- src/hooks/visual/FrameStageNotify.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/hooks/visual/FrameStageNotify.cpp b/src/hooks/visual/FrameStageNotify.cpp index 4cf95072..d37ac2f5 100644 --- a/src/hooks/visual/FrameStageNotify.cpp +++ b/src/hooks/visual/FrameStageNotify.cpp @@ -17,11 +17,8 @@ static settings::Rgba nightmode_gui_color{ "visual.night-mode.gui-color", "00000 static settings::Rgba nightmode_world_color{ "visual.night-mode.world-color", "000000FF" }; static settings::Boolean no_shake{ "visual.no-shake", "true" }; -// Previous values -static float old_nightmode_world{ 0.0f }; -static float old_nightmode_gui{ 0.0f }; -static rgba_t old_nightmode_world_color(0.0f, 0.0f, 0.0f, 1.0f); -static rgba_t old_nightmode_gui_color(0.0f, 0.0f, 0.0f, 1.0f); +// Should we update nightmode? +static bool update_nightmode = false; // Which strings trigger this nightmode option std::vector world_strings = { "SkyBox", "World" }; @@ -37,7 +34,7 @@ DEFINE_HOOKED_METHOD(FrameStageNotify, void, void *this_, ClientFrameStage_t sta PROF_SECTION(FrameStageNotify_TOTAL); - if (old_nightmode_gui != *nightmode_gui || old_nightmode_world != *nightmode_world || old_nightmode_world_color != *nightmode_world_color || old_nightmode_gui_color != *nightmode_gui_color) + if (update_nightmode) { static ConVar *r_DrawSpecificStaticProp = g_ICvar->FindVar("r_DrawSpecificStaticProp"); if (!r_DrawSpecificStaticProp) @@ -91,10 +88,7 @@ DEFINE_HOOKED_METHOD(FrameStageNotify, void, void *this_, ClientFrameStage_t sta } } } - old_nightmode_gui = *nightmode_gui; - old_nightmode_gui_color = *nightmode_gui_color; - old_nightmode_world = *nightmode_world; - old_nightmode_world_color = *nightmode_world_color; + update_nightmode = false; } if (!g_IEngine->IsInGame()) @@ -141,4 +135,14 @@ DEFINE_HOOKED_METHOD(FrameStageNotify, void, void *this_, ClientFrameStage_t sta } return original::FrameStageNotify(this_, stage); } +template void rvarCallback(settings::VariableBase &, T) +{ + update_nightmode = true; +} +static InitRoutine init_fsn([]() { + nightmode_gui.installChangeCallback(rvarCallback); + nightmode_world.installChangeCallback(rvarCallback); + nightmode_gui_color.installChangeCallback(rvarCallback); + nightmode_world_color.installChangeCallback(rvarCallback); +}); } // namespace hooked_methods