timermanager now creates its own timers
This commit is contained in:
+20
-9
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user