85 lines
1.4 KiB
C++
85 lines
1.4 KiB
C++
#include "sortiva.hpp"
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <memory>
|
|
#include <random>
|
|
|
|
|
|
#include <raylib.h>
|
|
|
|
|
|
void Sortiva::init() {
|
|
m_Sorter.set(m_List);
|
|
|
|
m_Steps = std::make_unique<val_step_diag>();
|
|
|
|
InitWindow(1280, 720, "Sortiva");
|
|
if (!IsWindowReady()) exit(2);
|
|
|
|
m_Width = GetRenderWidth();
|
|
m_Height = GetRenderHeight();
|
|
SetWindowMinSize(static_cast<int>(1280 * 0.25f), static_cast<int>(720 * 0.25f));
|
|
SetWindowState(ConfigFlags::FLAG_WINDOW_RESIZABLE | ConfigFlags::FLAG_VSYNC_HINT);
|
|
|
|
SetTargetFPS(60);
|
|
|
|
MaximizeWindow();
|
|
}
|
|
|
|
Sortiva::Sortiva(uint8_t count) : m_Ticker(std::chrono::seconds(1)) {
|
|
init();
|
|
count--;
|
|
m_CountValues = count % 7;
|
|
m_CountValues++;
|
|
}
|
|
|
|
Sortiva::~Sortiva()
|
|
{
|
|
CloseWindow();
|
|
}
|
|
|
|
void Sortiva::run()
|
|
{
|
|
while (m_Running)
|
|
{
|
|
if (WindowShouldClose()) m_Running = false;
|
|
if (IsWindowResized())
|
|
{
|
|
m_Width = GetScreenWidth();
|
|
m_Height = GetScreenHeight();
|
|
}
|
|
|
|
ClearBackground({ 25, 25, 25, 255 });
|
|
BeginDrawing();
|
|
|
|
update(GetFrameTime());
|
|
draw();
|
|
draw_overlay();
|
|
|
|
EndDrawing();
|
|
}
|
|
}
|
|
|
|
void Sortiva::setup()
|
|
{
|
|
m_Steps->clear();
|
|
m_List.list.clear();
|
|
|
|
|
|
for (uint8_t i = 1; i <= m_CountValues; ++i) // 1,2,3,4,5
|
|
{
|
|
m_List.list.push_back(i);
|
|
m_Steps->emplace_back();
|
|
}
|
|
|
|
std::random_device dev;
|
|
std::mt19937 rng(dev());
|
|
|
|
std::ranges::shuffle(m_List.list, rng); // 2,3,1,5,4
|
|
|
|
for (uint8_t i = 1; i <= m_CountValues; ++i)
|
|
{
|
|
m_Steps->at(m_List.at(i - 1) - 1).value = i;
|
|
}
|
|
}
|