57 lines
1.4 KiB
C++
57 lines
1.4 KiB
C++
// Copyright (c) 2022 Dominic Masters
|
|
//
|
|
// This software is released under the MIT License.
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
#include "ITimeManager.hpp"
|
|
|
|
using namespace Dawn;
|
|
|
|
ITimeManager::ITimeManager() {
|
|
|
|
}
|
|
|
|
void ITimeManager::update(float_t delta) {
|
|
this->delta = delta;
|
|
this->time += delta;
|
|
|
|
if(!this->isPaused) {
|
|
this->unpausedTime += delta;
|
|
|
|
// Timeout effect provider
|
|
auto itEffect = this->timeoutProvider.listeners.begin();
|
|
while(itEffect != this->timeoutProvider.listeners.end()) {
|
|
itEffect->data -= delta;
|
|
if(itEffect->data <= 0) {
|
|
itEffect->callback();
|
|
itEffect = this->timeoutProvider.listeners.erase(itEffect);
|
|
continue;
|
|
}
|
|
++itEffect;
|
|
}
|
|
|
|
|
|
// Interval provider
|
|
auto itInterval = this->intervalProvider.listeners.begin();
|
|
while(itInterval != this->intervalProvider.listeners.end()) {
|
|
itInterval->data.time += delta;
|
|
if(itInterval->data.time >= itInterval->data.interval) {
|
|
itInterval->callback();
|
|
itInterval->data.time = 0;
|
|
}
|
|
++itInterval;
|
|
}
|
|
}
|
|
}
|
|
|
|
void ITimeManager::pause() {
|
|
if(this->isPaused) return;
|
|
this->isPaused = true;
|
|
this->eventTimePaused.invoke();
|
|
}
|
|
|
|
void ITimeManager::resume() {
|
|
if(!this->isPaused) return;
|
|
this->isPaused = false;
|
|
this->eventTimeResumed.invoke();
|
|
} |