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:
2026-07-10 21:54:58 +02:00
parent f3b7de0489
commit 523dac1f4d
3 changed files with 80 additions and 19 deletions
+27 -5
View File
@@ -8,7 +8,13 @@
#include <string>
#include <vector>
class timer;
class timeraction {
public:
virtual ~timeraction() = default;
virtual void update(const timer &t) = 0;
};
class timer {
private:
@@ -21,18 +27,19 @@ public:
std::string name;
int triggercounter = 0;
bool is_infinite = false;
std::function<void(const timer&)> callbackfunc;
std::unique_ptr<timeraction> action;
bool is_expired = false;
//infinite timer
timer(std::string name_input, size_t interval_input,
std::function<void(const timer &)> callback_input);
std::unique_ptr<timeraction> action_input
);
//limited timer
timer(std::string name, size_t interval_input, int triggeramount,
std::function<void(const timer &)> callback);
std::unique_ptr<timeraction> action
);
// callbackfunc once enough time has accumulated
void updatetime(double DeltaTime);
};
@@ -47,4 +54,19 @@ public:
void updatetimers(double dtime);
};
#endif
class swapaction : public timeraction {
public:
size_t it_i = 0;
bool iscomplete = false;
std::vector<int> &input_vector;
swapaction(std::vector<int> &input_vector);
void update(const timer &t);
};
#endif
/*
externalize state
*/