From b7479e8342706ea360ac50325081d0207f67f4e7 Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Mon, 10 Apr 2023 02:10:15 +0200 Subject: [PATCH] Enable plugin callbacks to be peformed after condition checks completed Also run these callbacks before restarting the plugin. This should ensure that no outdated signals received while the plugin was stopped will trigger unexpected actions. (E.g. websocket messages that were received while the plugin was stopped) --- src/advanced-scene-switcher.cpp | 32 ++++++++++++++++++++++---------- src/switcher-data-structs.cpp | 7 +++++++ src/switcher-data-structs.hpp | 3 +++ 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/advanced-scene-switcher.cpp b/src/advanced-scene-switcher.cpp index 529a5461..8813a53c 100644 --- a/src/advanced-scene-switcher.cpp +++ b/src/advanced-scene-switcher.cpp @@ -255,7 +255,7 @@ void SwitcherData::Thread() } } - ClearWebsocketMessages(); + resetForNextInterval(); if (match) { if (macroMatch) { @@ -308,6 +308,16 @@ void SwitcherData::setPreconditions() lastCursorPos = getCursorPos(); } +void SwitcherData::resetForNextInterval() +{ + // Core reset functions + ClearWebsocketMessages(); + // Plugin reset functions + for (const auto &func : resetForNextIntervalFuncs) { + func(); + } +} + bool SwitcherData::checkForMatch(OBSWeakSource &scene, OBSWeakSource &transition, int &linger, bool &setPrevSceneAfterLinger, @@ -414,9 +424,20 @@ void switchPreviewScene(const OBSWeakSource &ws) obs_source_release(source); } +static void ResetMacros() +{ + for (auto &m : switcher->macros) { + m->ResetRunCount(); + m->ResetTimers(); + } +} + void SwitcherData::Start() { if (!(th && th->isRunning())) { + resetForNextInterval(); + ResetMacros(); + stop = false; th = new SwitcherThread(); th->start((QThread::Priority)threadPriority); @@ -441,14 +462,6 @@ void SwitcherData::Start() } } -void ResetMacros() -{ - for (auto &m : switcher->macros) { - m->ResetRunCount(); - m->ResetTimers(); - } -} - void SwitcherData::Stop() { if (th && th->isRunning()) { @@ -462,7 +475,6 @@ void SwitcherData::Stop() th = nullptr; writeToStatusFile("Advanced Scene Switcher stopped"); - ResetMacros(); } server.stop(); diff --git a/src/switcher-data-structs.cpp b/src/switcher-data-structs.cpp index 7044e40c..537eed8b 100644 --- a/src/switcher-data-structs.cpp +++ b/src/switcher-data-structs.cpp @@ -133,3 +133,10 @@ void SwitcherData::saveVersion(obs_data_t *obj, { obs_data_set_string(obj, "version", currentVersion.c_str()); } + +void SwitcherData::addResetForNextIntervalFunction( + std::function function) +{ + std::lock_guard lock(switcher->m); + resetForNextIntervalFuncs.emplace_back(function); +} diff --git a/src/switcher-data-structs.hpp b/src/switcher-data-structs.hpp index 9b845c7f..465a3344 100644 --- a/src/switcher-data-structs.hpp +++ b/src/switcher-data-structs.hpp @@ -271,6 +271,9 @@ struct SwitcherData { void writeToStatusFile(const QString &msg); void setPreconditions(); + void resetForNextInterval(); + void addResetForNextIntervalFunction(std::function); + std::vector> resetForNextIntervalFuncs; bool checkForMatch(OBSWeakSource &scene, OBSWeakSource &transition, int &linger, bool &setPreviousSceneAsMatch, bool ¯oMatch);