Added interval

This commit is contained in:
2023-03-10 09:18:32 -08:00
parent 5c6436dd18
commit 93ff957e38
5 changed files with 16 additions and 10 deletions

Submodule lib/SDL updated: c9aec268fa...87a83787a3

View File

@ -39,9 +39,10 @@ namespace Dawn {
this->listeners.push_back(l); this->listeners.push_back(l);
return std::bind([&](struct StateListener<D, A...> listener) { return std::bind([&](struct StateListener<D, A...> listener) {
auto it = std::find(listeners.begin(), listeners.end(), listener); assertUnreachable();
assertFalse(it == listeners.end()); // auto it = std::find(listeners.begin(), listeners.end(), listener);
listeners.erase(it); // assertFalse(it == listeners.end());
// listeners.erase(it);
}, l); }, l);
} }
}; };

View File

@ -34,10 +34,10 @@ void ITimeManager::update(float_t delta) {
// Interval provider // Interval provider
auto itInterval = this->intervalProvider.listeners.begin(); auto itInterval = this->intervalProvider.listeners.begin();
while(itInterval != this->intervalProvider.listeners.end()) { while(itInterval != this->intervalProvider.listeners.end()) {
itInterval->data.second += delta; itInterval->data.time += delta;
if(itInterval->data.second >= itInterval->data.first) { if(itInterval->data.time >= itInterval->data.interval) {
itInterval->callback(); itInterval->callback();
itInterval->data.second = 0; itInterval->data.time = 0;
} }
++itInterval; ++itInterval;
} }

View File

@ -9,6 +9,11 @@
#include "state/StateProvider.hpp" #include "state/StateProvider.hpp"
namespace Dawn { namespace Dawn {
struct IntervalProviderData {
float_t interval;
float_t time;
};
class ITimeManager { class ITimeManager {
public: public:
float_t time = 0.0f; float_t time = 0.0f;
@ -17,7 +22,7 @@ namespace Dawn {
bool_t isPaused = false; bool_t isPaused = false;
StateProviderSet<float_t> timeoutProvider; StateProviderSet<float_t> timeoutProvider;
StateProviderSet<std::pair<float_t, float_t>> intervalProvider; StateProviderSet<struct IntervalProviderData> intervalProvider;
Event<> eventTimePaused; Event<> eventTimePaused;
Event<> eventTimeResumed; Event<> eventTimeResumed;
@ -79,7 +84,7 @@ namespace Dawn {
T *context T *context
) { ) {
return context->getGame()->timeManager.intervalProvider.addEffect( return context->getGame()->timeManager.intervalProvider.addEffect(
callback, std::pair<float_t, float_t>({ interval, 0 }), context callback, { .interval = interval, .time = 0 }, context
); );
} }
} }