split app into seperate files to clean main

This commit is contained in:
2026-08-12 02:05:51 +02:00
parent 005d4282a9
commit ad94f758fc
4 changed files with 133 additions and 104 deletions
+1 -104
View File
@@ -1,14 +1,7 @@
// for now juist CLI, print an arr, then print each it
#include <chrono>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <memory>
#include <sstream>
#include <string>
#include <thread>
#include <utility>
#include <vector>
#include <SFML/Graphics/Color.hpp>
@@ -19,6 +12,7 @@
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include "core/app.hpp"
#include "steppable.hpp"
#include "timer.hpp"
#include "sorters.hpp"
@@ -26,23 +20,6 @@
using namespace std::chrono;
using namespace std;
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;
}
string arraytostr(SortInput input) {
string myoutput;
ostringstream stringrep;
for (size_t i = 0; i < input.values.size(); ++i) {
stringrep << input.values[i] <<" | ";
}
return stringrep.str();
}
vector<int> dataprovider(){
return vector<int> {9,8,1,2,7,3,6,4,5};
@@ -55,86 +32,6 @@ void setupsorttimers(TimerManager &mytimermanager, unique_ptr<Steppable> &mysess
milliseconds(250));
}
//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);
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;
sf::Text text;
vector<SortInput> inputs;
SortSession mysortsession;
sf::Font load_font(const string &filename) {
sf::Font font;
if (!font.openFromFile(filename)){
fprintf(stderr, "failed to load font");
std::exit(1);
}
return font;
}
App(vector<SortInput> inputs):
mywindow(sf::VideoMode({800,600}), "mywindow"),
myfont(load_font("assets/NS-R.ttf")),
text(myfont),
inputs(std::move(inputs)),
mysortsession(this->inputs)
{
text.setFont(myfont);
text.setString("Hello world");
text.setCharacterSize(24);
text.setFillColor(sf::Color::Red);
}
void run(){
//set up ui
while (mywindow.isOpen()){
while (const optional event = mywindow.pollEvent()){
if (event->is<sf::Event::Closed>())
mywindow.close();
}
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));
}
}
};
int main() {
vector<SortInput> inputs;