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);
return std::bind([&](struct StateListener<D, A...> 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);
}
};

View File

@ -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;
}

View File

@ -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<float_t> timeoutProvider;
StateProviderSet<std::pair<float_t, float_t>> intervalProvider;
StateProviderSet<struct IntervalProviderData> intervalProvider;
Event<> eventTimePaused;
Event<> eventTimeResumed;
@ -79,7 +84,7 @@ namespace Dawn {
T *context
) {
return context->getGame()->timeManager.intervalProvider.addEffect(
callback, std::pair<float_t, float_t>({ interval, 0 }), context
callback, { .interval = interval, .time = 0 }, context
);
}
}