From 93ff957e38bdc1f457551010ae64ae0e53f29578 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Fri, 10 Mar 2023 09:18:32 -0800 Subject: [PATCH] Added interval --- lib/SDL | 2 +- lib/openal-soft | 2 +- src/dawn/state/StateProvider.hpp | 7 ++++--- src/dawn/time/ITimeManager.cpp | 6 +++--- src/dawn/time/ITimeManager.hpp | 9 +++++++-- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/SDL b/lib/SDL index c9aec268..87a83787 160000 --- a/lib/SDL +++ b/lib/SDL @@ -1 +1 @@ -Subproject commit c9aec268fa7f892e183219683160599a4a2b86db +Subproject commit 87a83787a3a0a9922b02b35ba809d9da86930fc8 diff --git a/lib/openal-soft b/lib/openal-soft index fde74453..d66107e9 160000 --- a/lib/openal-soft +++ b/lib/openal-soft @@ -1 +1 @@ -Subproject commit fde74453a62a1ce4b5efaac0ec1835b9f5731e25 +Subproject commit d66107e9f008770b48f0df4fce041ee3e501e1e8 diff --git a/src/dawn/state/StateProvider.hpp b/src/dawn/state/StateProvider.hpp index dfd88e9d..f6355534 100644 --- a/src/dawn/state/StateProvider.hpp +++ b/src/dawn/state/StateProvider.hpp @@ -39,9 +39,10 @@ namespace Dawn { this->listeners.push_back(l); return std::bind([&](struct StateListener listener) { - auto it = std::find(listeners.begin(), listeners.end(), listener); - assertFalse(it == listeners.end()); - listeners.erase(it); + assertUnreachable(); + // auto it = std::find(listeners.begin(), listeners.end(), listener); + // assertFalse(it == listeners.end()); + // listeners.erase(it); }, l); } }; diff --git a/src/dawn/time/ITimeManager.cpp b/src/dawn/time/ITimeManager.cpp index b6bd0113..2eb45069 100644 --- a/src/dawn/time/ITimeManager.cpp +++ b/src/dawn/time/ITimeManager.cpp @@ -34,10 +34,10 @@ void ITimeManager::update(float_t delta) { // Interval provider auto itInterval = this->intervalProvider.listeners.begin(); while(itInterval != this->intervalProvider.listeners.end()) { - itInterval->data.second += delta; - if(itInterval->data.second >= itInterval->data.first) { + itInterval->data.time += delta; + if(itInterval->data.time >= itInterval->data.interval) { itInterval->callback(); - itInterval->data.second = 0; + itInterval->data.time = 0; } ++itInterval; } diff --git a/src/dawn/time/ITimeManager.hpp b/src/dawn/time/ITimeManager.hpp index 03393c0e..ef37d980 100644 --- a/src/dawn/time/ITimeManager.hpp +++ b/src/dawn/time/ITimeManager.hpp @@ -9,6 +9,11 @@ #include "state/StateProvider.hpp" namespace Dawn { + struct IntervalProviderData { + float_t interval; + float_t time; + }; + class ITimeManager { public: float_t time = 0.0f; @@ -17,7 +22,7 @@ namespace Dawn { bool_t isPaused = false; StateProviderSet timeoutProvider; - StateProviderSet> intervalProvider; + StateProviderSet intervalProvider; Event<> eventTimePaused; Event<> eventTimeResumed; @@ -79,7 +84,7 @@ namespace Dawn { T *context ) { return context->getGame()->timeManager.intervalProvider.addEffect( - callback, std::pair({ interval, 0 }), context + callback, { .interval = interval, .time = 0 }, context ); } } \ No newline at end of file