split data into sortsession struct with vectors
This commit is contained in:
+1
-1
@@ -27,7 +27,7 @@ struct SortView {
|
||||
};
|
||||
|
||||
|
||||
class SteppedBsort: Steppable {
|
||||
class SteppedBsort: public Steppable {
|
||||
public:
|
||||
SortInput &data;
|
||||
size_t stepcount = 0;
|
||||
|
||||
+41
-17
@@ -3,6 +3,7 @@
|
||||
#include <cstddef>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
@@ -18,15 +19,17 @@
|
||||
#include <SFML/Window.hpp>
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
#include "steppable.hpp"
|
||||
#include "timer.hpp"
|
||||
#include "sorters.hpp"
|
||||
|
||||
using namespace std::chrono;
|
||||
using namespace std;
|
||||
|
||||
bool displaynumbers(vector<int> input) {
|
||||
for (size_t i = 0; i < input.size(); ++i) {
|
||||
printf("array:%d ", input[i]);
|
||||
bool displaySortInput(SortInput input) {
|
||||
cout << "name: " + input.name + " values: ";
|
||||
for (size_t i = 0; i < input.values.size(); ++i) {
|
||||
printf("%d | ",input.values[i]);
|
||||
}
|
||||
printf("\n");
|
||||
return false;
|
||||
@@ -45,21 +48,35 @@ vector<int> dataprovider(){
|
||||
return vector<int> {9,8,1,2,7,3,6,4,5};
|
||||
}
|
||||
|
||||
void setupsorttimers(TimerManager &mytimermanager, SteppedBsort &mysession){
|
||||
void setupsorttimers(TimerManager &mytimermanager, unique_ptr<Steppable> &mysession){
|
||||
unique_ptr<Timer> mytimer = make_unique<Timer>(
|
||||
"sort1", 0,
|
||||
[&mysession](){return mysession.step();},
|
||||
[&mysession](){return mysession->step();},
|
||||
milliseconds(250));
|
||||
mytimermanager.add_timer(std::move(mytimer));
|
||||
}
|
||||
|
||||
//list of inputs, manually assign them to sorts
|
||||
struct SortSession {
|
||||
vector<SortInput> &inputs;
|
||||
unique_ptr<Steppable> sorts;
|
||||
TimerManager SortTimer;
|
||||
|
||||
SortSession(vector<SortInput> &inputs): inputs(inputs), sorts(make_unique<SteppedBsort>(inputs[0])) {
|
||||
setupsorttimers(SortTimer, sorts);
|
||||
}
|
||||
|
||||
void update_sorts(){
|
||||
SortTimer.update_timers();
|
||||
}
|
||||
};
|
||||
|
||||
struct App{
|
||||
sf::RenderWindow mywindow;
|
||||
sf::Font myfont;
|
||||
sf::Text text;
|
||||
TimerManager mytimermanager;
|
||||
SortInput input;
|
||||
SteppedBsort mystb;
|
||||
vector<SortInput> inputs;
|
||||
SortSession mysortsession;
|
||||
|
||||
sf::Font load_font(const string &filename) {
|
||||
sf::Font font;
|
||||
@@ -70,19 +87,17 @@ struct App{
|
||||
return font;
|
||||
}
|
||||
|
||||
App(SortInput input):
|
||||
App(vector<SortInput> inputs):
|
||||
mywindow(sf::VideoMode({800,600}), "mywindow"),
|
||||
myfont(load_font("assets/NS-R.ttf")),
|
||||
text(myfont),
|
||||
input(std::move(input)),
|
||||
mystb(this->input)
|
||||
inputs(std::move(inputs)),
|
||||
mysortsession(this->inputs)
|
||||
{
|
||||
text.setFont(myfont);
|
||||
text.setString("Hello world");
|
||||
text.setCharacterSize(24);
|
||||
text.setFillColor(sf::Color::Red);
|
||||
|
||||
setupsorttimers(mytimermanager, mystb);
|
||||
}
|
||||
|
||||
void run(){
|
||||
@@ -95,11 +110,14 @@ struct App{
|
||||
|
||||
mywindow.clear(sf::Color::Black);
|
||||
mywindow.draw(text);
|
||||
text.setString(arraytostr(input));
|
||||
text.setString(arraytostr(inputs[0]));
|
||||
|
||||
mytimermanager.update_timers();
|
||||
mysortsession.update_sorts();
|
||||
|
||||
for (SortInput input : inputs) {
|
||||
displaySortInput(input);
|
||||
}
|
||||
|
||||
displaynumbers(input.values);
|
||||
|
||||
mywindow.display();
|
||||
this_thread::sleep_for(milliseconds(250));
|
||||
@@ -108,7 +126,13 @@ struct App{
|
||||
};
|
||||
|
||||
int main() {
|
||||
vector<SortInput> inputs;
|
||||
SortInput myinput("arr1", dataprovider());
|
||||
App myapp(myinput);
|
||||
SortInput myinput2("arr2", dataprovider());
|
||||
|
||||
inputs.push_back(myinput);
|
||||
inputs.push_back(myinput2);
|
||||
|
||||
App myapp(inputs);
|
||||
myapp.run();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user