From 0f36f34a4f5118e86733a32386c1bf92ad44383e Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Sat, 13 May 2023 17:47:20 +0200 Subject: [PATCH] Cleanup * Const correctness * Group functionality * Move Actions() and Conditions() implementation --- src/macro-core/macro.cpp | 22 ++++++++---- src/macro-core/macro.hpp | 74 +++++++++++++++++++--------------------- 2 files changed, 52 insertions(+), 44 deletions(-) diff --git a/src/macro-core/macro.cpp b/src/macro-core/macro.cpp index f5b5b6dc..ca251f80 100644 --- a/src/macro-core/macro.cpp +++ b/src/macro-core/macro.cpp @@ -216,7 +216,7 @@ bool Macro::PerformActions(bool forceParallel, bool ignorePause) return ret; } -int64_t Macro::MsSinceLastCheck() +int64_t Macro::MsSinceLastCheck() const { if (_lastCheckTime.time_since_epoch().count() == 0) { return 0; @@ -307,6 +307,16 @@ void Macro::Stop() } } +std::deque> &Macro::Conditions() +{ + return _conditions; +} + +std::deque> &Macro::Actions() +{ + return _actions; +} + void Macro::UpdateActionIndices() { int idx = 0; @@ -325,7 +335,7 @@ void Macro::UpdateConditionIndices() } } -std::shared_ptr Macro::Parent() +std::shared_ptr Macro::Parent() const { return _parent.lock(); } @@ -521,7 +531,7 @@ bool Macro::PostLoad() return true; } -bool Macro::SwitchesScene() +bool Macro::SwitchesScene() const { MacroActionSwitchScene temp(nullptr); auto sceneSwitchId = temp.GetId(); @@ -576,7 +586,7 @@ void Macro::EnablePauseHotkeys(bool value) _registerHotkeys = value; } -bool Macro::PauseHotkeysEnabled() +bool Macro::PauseHotkeysEnabled() const { return _registerHotkeys; } @@ -786,7 +796,7 @@ void Macro::SetupHotkeys() togglePauseCB); } -void Macro::ClearHotkeys() +void Macro::ClearHotkeys() const { obs_hotkey_unregister(_pauseHotkey); obs_hotkey_unregister(_unpauseHotkey); @@ -801,7 +811,7 @@ void setHotkeyDescriptionHelper(const char *formatModuleText, obs_hotkey_set_description(id, hotkeyDesc.toStdString().c_str()); } -void Macro::SetHotkeysDesc() +void Macro::SetHotkeysDesc() const { setHotkeyDescriptionHelper("AdvSceneSwitcher.hotkey.macro.pause", _name, _pauseHotkey); diff --git a/src/macro-core/macro.hpp b/src/macro-core/macro.hpp index 4300cad4..a524732e 100644 --- a/src/macro-core/macro.hpp +++ b/src/macro-core/macro.hpp @@ -26,26 +26,25 @@ public: bool CeckMatch(); bool PerformActions(bool forceParallel = false, bool ignorePause = false); - bool Matched() { return _matched; } - int64_t MsSinceLastCheck(); - std::string Name() { return _name; } + bool Matched() const { return _matched; } + int64_t MsSinceLastCheck() const; + std::string Name() const { return _name; } void SetName(const std::string &name); void SetRunInParallel(bool parallel) { _runInParallel = parallel; } - bool RunInParallel() { return _runInParallel; } + bool RunInParallel() const { return _runInParallel; } void SetPaused(bool pause = true); - bool Paused() { return _paused; } + bool Paused() const { return _paused; } void SetMatchOnChange(bool onChange) { _matchOnChange = onChange; } - bool MatchOnChange() { return _matchOnChange; } - int RunCount() { return _runCount; }; + bool MatchOnChange() const { return _matchOnChange; } + int RunCount() const { return _runCount; }; void ResetRunCount() { _runCount = 0; }; + void ResetTimers(); void AddHelperThread(std::thread &&); - bool GetStop() { return _stop; } + bool GetStop() const { return _stop; } void Stop(); - std::deque> &Conditions() - { - return _conditions; - } - std::deque> &Actions() { return _actions; } + + std::deque> &Conditions(); + std::deque> &Actions(); void UpdateActionIndices(); void UpdateConditionIndices(); @@ -58,14 +57,15 @@ public: std::shared_ptr item); static void PrepareMoveToGroup(std::shared_ptr group, std::shared_ptr item); - bool IsGroup() { return _isGroup; } - uint32_t GroupSize() { return _groupSize; } - bool IsSubitem() { return !_parent.expired(); } + bool IsGroup() const { return _isGroup; } + uint32_t GroupSize() const { return _groupSize; } + bool IsSubitem() const { return !_parent.expired(); } void SetCollapsed(bool val) { _isCollapsed = val; } - bool IsCollapsed() { return _isCollapsed; } + bool IsCollapsed() const { return _isCollapsed; } void SetParent(std::shared_ptr m) { _parent = m; } - std::shared_ptr Parent(); + std::shared_ptr Parent() const; + // Saving and loading bool Save(obs_data_t *obj) const; bool Load(obs_data_t *obj); // Some macros can refer to other macros, which are not yet loaded. @@ -73,29 +73,27 @@ public: bool PostLoad(); // Helper function for plugin state condition regarding scene change - bool SwitchesScene(); + bool SwitchesScene() const; - // UI helpers for the macro tab + // UI helpers bool WasExecutedRecently(); bool OnChangePreventedActionsRecently(); void ResetUIHelpers(); void EnablePauseHotkeys(bool); - bool PauseHotkeysEnabled(); + bool PauseHotkeysEnabled() const; void EnableDock(bool); - bool DockEnabled() { return _registerDock; } + bool DockEnabled() const { return _registerDock; } void SetDockHasRunButton(bool value); - bool DockHasRunButton() { return _dockHasRunButton; } + bool DockHasRunButton() const { return _dockHasRunButton; } void SetDockHasPauseButton(bool value); - bool DockHasPauseButton() { return _dockHasPauseButton; } - - void ResetTimers(); + bool DockHasPauseButton() const { return _dockHasPauseButton; } private: void SetupHotkeys(); - void ClearHotkeys(); - void SetHotkeysDesc(); + void ClearHotkeys() const; + void SetHotkeysDesc() const; void RunActions(bool &ret, bool ignorePause); void RunActions(bool ignorePause); void SetOnChangeHighlight(); @@ -106,11 +104,20 @@ private: void RemoveDock(); std::string _name = ""; + bool _die = false; + bool _stop = false; + bool _done = true; + std::chrono::high_resolution_clock::time_point _lastCheckTime{}; + std::thread _backgroundThread; + std::vector _helperThreads; + std::deque> _conditions; std::deque> _actions; std::weak_ptr _parent; uint32_t _groupSize = 0; + bool _isGroup = false; + bool _isCollapsed = false; bool _runInParallel = false; bool _matched = false; @@ -124,10 +131,9 @@ private: obs_hotkey_id _togglePauseHotkey = OBS_INVALID_HOTKEY_ID; // UI helpers for the macro tab - bool _isGroup = false; - bool _isCollapsed = false; bool _wasExecutedRecently = false; bool _onChangeTriggered = false; + bool _registerDock = false; bool _dockHasRunButton = true; bool _dockHasPauseButton = true; @@ -137,14 +143,6 @@ private: QByteArray _dockGeo; MacroDock *_dock = nullptr; QAction *_dockAction = nullptr; - - std::chrono::high_resolution_clock::time_point _lastCheckTime{}; - - bool _die = false; - bool _stop = false; - bool _done = true; - std::thread _backgroundThread; - std::vector _helperThreads; }; Macro *GetMacroByName(const char *name);