Added interval
This commit is contained in:
2
lib/SDL
2
lib/SDL
Submodule lib/SDL updated: c9aec268fa...87a83787a3
Submodule lib/openal-soft updated: fde74453a6...d66107e9f0
@ -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);
|
||||
}
|
||||
};
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user