Viewer done
This commit is contained in:
parent
c8b68ae030
commit
bba921a2c4
@ -54,17 +54,8 @@ void checker()
|
||||
}
|
||||
printf("Start Check\n");
|
||||
DnaManagerData data;
|
||||
data.id = user_id;
|
||||
data.randSeed = mrand::getState(data.id);
|
||||
data.queued = 0;
|
||||
data.showed = 0;
|
||||
data.generation = 0;
|
||||
data.vector.resize(NUM_PER_GEN);
|
||||
DnaManager::setUp(&data, user_id);
|
||||
|
||||
for (std::size_t i = 0; i < NUM_PER_GEN; i++)
|
||||
{
|
||||
DNA::newDna(&data.vector[i], &data.randSeed);
|
||||
}
|
||||
bool found_err = false;
|
||||
while (found_err != true)
|
||||
{
|
||||
|
@ -45,4 +45,6 @@ namespace DnaManager
|
||||
UiUnit next(DnaManagerData *data);
|
||||
bool like(UiUnit unit, DnaManagerData *data);
|
||||
void newGen(DnaManagerData *data);
|
||||
void setUp(DnaManagerData *data, int64_t id);
|
||||
void cleanUp(DnaManagerData *data, int64_t id);
|
||||
};
|
||||
|
@ -108,3 +108,25 @@ void DnaManager::newGen(DnaManagerData *data)
|
||||
data->disliked.clear();
|
||||
data->liked.clear();
|
||||
}
|
||||
|
||||
void DnaManager::setUp(DnaManagerData *data, int64_t id)
|
||||
{
|
||||
data->vector.resize(NUM_PER_GEN);
|
||||
cleanUp(data, id);
|
||||
}
|
||||
|
||||
void DnaManager::cleanUp(DnaManagerData *data, int64_t id)
|
||||
{
|
||||
data->id = id;
|
||||
data->randSeed = mrand::getState(id);
|
||||
data->queued = 0;
|
||||
data->showed = 0;
|
||||
data->generation = 0;
|
||||
data->liked.clear();
|
||||
data->disliked.clear();
|
||||
|
||||
for (std::size_t i = 0; i < NUM_PER_GEN; i++)
|
||||
{
|
||||
DNA::newDna(&data->vector[i], &data->randSeed);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,14 @@
|
||||
#include <vector>
|
||||
#include "sql.hpp"
|
||||
#include "values/DnaManager.hpp"
|
||||
#include "canvas/Canvas.hpp"
|
||||
|
||||
enum DrawingStage{
|
||||
setup,
|
||||
drawTree,
|
||||
drawBig,
|
||||
done,
|
||||
};
|
||||
|
||||
class Vapp
|
||||
{
|
||||
@ -16,8 +25,20 @@ private:
|
||||
sqlite3_stmt *get_gen_num;
|
||||
std::vector<int64_t> ids;
|
||||
int64_t gens = -1;
|
||||
int selected_id = -1;
|
||||
bool update_gen = false;
|
||||
int selected_gen = -1;
|
||||
bool enableAll = true;
|
||||
|
||||
int64_t selected_id = -1;
|
||||
int selected_gen = -1;
|
||||
DnaManagerData manager;
|
||||
DrawingStage stageOfDrawing = DrawingStage::done;
|
||||
|
||||
Canvas canvas;
|
||||
RenderTexture2D treeTexture;
|
||||
int drawTreeIndex = -1;
|
||||
|
||||
RenderTexture2D bigTexture;
|
||||
int drawX = 0;
|
||||
int drawY = 0;
|
||||
void setUpManager();
|
||||
};
|
@ -10,8 +10,16 @@
|
||||
|
||||
const char select_user_id[] = "SELECT USER_ID FROM user_table GROUP BY USER_ID;";
|
||||
|
||||
constexpr int sizeOfCanvas = 1000;
|
||||
|
||||
void Vapp::init()
|
||||
{
|
||||
bigTexture = LoadRenderTexture(sizeOfCanvas * 4, sizeOfCanvas * 4);
|
||||
treeTexture = LoadRenderTexture(sizeOfCanvas, sizeOfCanvas);
|
||||
canvas.init(sizeOfCanvas);
|
||||
|
||||
DnaManager::setUp(&manager, 0);
|
||||
|
||||
sql::init();
|
||||
sql::open(DB_NAME, &db);
|
||||
|
||||
@ -47,21 +55,75 @@ void Vapp::update()
|
||||
|
||||
update_gen = false;
|
||||
}
|
||||
|
||||
switch (stageOfDrawing)
|
||||
{
|
||||
case DrawingStage::setup:
|
||||
setUpManager();
|
||||
stageOfDrawing = DrawingStage::drawTree;
|
||||
drawTreeIndex = 0;
|
||||
drawX = 0;
|
||||
drawY = 0;
|
||||
canvas.newGen(treeTexture, &manager.vector[drawTreeIndex]);
|
||||
break;
|
||||
case DrawingStage::drawTree:
|
||||
if (canvas.tick(treeTexture))
|
||||
{
|
||||
stageOfDrawing = DrawingStage::drawBig;
|
||||
}
|
||||
break;
|
||||
case DrawingStage::drawBig:
|
||||
BeginTextureMode(bigTexture);
|
||||
DrawTexture(treeTexture.texture, drawX * sizeOfCanvas, drawY * sizeOfCanvas, WHITE);
|
||||
EndTextureMode();
|
||||
|
||||
drawTreeIndex++;
|
||||
if (drawTreeIndex < NUM_PER_GEN)
|
||||
{
|
||||
canvas.newGen(treeTexture, &manager.vector[drawTreeIndex]);
|
||||
stageOfDrawing = DrawingStage::drawTree;
|
||||
}
|
||||
else
|
||||
{
|
||||
stageOfDrawing = DrawingStage::done;
|
||||
}
|
||||
|
||||
drawX++;
|
||||
if (drawX == 4)
|
||||
{
|
||||
drawY++;
|
||||
drawX = 0;
|
||||
}
|
||||
if (drawY == 4)
|
||||
{
|
||||
drawY = 0;
|
||||
}
|
||||
break;
|
||||
case DrawingStage::done:
|
||||
enableAll = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Vapp::draw()
|
||||
{
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
DrawTextureEx(bigTexture.texture, Vector2(0,0), 0.0f, 0.25f, WHITE);
|
||||
|
||||
ImGui::DockSpaceOverViewport(0, NULL, ImGuiDockNodeFlags_PassthruCentralNode);
|
||||
|
||||
if (ImGui::BeginMainMenuBar())
|
||||
{
|
||||
ImGui::MenuItem("Demo Window", nullptr, &showDemoWindow, enableAll);
|
||||
ImGui::MenuItem("Selection", nullptr, &showSelection, enableAll);
|
||||
if(ImGui::MenuItem("Draw", nullptr, false, enableAll)){
|
||||
if (ImGui::MenuItem("Draw", nullptr, false, enableAll))
|
||||
{
|
||||
enableAll = false;
|
||||
showSelection = false;
|
||||
stageOfDrawing = DrawingStage::setup;
|
||||
}
|
||||
ImGui::EndMainMenuBar();
|
||||
}
|
||||
@ -103,5 +165,51 @@ void Vapp::draw()
|
||||
|
||||
void Vapp::deinit()
|
||||
{
|
||||
UnloadRenderTexture(treeTexture);
|
||||
UnloadRenderTexture(bigTexture);
|
||||
canvas.deinit();
|
||||
sql::close(db);
|
||||
sql::shutdown();
|
||||
}
|
||||
|
||||
void Vapp::setUpManager()
|
||||
{
|
||||
|
||||
sqlite3_stmt *get_gen_stmt;
|
||||
sql::prepare_v2(db, get_gen, -1, &get_gen_stmt, NULL);
|
||||
|
||||
DnaManager::cleanUp(&manager, selected_id);
|
||||
int lodedGen = -1;
|
||||
|
||||
while (lodedGen < selected_gen)
|
||||
{
|
||||
sql::bind_int64(get_gen_stmt, 1, manager.id);
|
||||
sql::bind_int64(get_gen_stmt, 2, manager.generation);
|
||||
|
||||
bool new_gen = false;
|
||||
while (sql::step(get_gen_stmt) != SQL_DONE)
|
||||
{
|
||||
int64_t pos = sql::column_int64(get_gen_stmt, 1);
|
||||
int64_t liked = sql::column_int64(get_gen_stmt, 2);
|
||||
UiUnit unit = DnaManager::next(&manager);
|
||||
if ((unit.index != pos))
|
||||
{
|
||||
// DOTO: SET ERROR
|
||||
sql::finalize(get_gen_stmt);
|
||||
return;
|
||||
}
|
||||
unit.liked = (Liked)liked;
|
||||
new_gen = DnaManager::like(unit, &manager);
|
||||
}
|
||||
|
||||
if (manager.generation < selected_gen)
|
||||
{
|
||||
DnaManager::newGen(&manager);
|
||||
}
|
||||
|
||||
sql::reset(get_gen_stmt);
|
||||
lodedGen++;
|
||||
}
|
||||
|
||||
sql::finalize(get_gen_stmt);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user