headers, split steppable
This commit is contained in:
+6
-5
@@ -1,11 +1,12 @@
|
||||
#ifndef _SORTERS_
|
||||
#define _SORTERS_
|
||||
#ifndef SORTERS_HPP
|
||||
#define SORTERS_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "timer.hpp"
|
||||
|
||||
#include "steppable.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -29,10 +30,10 @@ struct SortView {
|
||||
class SteppedBsort: Steppable {
|
||||
public:
|
||||
SortInput &data;
|
||||
int stepcount = 0;
|
||||
size_t stepcount = 0;
|
||||
size_t i = 0;
|
||||
size_t j = 0;
|
||||
bool is_finished;
|
||||
bool is_finished = false;
|
||||
|
||||
SteppedBsort(SortInput &data);
|
||||
|
||||
|
||||
+7
-6
@@ -1,9 +1,4 @@
|
||||
// for now juist CLI, print an arr, then print each it
|
||||
#include <SFML/Graphics/Color.hpp>
|
||||
#include <SFML/Graphics/Font.hpp>
|
||||
#include <SFML/Graphics/RenderWindow.hpp>
|
||||
#include <SFML/Graphics/Text.hpp>
|
||||
#include <SFML/Window/Window.hpp>
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <cstdio>
|
||||
@@ -15,6 +10,11 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <SFML/Graphics/Color.hpp>
|
||||
#include <SFML/Graphics/Font.hpp>
|
||||
#include <SFML/Graphics/RenderWindow.hpp>
|
||||
#include <SFML/Graphics/Text.hpp>
|
||||
#include <SFML/Window/Window.hpp>
|
||||
#include <SFML/Window.hpp>
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
@@ -53,7 +53,6 @@ void setupsorttimers(TimerManager &mytimermanager, SteppedBsort &mysession){
|
||||
mytimermanager.add_timer(std::move(mytimer));
|
||||
}
|
||||
|
||||
|
||||
struct App{
|
||||
sf::RenderWindow mywindow;
|
||||
sf::Font myfont;
|
||||
@@ -87,6 +86,7 @@ struct App{
|
||||
}
|
||||
|
||||
void run(){
|
||||
//set up ui
|
||||
while (mywindow.isOpen()){
|
||||
while (const optional event = mywindow.pollEvent()){
|
||||
if (event->is<sf::Event::Closed>())
|
||||
@@ -96,6 +96,7 @@ struct App{
|
||||
mywindow.clear(sf::Color::Black);
|
||||
mywindow.draw(text);
|
||||
text.setString(arraytostr(input));
|
||||
|
||||
mytimermanager.update_timers();
|
||||
|
||||
displaynumbers(input.values);
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef STEPPABLE_HPP
|
||||
#define STEPPABLE_HPP
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
class Steppable {
|
||||
public:
|
||||
virtual ~Steppable() = default;
|
||||
bool is_finished = 0;
|
||||
size_t stepcount = 0;
|
||||
virtual bool step() = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
+3
-5
@@ -15,11 +15,9 @@ void Timer::add_time(milliseconds deltatime) {
|
||||
accumulator += deltatime;
|
||||
if (accumulator >= triggerinterval) {
|
||||
accumulator -= triggerinterval;
|
||||
if (timeraction()==true){
|
||||
isdone = true;
|
||||
};
|
||||
triggercounter++;
|
||||
if (!isinfinite && triggercounter >= triggeramount){
|
||||
timeraction();
|
||||
triggercount++;
|
||||
if (!isinfinite && triggercount >= triggeramount){
|
||||
isexpired=true;
|
||||
}
|
||||
}
|
||||
|
||||
+11
-20
@@ -1,5 +1,5 @@
|
||||
#ifndef _TIMERS_
|
||||
#define _TIMERS_
|
||||
#ifndef TIMER_HPP
|
||||
#define TIMER_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <ctime>
|
||||
@@ -9,48 +9,39 @@
|
||||
#include <chrono>
|
||||
#include <vector>
|
||||
|
||||
using namespace std::chrono;
|
||||
using namespace std;
|
||||
|
||||
class Steppable {
|
||||
public:
|
||||
bool is_finished = 0;
|
||||
virtual bool step() = 0;
|
||||
};
|
||||
|
||||
//check if the timer is valid, check if enough time has passed and if so, actuate
|
||||
//check if the timer is still valid, check if enough time has passed and if so, actuate action
|
||||
class Timer {
|
||||
public:
|
||||
string name;
|
||||
size_t triggeramount;
|
||||
|
||||
bool isexpired = false;
|
||||
bool isdone = false;
|
||||
bool isinfinite = false;
|
||||
size_t triggercounter = 0;
|
||||
size_t triggercount = 0;
|
||||
function<bool()> timeraction;
|
||||
|
||||
Timer(string name, int triggercount, function<bool()> myaction, milliseconds triggerinterval);
|
||||
void add_time(milliseconds deltatime);
|
||||
Timer(string name, int triggercount, function<bool()> myaction, std::chrono::milliseconds triggerinterval);
|
||||
void add_time(std::chrono::milliseconds deltatime);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
milliseconds accumulator = milliseconds(0);
|
||||
milliseconds triggerinterval = milliseconds(1000); //default to 1 sec
|
||||
std::chrono::milliseconds accumulator = std::chrono::milliseconds(0);
|
||||
std::chrono::milliseconds triggerinterval = std::chrono::milliseconds(1000); //default to 1 sec
|
||||
};
|
||||
|
||||
//CRUD timers and give them dt
|
||||
//CRUD timers and give them dt on update
|
||||
class TimerManager {
|
||||
public:
|
||||
vector<unique_ptr<Timer>> timers;
|
||||
TimerManager() { previoustime = steady_clock::now(); }
|
||||
TimerManager() { previoustime = std::chrono::steady_clock::now(); }
|
||||
void add_timer(unique_ptr<Timer> newtimer);
|
||||
void delete_timer();
|
||||
void update_timers();
|
||||
|
||||
private:
|
||||
steady_clock::time_point previoustime;
|
||||
std::chrono::steady_clock::time_point previoustime;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user