From 84dd5e6930235e0bae4c3546d072f27f99cc3bae Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Sun, 24 Dec 2023 01:01:52 +0100 Subject: [PATCH] Add macro-helpers Added to reduce dependencies to switcher-data --- CMakeLists.txt | 2 ++ src/macro-core/macro-helpers.cpp | 59 ++++++++++++++++++++++++++++++++ src/macro-core/macro-helpers.hpp | 21 ++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 src/macro-core/macro-helpers.cpp create mode 100644 src/macro-core/macro-helpers.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f244959..61a59fdb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -237,6 +237,8 @@ target_sources( src/macro-core/macro-condition.hpp src/macro-core/macro-dock.cpp src/macro-core/macro-dock.hpp + src/macro-core/macro-helpers.cpp + src/macro-core/macro-helpers.hpp src/macro-core/macro-properties.cpp src/macro-core/macro-properties.hpp src/macro-core/macro-ref.cpp diff --git a/src/macro-core/macro-helpers.cpp b/src/macro-core/macro-helpers.cpp new file mode 100644 index 00000000..4fa56e43 --- /dev/null +++ b/src/macro-core/macro-helpers.cpp @@ -0,0 +1,59 @@ +#include "macro-helpers.hpp" +#include "plugin-state-helpers.hpp" + +namespace advss { + +static std::atomic_bool abortMacroWait = {false}; +static std::atomic_bool macroSceneSwitched = {false}; +static std::atomic_int shutdownConditionCount = {0}; + +std::condition_variable &GetMacroWaitCV() +{ + static std::condition_variable cv; + return cv; +} + +std::condition_variable &GetMacroTransitionCV() +{ + static std::condition_variable cv; + return cv; +} + +std::atomic_bool &MacroWaitShouldAbort() +{ + return abortMacroWait; +} + +void SetMacroAbortWait(bool value) +{ + abortMacroWait = value; +} + +bool ShutdownCheckIsNecessary() +{ + return shutdownConditionCount > 0; +} + +std::atomic_int &GetShutdownConditionCount() +{ + return shutdownConditionCount; +} + +void SetMacroSwitchedScene(bool value) +{ + static bool setupDone = false; + if (!setupDone) { + // Will always be called with switcher lock already held + AddIntervalResetStep([]() { macroSceneSwitched = false; }, + false); + setupDone = true; + } + macroSceneSwitched = value; +} + +bool MacroSwitchedScene() +{ + return macroSceneSwitched; +} + +} // namespace advss diff --git a/src/macro-core/macro-helpers.hpp b/src/macro-core/macro-helpers.hpp new file mode 100644 index 00000000..8a607c46 --- /dev/null +++ b/src/macro-core/macro-helpers.hpp @@ -0,0 +1,21 @@ +#pragma once +#include +#include +#include + +namespace advss { + +constexpr std::string_view GetSceneSwitchActionId() +{ + return "scene_switch"; +} +std::condition_variable &GetMacroWaitCV(); +std::condition_variable &GetMacroTransitionCV(); +std::atomic_bool &MacroWaitShouldAbort(); +void SetMacroAbortWait(bool); +bool ShutdownCheckIsNecessary(); +std::atomic_int &GetShutdownConditionCount(); +void SetMacroSwitchedScene(bool value); +bool MacroSwitchedScene(); + +} // namespace advss