Compare commits
8 Commits
FPS_Tests
...
771cabed8f
| Author | SHA1 | Date | |
|---|---|---|---|
| 771cabed8f | |||
| 96f4f51e69 | |||
| 525936c6e7 | |||
| 060b9f9182 | |||
| 59fd47e684 | |||
| 593b813988 | |||
| 5f6305a2f2 | |||
| dddf8ca632 |
@@ -8,11 +8,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||
# set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||
add_compile_options(-ggdb)
|
||||
|
||||
include_directories(
|
||||
external/include
|
||||
shared/inc
|
||||
)
|
||||
|
||||
include_directories(external/include/)
|
||||
link_libraries(
|
||||
${CMAKE_SOURCE_DIR}/external/libimgui.a
|
||||
${CMAKE_SOURCE_DIR}/external/libraylib.a
|
||||
@@ -22,7 +18,11 @@ link_libraries(
|
||||
m
|
||||
)
|
||||
|
||||
add_library(shared STATIC
|
||||
add_executable(app
|
||||
app/src/main.cpp
|
||||
app/src/App.cpp
|
||||
app/src/DnaStore.cpp
|
||||
app/src/sys.cpp
|
||||
shared/src/canvas/BackGround.cpp
|
||||
shared/src/canvas/BackGroundColors.cpp
|
||||
shared/src/canvas/Canvas.cpp
|
||||
@@ -32,36 +32,36 @@ add_library(shared STATIC
|
||||
shared/src/values/mrand.cpp
|
||||
shared/src/values/Similarity.cpp
|
||||
shared/src/TcpSocket.cpp
|
||||
)
|
||||
# Add include directories
|
||||
target_include_directories(app PRIVATE app/inc shared/inc )
|
||||
|
||||
add_executable(server
|
||||
server/src/server.cpp
|
||||
server/src/checker.cpp
|
||||
|
||||
shared/src/sql.cpp
|
||||
shared/src/timing.cpp
|
||||
shared/src/TcpSocket.cpp
|
||||
shared/src/values/Dna.cpp
|
||||
shared/src/values/DnaManager.cpp
|
||||
shared/src/values/mrand.cpp
|
||||
)
|
||||
# Add include directories
|
||||
target_include_directories(server PRIVATE server/inc shared/inc)
|
||||
|
||||
add_executable(app
|
||||
app/src/main.cpp
|
||||
app/src/App.cpp
|
||||
app/src/DnaStore.cpp
|
||||
app/src/sys.cpp
|
||||
add_executable(view
|
||||
view/src/main.cpp
|
||||
view/src/Vapp.cpp
|
||||
shared/src/canvas/BackGround.cpp
|
||||
shared/src/canvas/BackGroundColors.cpp
|
||||
shared/src/canvas/Canvas.cpp
|
||||
shared/src/canvas/Tree.cpp
|
||||
shared/src/values/Dna.cpp
|
||||
shared/src/values/DnaManager.cpp
|
||||
shared/src/values/mrand.cpp
|
||||
shared/src/values/Similarity.cpp
|
||||
|
||||
shared/src/sql.cpp
|
||||
)
|
||||
target_include_directories(app PRIVATE app/inc)
|
||||
target_link_libraries(app PRIVATE shared)
|
||||
|
||||
# add_executable(server
|
||||
# server/src/server.cpp
|
||||
# server/src/checker.cpp
|
||||
# )
|
||||
# target_include_directories(server PRIVATE server/inc)
|
||||
# target_link_libraries(server PRIVATE shared)
|
||||
|
||||
# add_executable(view
|
||||
# view/src/main.cpp
|
||||
# view/src/Vapp.cpp
|
||||
# )
|
||||
# target_include_directories(view PRIVATE view/inc)
|
||||
# target_link_libraries(view PRIVATE shared)
|
||||
|
||||
# add_executable(slike
|
||||
# random/slike.cpp
|
||||
# )
|
||||
# target_link_libraries(slike PRIVATE shared)
|
||||
|
||||
file(COPY CascadiaCode.ttf DESTINATION "res")
|
||||
# Add include directories
|
||||
target_include_directories(view PRIVATE view/inc shared/inc)
|
||||
BIN
CascadiaCode.ttf
BIN
CascadiaCode.ttf
Binary file not shown.
@@ -18,14 +18,30 @@ private:
|
||||
int screenWidth, screenHeight;
|
||||
Canvas canvas;
|
||||
|
||||
RenderTexture2D canvasTexure = {0};
|
||||
int pos = 0;
|
||||
std::array<RenderTexture2D, 2> canvasTexure = {0};
|
||||
|
||||
float rotation = 0.0f;
|
||||
Vector2 mouseStart;
|
||||
bool validHit = false;
|
||||
float len;
|
||||
float ofset;
|
||||
|
||||
Liked topLiked = Liked::tbd;
|
||||
|
||||
Rectangle destA;
|
||||
Rectangle destB;
|
||||
Rectangle likeBox;
|
||||
Rectangle disLikeBox;
|
||||
|
||||
UiUnit unit = {0};
|
||||
std::array<UiUnit, 2> unit = {0};
|
||||
|
||||
DnaManagerData manager;
|
||||
|
||||
Rectangle likedTextBox;
|
||||
Rectangle genTextBox;
|
||||
Rectangle simTextBox;
|
||||
float simil = 100.0f;
|
||||
|
||||
Color appColor = BLUE;
|
||||
};
|
||||
|
||||
225
app/src/App.cpp
225
app/src/App.cpp
@@ -2,118 +2,241 @@
|
||||
#include <cmath>
|
||||
|
||||
#include "App.hpp"
|
||||
#include "timing.hpp"
|
||||
|
||||
#include <raylib.h>
|
||||
#include <raymath.h>
|
||||
|
||||
Font fontTtf;
|
||||
#define TOP (1 - pos)
|
||||
#define BOTTOM pos
|
||||
|
||||
void DrawTextB(const char *text, float posX, float posY, int fontSize, Color color)
|
||||
Rectangle TextInSpace(Rectangle box, float textH, float textW, float margin, bool topOrBottom, bool leftOrRigth)
|
||||
{
|
||||
DrawTextEx(fontTtf, text, (Vector2){ posX, posY }, fontSize, 1, color);
|
||||
float br = box.width / box.height;
|
||||
float tr = textW / textH;
|
||||
|
||||
Rectangle ret = {0, 0, 0, 0};
|
||||
|
||||
float hm = box.height * margin;
|
||||
float wm = box.width * margin;
|
||||
|
||||
ret.height = box.height - hm;
|
||||
ret.width = box.width - wm;
|
||||
|
||||
if (br < tr)
|
||||
{
|
||||
// bolj kvadrat izracunaj visino iz sirine
|
||||
ret.height = ret.width / tr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// bolj podolgovat izracunaj sirino iz visine
|
||||
ret.width = ret.height * tr;
|
||||
}
|
||||
|
||||
if (topOrBottom)
|
||||
{
|
||||
ret.y = box.y + hm;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret.y = box.y + box.height - hm - ret.height;
|
||||
}
|
||||
|
||||
if (leftOrRigth)
|
||||
{
|
||||
ret.x = box.x + wm;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret.x = box.x + box.width - wm - ret.width;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Dimentions for font size 20
|
||||
// DISLIKE 83
|
||||
// LIKE 46
|
||||
// GEN 9999: 999/999 -> 200
|
||||
constexpr float textMargin = 0.02f;
|
||||
|
||||
void App::init(int screenWidth, int screenHeight)
|
||||
{
|
||||
fontTtf = LoadFontEx("res/CascadiaCode.ttf", 32, 0, 0);
|
||||
SetTextLineSpacing(16);
|
||||
this->screenWidth = screenWidth;
|
||||
this->screenHeight = screenHeight;
|
||||
this->canvas.init(screenWidth);
|
||||
|
||||
// int s = MeasureText("GEN 9999: 999/999", 20);
|
||||
// TraceLog(LOG_INFO, "%d", s);
|
||||
|
||||
canvasTexure = LoadRenderTexture(screenWidth, screenWidth);
|
||||
for (size_t i = 0; i < canvasTexure.size(); i++)
|
||||
{
|
||||
canvasTexure[i] = LoadRenderTexture(screenWidth, screenWidth);
|
||||
}
|
||||
|
||||
DnaStore::load(&manager);
|
||||
simil = Similarity::calc_similarity(manager.vector);
|
||||
upTex(Liked::tbd);
|
||||
while (!canvas.tick(canvasTexure))
|
||||
while (!canvas.tick(canvasTexure[TOP]))
|
||||
{
|
||||
// wait to finish drawing
|
||||
}
|
||||
pos = 1 - pos;
|
||||
upTex(Liked::tbd);
|
||||
while (!canvas.tick(canvasTexure[TOP]))
|
||||
{
|
||||
// wait to finish drawing
|
||||
}
|
||||
pos = 1 - pos;
|
||||
|
||||
float posY = (screenHeight - screenWidth) / 2.0f;
|
||||
|
||||
destA = {0, posY, (float)screenWidth, (float)screenWidth};
|
||||
likedTextBox = TextInSpace({0,
|
||||
0,
|
||||
(float)screenWidth / 2.0f,
|
||||
posY},
|
||||
20.0f, 83.0f, textMargin, false, true);
|
||||
|
||||
genTextBox = TextInSpace({0,
|
||||
posY + screenWidth,
|
||||
(float)screenWidth,
|
||||
posY},
|
||||
20.0f, 200.0f, textMargin, true, true);
|
||||
|
||||
simTextBox = TextInSpace({(float)screenWidth / 2.0f,
|
||||
likedTextBox.y,
|
||||
(float)screenWidth / 2.0f,
|
||||
likedTextBox.height},
|
||||
20.0f, 60.0f, textMargin, false, false);
|
||||
|
||||
destB = {0, posY, (float)screenWidth, (float)screenWidth};
|
||||
destA = destB;
|
||||
|
||||
float recPosX = screenWidth * 0.3f;
|
||||
disLikeBox = {0, posY, (float)recPosX, (float)screenWidth};
|
||||
likeBox = {screenWidth - recPosX, posY, (float)recPosX, (float)screenWidth};
|
||||
|
||||
if(!DnaStore::ping()){
|
||||
appColor = RED;
|
||||
}
|
||||
}
|
||||
|
||||
void App::upTex(Liked liked)
|
||||
{
|
||||
if (liked != Liked::tbd)
|
||||
{
|
||||
unit.liked = liked;
|
||||
bool ng = DnaManager::like(unit, &manager);
|
||||
unit[TOP].liked = liked;
|
||||
bool ng = DnaManager::like(unit[TOP], &manager);
|
||||
|
||||
if (ng)
|
||||
{
|
||||
DnaStore::saveGen(&manager);
|
||||
DnaManager::newGen(&manager);
|
||||
DnaStore::saveVec(&manager);
|
||||
simil = Similarity::calc_similarity(manager.vector);
|
||||
}
|
||||
DnaStore::saveData(&manager);
|
||||
}
|
||||
unit = DnaManager::next(&manager);
|
||||
if (unit.dna != nullptr)
|
||||
unit[TOP] = DnaManager::next(&manager);
|
||||
if (unit[TOP].dna != nullptr)
|
||||
{
|
||||
canvas.newGen(canvasTexure, unit.dna);
|
||||
canvas.newGen(canvasTexure[TOP], unit[TOP].dna);
|
||||
return;
|
||||
}
|
||||
|
||||
BeginTextureMode(canvasTexure);
|
||||
BeginTextureMode(canvasTexure[TOP]);
|
||||
ClearBackground(BLACK);
|
||||
DrawText("NEXT GEN", 10, 10, screenWidth/10, WHITE);
|
||||
EndTextureMode();
|
||||
}
|
||||
|
||||
void App::update(){}
|
||||
void App::update()
|
||||
{
|
||||
bool isDone = canvas.tick(canvasTexure[BOTTOM]);
|
||||
Vector2 mousePosition = GetMousePosition();
|
||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
|
||||
{
|
||||
mouseStart = mousePosition;
|
||||
validHit = CheckCollisionPointRec(mouseStart, destA);
|
||||
len = Vector2Distance(mouseStart, {destB.x, destB.y});
|
||||
ofset = std::atan2(destB.x - mouseStart.x, destB.y - mouseStart.y);
|
||||
}
|
||||
|
||||
enum class Rend_type{
|
||||
every_frame,
|
||||
in_one_frame,
|
||||
over_frames,
|
||||
};
|
||||
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT) && validHit)
|
||||
{
|
||||
float dist = mousePosition.x - mouseStart.x;
|
||||
float l = dist / screenWidth;
|
||||
rotation = Lerp(45.0f, -45.0f, (l + 1) / 2);
|
||||
|
||||
constexpr Rend_type rend_type = Rend_type::over_frames;
|
||||
float angle = ((rotation)*PI) / 180.0f;
|
||||
angle += ofset;
|
||||
Vector2 newCenter = {.x = len * std::sin(angle), .y = len * std::cos(angle)};
|
||||
|
||||
destA.x = newCenter.x + mousePosition.x;
|
||||
destA.y = newCenter.y + mousePosition.y;
|
||||
|
||||
if (CheckCollisionPointRec(mousePosition, disLikeBox))
|
||||
{
|
||||
topLiked = Liked::no;
|
||||
}
|
||||
else if (CheckCollisionPointRec(mousePosition, likeBox))
|
||||
{
|
||||
topLiked = Liked::yes;
|
||||
}
|
||||
else
|
||||
{
|
||||
topLiked = Liked::tbd;
|
||||
}
|
||||
}
|
||||
|
||||
if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT) && validHit)
|
||||
{
|
||||
if (isDone)
|
||||
{
|
||||
if (topLiked != Liked::tbd)
|
||||
{
|
||||
upTex(topLiked);
|
||||
pos = 1 - pos; // switch bottom and top
|
||||
}
|
||||
}
|
||||
rotation = 0.0f;
|
||||
destA = destB;
|
||||
topLiked = Liked::tbd;
|
||||
}
|
||||
}
|
||||
|
||||
void App::draw()
|
||||
{
|
||||
if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT))
|
||||
{
|
||||
TraceLog(LOG_INFO, "CLICK");
|
||||
upTex(Liked::yes);
|
||||
if constexpr (rend_type == Rend_type::in_one_frame){
|
||||
while (!canvas.tick(canvasTexure))
|
||||
{
|
||||
// wait to finish drawing
|
||||
}
|
||||
}
|
||||
}
|
||||
if constexpr (rend_type == Rend_type::over_frames){
|
||||
canvas.tick(canvasTexure);
|
||||
}
|
||||
ClearBackground(BLUE);
|
||||
|
||||
int fps = GetFPS();
|
||||
const char* fpstext = TextFormat("%04d FPS", fps);
|
||||
DrawTextB(fpstext, 10, 10, 36, BLACK);
|
||||
const char* ctext = TextFormat("%04ld Circles", canvas.tree.circles);
|
||||
DrawTextB(ctext, 10, 50, 36, BLACK);
|
||||
ClearBackground(appColor);
|
||||
|
||||
Rectangle source = {0, 0, (float)screenWidth, (float)-screenWidth};
|
||||
Vector2 origin = {0.0f, 0.0f};
|
||||
if constexpr (rend_type == Rend_type::every_frame){
|
||||
canvas.newGen(canvasTexure, unit.dna);
|
||||
while (!canvas.tick(canvasTexure))
|
||||
|
||||
DrawTexturePro(canvasTexure[BOTTOM].texture, source, destB, origin, 0.0f, WHITE);
|
||||
|
||||
DrawTexturePro(canvasTexure[TOP].texture, source, destA, origin, 360 - rotation, WHITE);
|
||||
|
||||
const char *textGen = TextFormat("GEN %d: %d / %d", manager.generation, unit[TOP].index + 1, NUM_PER_GEN);
|
||||
DrawText(textGen, genTextBox.x, genTextBox.y, genTextBox.height, BLACK);
|
||||
const char *textProc = TextFormat("%.1f%%", simil);
|
||||
DrawText(textProc, simTextBox.x, simTextBox.y, simTextBox.height, BLACK);
|
||||
switch (topLiked)
|
||||
{
|
||||
// wait to finish drawing
|
||||
case Liked::yes:
|
||||
DrawText("LIKED", likedTextBox.x, likedTextBox.y, likedTextBox.height, BLACK);
|
||||
break;
|
||||
case Liked::no:
|
||||
DrawText("DISLIKE", likedTextBox.x, likedTextBox.y, likedTextBox.height, BLACK);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
DrawTexturePro(canvasTexure.texture, source, destA, origin, 360, WHITE);
|
||||
}
|
||||
|
||||
void App::deinit()
|
||||
{
|
||||
UnloadRenderTexture(canvasTexure);
|
||||
UnloadFont(fontTtf);
|
||||
for (size_t i = 0; i < canvasTexure.size(); i++)
|
||||
{
|
||||
UnloadRenderTexture(canvasTexure[i]);
|
||||
}
|
||||
canvas.deinit();
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
#include <raylib.h>
|
||||
#include "App.hpp"
|
||||
#include "timing.hpp"
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
#include <emscripten/emscripten.h>
|
||||
@@ -8,14 +7,12 @@
|
||||
|
||||
static App app;
|
||||
|
||||
Timer t;
|
||||
void UpdateDrawFrame()
|
||||
{
|
||||
t.reset_and_start();
|
||||
app.update();
|
||||
BeginDrawing();
|
||||
app.draw();
|
||||
EndDrawing();
|
||||
t.stop_and_print("to draw frame");
|
||||
}
|
||||
|
||||
int main(void)
|
||||
@@ -37,7 +34,7 @@ int main(void)
|
||||
#if defined(PLATFORM_WEB)
|
||||
emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
|
||||
#else
|
||||
// SetTargetFPS(60);
|
||||
SetTargetFPS(60);
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
UpdateDrawFrame();
|
||||
|
||||
147
random/slike.cpp
147
random/slike.cpp
@@ -1,147 +0,0 @@
|
||||
#include <raylib.h>
|
||||
#include <raymath.h>
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
|
||||
Vector2 newPoint(Vector2 start, float len, float angleD){
|
||||
float angleR = (angleD * PI) / 180; // radian
|
||||
return {start.x + len * cos(angleR), start.y - len * sin(angleR)};
|
||||
}
|
||||
|
||||
void drawBranch(Vector2 startV, Vector2 endV, Color startC, Color endC, int startR, int endR){
|
||||
float fstep = 0.05;
|
||||
for (float i = 0; i < 1.05; i += fstep)
|
||||
{
|
||||
Vector2 point = Vector2Lerp(startV, endV, i);
|
||||
Color color = ColorLerp(startC, endC, i);
|
||||
int size = Lerp(startR, endR, i);
|
||||
DrawCircleV(point, size, color);
|
||||
}
|
||||
}
|
||||
|
||||
constexpr float screenWidth = 800;
|
||||
constexpr float screenHeight = 800;
|
||||
|
||||
constexpr float len = 300;
|
||||
constexpr float angleD = 100;
|
||||
constexpr Vector2 start = {screenWidth / 2, screenHeight - 100};
|
||||
constexpr float radius = 20;
|
||||
constexpr float radiusS = 80;
|
||||
constexpr float radiusE = 60;
|
||||
constexpr Color colorS = RED;
|
||||
constexpr Color colorE = GREEN;
|
||||
|
||||
typedef void (*slika)();
|
||||
|
||||
int idx = 0;
|
||||
|
||||
std::vector<slika> v_slik = {
|
||||
[]()
|
||||
{
|
||||
DrawCircleV(start, radius, BLACK);
|
||||
},
|
||||
|
||||
[]()
|
||||
{
|
||||
Vector2 end = {start.x, start.y - len};
|
||||
DrawCircleV(start, radius, BLACK);
|
||||
DrawLineEx(start, end, 10, BLACK);
|
||||
},
|
||||
|
||||
[]()
|
||||
{
|
||||
Vector2 end = newPoint(start, len, angleD);
|
||||
DrawCircleV(start, radius, BLACK);
|
||||
DrawLineEx(start, end, 10, BLACK);
|
||||
DrawCircleV(end, radius, BLACK);
|
||||
DrawCircleSectorLines(start, len / 3, 360 - angleD, 360, 30, BLACK);
|
||||
},
|
||||
|
||||
[]()
|
||||
{
|
||||
Vector2 end = newPoint(start, len, angleD);
|
||||
DrawCircleV(start, radius, BLACK);
|
||||
DrawLineEx(start, end, 10, BLACK);
|
||||
DrawCircleV(end, radius, BLACK);
|
||||
DrawCircleLinesV(start, radiusS, BLACK);
|
||||
DrawCircleLinesV(end, radiusE, BLACK);
|
||||
},
|
||||
|
||||
[]()
|
||||
{
|
||||
Vector2 end = newPoint(start, len, angleD);
|
||||
DrawLineEx(start, end, 10, BLACK);
|
||||
DrawCircleV(start, radiusS, colorS);
|
||||
DrawCircleV(end, radiusE, colorE);
|
||||
},
|
||||
|
||||
[]()
|
||||
{
|
||||
Vector2 end = newPoint(start, len, angleD);
|
||||
drawBranch(start, end, colorS, colorE, radiusS, radiusE);
|
||||
},
|
||||
|
||||
[]()
|
||||
{
|
||||
Vector2 p = newPoint(start, len, angleD);
|
||||
drawBranch(start, p, colorS, colorE, radiusS, radiusE);
|
||||
Vector2 p1 = newPoint(p, len, 135);
|
||||
Vector2 p2 = newPoint(p, len, 90);
|
||||
Vector2 p3 = newPoint(p, len, 45);
|
||||
DrawLineEx(p, p1, 10, BLACK);
|
||||
DrawLineEx(p, p2, 10, BLACK);
|
||||
DrawLineEx(p, p3, 10, BLACK);
|
||||
DrawCircleV(p, radius, BLACK);
|
||||
DrawCircleV(p1, radius, BLACK);
|
||||
DrawCircleV(p2, radius, BLACK);
|
||||
DrawCircleV(p3, radius, BLACK);
|
||||
},
|
||||
|
||||
[]()
|
||||
{
|
||||
Vector2 p = newPoint(start, len, angleD);
|
||||
drawBranch(start, p, colorS, colorE, radiusS, radiusE);
|
||||
Vector2 p1 = newPoint(p, len, 135);
|
||||
Vector2 p2 = newPoint(p, len, 90);
|
||||
Vector2 p3 = newPoint(p, len, 45);
|
||||
drawBranch(p, p1, colorE, BLUE, radiusE, 50);
|
||||
drawBranch(p, p2, colorE, ORANGE, radiusE, 50);
|
||||
drawBranch(p, p3, colorE, PURPLE, radiusE, 50);
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
InitWindow(screenWidth, screenHeight, "Slike");
|
||||
SetTargetFPS(60);
|
||||
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
BeginDrawing();
|
||||
if (IsKeyPressed(KEY_S))
|
||||
{
|
||||
TakeScreenshot(TextFormat("slika%.2d.png", idx));
|
||||
}
|
||||
if (IsKeyPressed(KEY_N))
|
||||
{
|
||||
idx++;
|
||||
if (idx >= v_slik.size())
|
||||
idx = v_slik.size() - 1;
|
||||
}
|
||||
if (IsKeyPressed(KEY_P))
|
||||
{
|
||||
idx--;
|
||||
if (idx < 0)
|
||||
idx = 0;
|
||||
}
|
||||
ClearBackground(WHITE);
|
||||
v_slik[idx]();
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
|
||||
CloseWindow();
|
||||
return 0;
|
||||
}
|
||||
@@ -13,6 +13,7 @@ public:
|
||||
void newGen(RenderTexture2D &target, Dna *dna);
|
||||
bool tick(RenderTexture2D &target);
|
||||
|
||||
private:
|
||||
BackGround backGround;
|
||||
Tree tree;
|
||||
};
|
||||
|
||||
@@ -23,7 +23,6 @@ public:
|
||||
void init(int size);
|
||||
void draw(Dna *dna);
|
||||
bool tick();
|
||||
uint64_t circles;
|
||||
|
||||
private:
|
||||
Dna *m_dna;
|
||||
@@ -35,8 +34,7 @@ private:
|
||||
|
||||
void calculateBranch();
|
||||
|
||||
void drawBranch_rlTriangle(Vector2 startPoint, Vector2 endPoint, Color startColor, Color endColor, float startThickness, float endThickness, float length);
|
||||
void drawBranch_circles(Vector2 startPoint, Vector2 endPoint, Color startColor, Color endColor, float startThickness, float endThickness, float length);
|
||||
void drawBranch(Vector2 startPoint, Vector2 endPoint, Color startColor, Color endColor, float startThickness, float endThickness);
|
||||
inline size_t getNumOfBranches(int dep);
|
||||
inline Color getStartColor(DrawArgs &arg);
|
||||
inline Color getEndColor(int dep, Color &start);
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
|
||||
#include <chrono>
|
||||
|
||||
|
||||
struct Timer
|
||||
{
|
||||
std::chrono::steady_clock::time_point start_t;
|
||||
std::chrono::steady_clock::time_point end_t;
|
||||
std::chrono::nanoseconds dur;
|
||||
void start();
|
||||
void stop();
|
||||
void reset();
|
||||
void print(const char * str);
|
||||
void stop_and_print(const char * str);
|
||||
void reset_and_start();
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
|
||||
#include "canvas/BackGround.hpp"
|
||||
#include "canvas/BackGroundColors.hpp"
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "canvas/Canvas.hpp"
|
||||
#include "timing.hpp"
|
||||
|
||||
void Canvas::init(int size)
|
||||
{
|
||||
@@ -7,13 +6,8 @@ void Canvas::init(int size)
|
||||
tree.init(size);
|
||||
}
|
||||
|
||||
bool finished = false;
|
||||
Timer timer;
|
||||
void Canvas::newGen(RenderTexture2D &target, Dna *dna)
|
||||
{
|
||||
|
||||
finished = false;
|
||||
timer.reset_and_start();
|
||||
BeginTextureMode(target);
|
||||
ClearBackground(WHITE);
|
||||
|
||||
@@ -21,20 +15,13 @@ void Canvas::newGen(RenderTexture2D &target, Dna *dna)
|
||||
tree.draw(dna);
|
||||
|
||||
EndTextureMode();
|
||||
timer.stop();
|
||||
}
|
||||
|
||||
bool Canvas::tick(RenderTexture2D &target)
|
||||
{
|
||||
timer.start();
|
||||
BeginTextureMode(target);
|
||||
bool ret = tree.tick();
|
||||
EndTextureMode();
|
||||
timer.stop();
|
||||
if(ret && !finished){
|
||||
finished = true;
|
||||
timer.print("to draw canvas");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
#include <cmath>
|
||||
|
||||
#include "canvas/Tree.hpp"
|
||||
#include "timing.hpp"
|
||||
|
||||
#include <raylib.h>
|
||||
#include <raymath.h>
|
||||
#include <rlgl.h>
|
||||
|
||||
#define ITER_PER_FRAME 10000
|
||||
#define ITER_PER_FRAME 5000
|
||||
|
||||
constexpr int maxColorChange = 15;
|
||||
constexpr int minColorChange = -15;
|
||||
@@ -47,23 +46,22 @@ void Tree::init(int size)
|
||||
|
||||
void Tree::draw(Dna *dna)
|
||||
{
|
||||
circles = 0;
|
||||
m_dna = dna;
|
||||
branchSeed = dna->branchSeed;
|
||||
drawCalls.push_back({start, 180.0f, 0});
|
||||
tick();
|
||||
}
|
||||
|
||||
bool Tree::tick()
|
||||
{
|
||||
using namespace std::chrono;
|
||||
auto start = steady_clock::now();
|
||||
nanoseconds dur = 0us;
|
||||
while (!drawCalls.empty() && dur < 14ms)
|
||||
size_t i = 0;
|
||||
while (!drawCalls.empty())
|
||||
{
|
||||
calculateBranch();
|
||||
drawCalls.pop_front();
|
||||
auto end = steady_clock::now();
|
||||
dur = end - start;
|
||||
i++;
|
||||
if (i >= ITER_PER_FRAME)
|
||||
break;
|
||||
}
|
||||
|
||||
return drawCalls.empty();
|
||||
@@ -85,12 +83,19 @@ void Tree::calculateBranch()
|
||||
|
||||
int sizeStart = getStartSize(arg);
|
||||
int sizeEnd = getEndSize(arg, sizeStart);
|
||||
float fstep = 1.0 / ((length / sizeStart) * 2.0f);
|
||||
|
||||
Color colorStart = getStartColor(arg);
|
||||
Color colorEnd = getEndColor(arg.dep, colorStart);
|
||||
// drawBranch_rlTriangle(arg.start, end, colorStart, colorEnd, sizeStart, sizeEnd, length);
|
||||
drawBranch_circles(arg.start, end, colorStart, colorEnd, sizeStart, sizeEnd, length);
|
||||
// DrawLineEx(arg.start, end, sizeStart, colorStart);
|
||||
// drawBranch(arg.start, end, colorStart, colorEnd, sizeStart, sizeEnd);
|
||||
for (float i = 0; i < 1; i += fstep)
|
||||
{
|
||||
Vector2 point = Vector2Lerp(arg.start, end, i);
|
||||
Color color = ColorLerp(colorStart, colorEnd, i);
|
||||
int size = Lerp(sizeStart, sizeEnd, i);
|
||||
DrawCircleV(point, size, color);
|
||||
// DrawTextureEx(texBunny, point,0, ((float)size) / texBunny.height, color);
|
||||
}
|
||||
|
||||
// add more branches to draw
|
||||
|
||||
@@ -109,7 +114,6 @@ void Tree::calculateBranch()
|
||||
|
||||
inline size_t Tree::getNumOfBranches(int dep)
|
||||
{
|
||||
return 3;
|
||||
if (m_dna->branches[dep].branchCount < 128)
|
||||
return 2;
|
||||
else
|
||||
@@ -159,7 +163,7 @@ inline int Tree::getStartSize(DrawArgs &arg)
|
||||
float mixLevel = m_dna->branches[arg.dep].sizeLevel / 255.0f;
|
||||
size = std::lerp(size, sizes[MAX_DEPTH - arg.dep - 1], mixLevel);
|
||||
|
||||
//if (size < 1)
|
||||
if (size < 1)
|
||||
size = 1;
|
||||
return size;
|
||||
}
|
||||
@@ -169,7 +173,7 @@ inline int Tree::getEndSize(DrawArgs &arg, int start)
|
||||
int size = Remap(m_dna->branches[arg.dep].sizeChange, 0, 255, MinSizeChange, maxSizeChange);
|
||||
size += start;
|
||||
|
||||
//if (size < 1)
|
||||
if (size < 1)
|
||||
size = 1;
|
||||
return size;
|
||||
}
|
||||
@@ -177,9 +181,9 @@ inline int Tree::getEndSize(DrawArgs &arg, int start)
|
||||
inline float Tree::getLength(DrawArgs &arg)
|
||||
{
|
||||
float lenght = lengths[arg.dep];
|
||||
float lenghtRatio = Remap(255, 0, 255, 0.5f, 1.3f);
|
||||
float lenghtRatio = Remap(m_dna->branches[arg.dep].length, 0, 255, 0.5f, 1.3f);
|
||||
lenght *= lenghtRatio;
|
||||
float lenghtVar = Remap(255, 0, 255, -0.15f, 0.15f);
|
||||
float lenghtVar = Remap(m_dna->branches[arg.dep].lengthVar, 0, 255, -0.15f, 0.15f);
|
||||
lenght += lenght * lenghtVar * mrand::getFloat(&branchSeed);
|
||||
if (lenght < 1)
|
||||
lenght = 1;
|
||||
@@ -195,28 +199,15 @@ inline float Tree::getAngleVar(DrawArgs &arg)
|
||||
return angleVar;
|
||||
}
|
||||
|
||||
void Tree::drawBranch_circles(Vector2 startPoint, Vector2 endPoint, Color startColor, Color endColor, float startThickness, float endThickness, float length)
|
||||
void Tree::drawBranch(Vector2 startPoint, Vector2 endPoint, Color startColor, Color endColor, float startThickness, float endThickness)
|
||||
{
|
||||
|
||||
float fstep = 1.0 / ((length / startThickness) * 2.0f);
|
||||
for (float i = 0; i < 1; i += fstep)
|
||||
{
|
||||
Vector2 point = Vector2Lerp(startPoint, endPoint, i);
|
||||
Color color = ColorLerp(startColor, endColor, i);
|
||||
int size = Lerp(startThickness, endThickness, i);
|
||||
DrawCircleV(point, size, color);
|
||||
circles++;
|
||||
}
|
||||
}
|
||||
|
||||
void Tree::drawBranch_rlTriangle(Vector2 startPoint, Vector2 endPoint, Color startColor, Color endColor, float startThickness, float endThickness, float length)
|
||||
{
|
||||
DrawCircleV(startPoint, startThickness, startColor);
|
||||
DrawCircleV(endPoint, endThickness, endColor);
|
||||
// Calculate the direction vector from startPoint to endPoint
|
||||
Vector2 direction = {endPoint.x - startPoint.x, endPoint.y - startPoint.y};
|
||||
|
||||
// Normalize the direction vector
|
||||
float length = sqrtf(direction.x * direction.x + direction.y * direction.y);
|
||||
if (length == 0)
|
||||
length = 1; // Avoid division by zero
|
||||
Vector2 normalizedDir = {direction.x / length, direction.y / length};
|
||||
|
||||
// Calculate the perpendicular vector (rotate 90 degrees)
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
#include <raylib.h>
|
||||
#include <chrono>
|
||||
#include "timing.hpp"
|
||||
|
||||
using namespace std::chrono;
|
||||
|
||||
void Timer::start()
|
||||
{
|
||||
start_t = std::chrono::steady_clock::now();
|
||||
}
|
||||
|
||||
void Timer::stop()
|
||||
{
|
||||
end_t = std::chrono::steady_clock::now();
|
||||
dur += end_t - start_t;
|
||||
}
|
||||
|
||||
void Timer::reset()
|
||||
{
|
||||
dur = 0ns;
|
||||
}
|
||||
|
||||
void Timer::print(const char * str)
|
||||
{
|
||||
auto s = std::chrono::duration_cast<std::chrono::milliseconds>(dur);
|
||||
if (s > 1000us)
|
||||
{
|
||||
TraceLog(LOG_INFO, "%ld ms %s", s.count(), str);
|
||||
}
|
||||
}
|
||||
|
||||
void Timer::stop_and_print(const char *str)
|
||||
{
|
||||
stop();
|
||||
print(str);
|
||||
}
|
||||
|
||||
void Timer::reset_and_start()
|
||||
{
|
||||
reset();
|
||||
start();
|
||||
}
|
||||
@@ -136,11 +136,7 @@ namespace Similarity
|
||||
}
|
||||
else if (f == &Similarity::hamming_distance)
|
||||
{
|
||||
return "hamming_distance";
|
||||
}
|
||||
else if (f == &Similarity::hamming_distance_without_seeds)
|
||||
{
|
||||
return "hamming_distance_without_seeds";
|
||||
return "hamming";
|
||||
}
|
||||
else if (f == &Similarity::levenshtein_distance)
|
||||
{
|
||||
@@ -148,7 +144,7 @@ namespace Similarity
|
||||
}
|
||||
else
|
||||
{
|
||||
return "unknown nameofFunc";
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,6 +167,7 @@ namespace Similarity
|
||||
|
||||
const auto int_ms = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
|
||||
|
||||
TraceLog(LOG_INFO, "%s, %d", nameofFunc(f), int_ms);
|
||||
return average_similarity * 100.0f;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ public:
|
||||
private:
|
||||
bool showSelection;
|
||||
bool showStats;
|
||||
bool saveToFile;
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *get_gen_num;
|
||||
std::vector<int64_t> ids;
|
||||
|
||||
@@ -110,7 +110,7 @@ void Vapp::update()
|
||||
stageOfDrawing = DrawingStage::save;
|
||||
break;
|
||||
case DrawingStage::save:
|
||||
if(saveToFile) drawToFile();
|
||||
drawToFile();
|
||||
stageOfDrawing = DrawingStage::done;
|
||||
break;
|
||||
case DrawingStage::done:
|
||||
@@ -140,10 +140,6 @@ void Vapp::draw()
|
||||
{
|
||||
setUpTable();
|
||||
}
|
||||
if(ImGui::MenuItem("Save to File", nullptr, saveToFile, true))
|
||||
{
|
||||
saveToFile = !saveToFile;
|
||||
}
|
||||
ImGui::EndMainMenuBar();
|
||||
}
|
||||
|
||||
@@ -339,10 +335,10 @@ void Vapp::setUpTable()
|
||||
}
|
||||
|
||||
sql::reset(get_gen_stmt);
|
||||
if(saveToFile)
|
||||
{
|
||||
|
||||
int64_t id = ids[selected_id_index];
|
||||
const char* buff = TextFormat("%ld.txt", id);
|
||||
char buff[50];
|
||||
sprintf(buff, "%ld.txt", id);
|
||||
std::ofstream file(buff);
|
||||
|
||||
file << "| index | euclidean_distance | cosine_similarity | cosine_similarity_int | hamming_distance | levenshtein_distance | dot_minmax |\n";
|
||||
@@ -360,7 +356,6 @@ void Vapp::setUpTable()
|
||||
file << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sql::finalize(get_gen_stmt);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user