updated naming
This commit is contained in:
+15
-16
@@ -2,47 +2,46 @@
|
||||
#include "timer.hpp"
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <ncurses.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// infinite timer
|
||||
timer::timer(std::string name_input, double interval_input,
|
||||
std::unique_ptr<timeraction> action_input)
|
||||
Timer::Timer(std::string name_input, double interval_input,
|
||||
std::unique_ptr<TimerAction> action_input)
|
||||
: time_interval(interval_input), name(name_input), is_infinite(true),
|
||||
action(std::move(action_input)) {}
|
||||
|
||||
// limited timer
|
||||
timer::timer(std::string name, double interval_input, int triggeramount,
|
||||
std::unique_ptr<timeraction> action_input)
|
||||
: triggeramount(triggeramount), time_interval(interval_input), name(name),
|
||||
Timer::Timer(std::string name, double interval_input, int trigger_amount,
|
||||
std::unique_ptr<TimerAction> action_input)
|
||||
: trigger_amount(trigger_amount), time_interval(interval_input), name(name),
|
||||
action(std::move(action_input)) {}
|
||||
|
||||
// callbackfunc once enough time has accumulated
|
||||
void timer::updatetime(double DeltaTime) {
|
||||
accumulator += DeltaTime;
|
||||
void Timer::updatetime(double delta_time) {
|
||||
accumulator += delta_time;
|
||||
if (!is_expired) {
|
||||
if (accumulator >= time_interval) {
|
||||
action->update(*this);
|
||||
accumulator -= time_interval;
|
||||
triggercounter++;
|
||||
if (!is_infinite && triggercounter >= triggeramount) {
|
||||
trigger_counter++;
|
||||
if (!is_infinite && trigger_counter >= trigger_amount) {
|
||||
is_expired = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void timermanager::addtimer(std::unique_ptr<timer> input_timer) {
|
||||
void TimerManager::addtimer(std::unique_ptr<Timer> input_timer) {
|
||||
timers.push_back(std::move(input_timer));
|
||||
}
|
||||
|
||||
void timermanager::updatetimers() {
|
||||
void TimerManager::updatetimers() {
|
||||
//get dtime
|
||||
auto currenttime = std::chrono::steady_clock::now();
|
||||
std::chrono::duration<double> myDeltaTime = currenttime - prevtime;
|
||||
auto current_time = std::chrono::steady_clock::now();
|
||||
std::chrono::duration<double> myDeltaTime = current_time - prev_time;
|
||||
double dtime = myDeltaTime.count();
|
||||
|
||||
//update timers with dtime
|
||||
@@ -51,7 +50,7 @@ void timermanager::updatetimers() {
|
||||
mvprintw(12, 0, "updated timer %s", mytimer->name.c_str());
|
||||
}
|
||||
//reset for next tick
|
||||
prevtime = currenttime;
|
||||
prev_time = current_time;
|
||||
timers.erase(std::remove_if(timers.begin(), timers.end(),
|
||||
[](auto &timer) { return timer->is_expired; }),
|
||||
timers.end());
|
||||
@@ -59,5 +58,5 @@ void timermanager::updatetimers() {
|
||||
refresh();
|
||||
}
|
||||
|
||||
timermanager::timermanager(): prevtime(std::chrono::steady_clock::now()){}
|
||||
TimerManager::TimerManager(): prev_time(std::chrono::steady_clock::now()){}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user