This commit is contained in:
2023-03-10 08:35:57 -08:00
parent 7e09b1760e
commit 09ab7622b5
6 changed files with 161 additions and 106 deletions

View File

@ -1,32 +1,57 @@
// 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;
}
}
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();
// 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.second += delta;
if(itInterval->data.second >= itInterval->data.first) {
itInterval->callback();
itInterval->data.second = 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();
}