went from callback lambda to class with update function (command pattern?) so it can keep state. (to bypass for loop by counting iterations)
implemented reversing array and "animating" it
This commit is contained in:
@@ -6,25 +6,26 @@
|
||||
#include <memory>
|
||||
#include <ncurses.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// infinite timer
|
||||
timer::timer(std::string name_input, size_t interval_input,
|
||||
std::function<void(const timer &)> callback_input)
|
||||
std::unique_ptr<timeraction> action_input)
|
||||
: time_interval(interval_input), name(name_input), is_infinite(true),
|
||||
callbackfunc(callback_input) {}
|
||||
action(std::move(action_input)) {}
|
||||
|
||||
// limited timer
|
||||
timer::timer(std::string name, size_t interval_input, int triggeramount,
|
||||
std::function<void(const timer &)> callback)
|
||||
std::unique_ptr<timeraction> action_input)
|
||||
: triggeramount(triggeramount), time_interval(interval_input), name(name),
|
||||
callbackfunc(callback) {}
|
||||
action(std::move(action_input)) {}
|
||||
|
||||
// callbackfunc once enough time has accumulated
|
||||
void timer::updatetime(double DeltaTime) {
|
||||
accumulator += DeltaTime;
|
||||
if (!is_expired) {
|
||||
if (accumulator >= time_interval) {
|
||||
callbackfunc(*this);
|
||||
action->update(*this);
|
||||
accumulator -= time_interval;
|
||||
triggercounter++;
|
||||
if (!is_infinite && triggercounter >= triggeramount) {
|
||||
@@ -49,3 +50,15 @@ void timermanager::updatetimers(double dtime) {
|
||||
// implement delete timers
|
||||
refresh();
|
||||
}
|
||||
|
||||
swapaction::swapaction(std::vector<int> &input_vector): input_vector(input_vector){}
|
||||
|
||||
void swapaction::update(const timer &input_timer){
|
||||
if (!iscomplete) {
|
||||
int temp = input_vector[it_i];
|
||||
input_vector[it_i] = input_vector[input_vector.size() -1 - it_i];
|
||||
input_vector[input_vector.size() - 1 - it_i] = temp;
|
||||
it_i++;
|
||||
if(it_i>=input_vector.size() / 2){iscomplete=true;}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user