timermanager now creates its own timers

This commit is contained in:
2026-08-12 01:43:50 +02:00
parent e6e170a42a
commit 8a60e45cd1
3 changed files with 34 additions and 23 deletions
+20 -9
View File
@@ -49,11 +49,10 @@ vector<int> dataprovider(){
}
void setupsorttimers(TimerManager &mytimermanager, unique_ptr<Steppable> &mysession){
unique_ptr<Timer> mytimer = make_unique<Timer>(
"sort1", 0,
[&mysession](){return mysession->step();},
milliseconds(250));
mytimermanager.add_timer(std::move(mytimer));
mytimermanager.add_timer(
0,
[&mysession](){return mysession->step();},
milliseconds(250));
}
//list of inputs, manually assign them to sorts
@@ -63,14 +62,27 @@ struct SortSession {
TimerManager SortTimer;
SortSession(vector<SortInput> &inputs): inputs(inputs), sorts(make_unique<SteppedBsort>(inputs[0])) {
setupsorttimers(SortTimer, sorts);
//setupsorttimers(SortTimer, sorts);
add_session(sorts);
}
void add_session(unique_ptr<Steppable> &mysteppable){
SortTimer.add_timer(0,
[&mysteppable]() {return mysteppable->step();},
milliseconds(250));
}
void update_sorts(){
SortTimer.update_timers();
}
};
struct ViewSession{
sf::RenderWindow mywindow;
sf::Font myfont;
sf::Text text;
};
struct App{
sf::RenderWindow mywindow;
sf::Font myfont;
@@ -111,13 +123,12 @@ struct App{
mywindow.clear(sf::Color::Black);
mywindow.draw(text);
text.setString(arraytostr(inputs[0]));
mysortsession.update_sorts();
for (SortInput input : inputs) {
displaySortInput(input);
}
mywindow.display();
this_thread::sleep_for(milliseconds(250));
@@ -132,7 +143,7 @@ int main() {
inputs.push_back(myinput);
inputs.push_back(myinput2);
App myapp(inputs);
myapp.run();
}