Compare commits
18 Commits
e020784f4f
...
test_sqlit
| Author | SHA1 | Date | |
|---|---|---|---|
| 6794dada92 | |||
| 6ff4a66551 | |||
| 45f73c721e | |||
| e99bd33985 | |||
| 40b2f963a6 | |||
| cc00586bc9 | |||
| d7ea0b99ac | |||
| 0dedb2d6b9 | |||
| d41f11a333 | |||
| 53c333d46d | |||
| 30980423eb | |||
| 31e8f302ac | |||
| 1516ad63cb | |||
| 4fa74d0cfb | |||
| 64364bfefd | |||
| 2cd8ef5558 | |||
| 266d250881 | |||
| 1994e7ccb1 |
@@ -8,7 +8,11 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
|
|||||||
# set(CMAKE_VERBOSE_MAKEFILE ON)
|
# set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||||
add_compile_options(-ggdb)
|
add_compile_options(-ggdb)
|
||||||
|
|
||||||
include_directories(external/include/)
|
include_directories(
|
||||||
|
external/include
|
||||||
|
shared/inc
|
||||||
|
)
|
||||||
|
|
||||||
link_libraries(
|
link_libraries(
|
||||||
${CMAKE_SOURCE_DIR}/external/libimgui.a
|
${CMAKE_SOURCE_DIR}/external/libimgui.a
|
||||||
${CMAKE_SOURCE_DIR}/external/libraylib.a
|
${CMAKE_SOURCE_DIR}/external/libraylib.a
|
||||||
@@ -18,52 +22,44 @@ link_libraries(
|
|||||||
m
|
m
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_library(shared STATIC
|
||||||
|
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/TcpSocket.cpp
|
||||||
|
shared/src/sql.cpp
|
||||||
|
shared/src/values/DnaDB.cpp
|
||||||
|
)
|
||||||
|
|
||||||
add_executable(app
|
add_executable(app
|
||||||
app/src/main.cpp
|
app/src/main.cpp
|
||||||
app/src/App.cpp
|
app/src/App.cpp
|
||||||
app/src/DnaStore.cpp
|
app/src/DnaStore.cpp
|
||||||
app/src/sys.cpp
|
app/src/sys.cpp
|
||||||
shared/src/canvas/BackGround.cpp
|
|
||||||
shared/src/canvas/BackGroundColors.cpp
|
|
||||||
shared/src/canvas/Canvas.cpp
|
|
||||||
shared/src/canvas/Circle.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/TcpSocket.cpp
|
|
||||||
)
|
)
|
||||||
# Add include directories
|
target_include_directories(app PRIVATE app/inc)
|
||||||
target_include_directories(app PRIVATE app/inc shared/inc )
|
target_link_libraries(app PRIVATE shared)
|
||||||
|
|
||||||
add_executable(server
|
add_executable(server
|
||||||
server/src/server.cpp
|
server/src/server.cpp
|
||||||
server/src/checker.cpp
|
server/src/checker.cpp
|
||||||
|
|
||||||
shared/src/sql.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)
|
||||||
target_include_directories(server PRIVATE server/inc shared/inc)
|
target_link_libraries(server PRIVATE shared)
|
||||||
|
|
||||||
add_executable(view
|
add_executable(view
|
||||||
view/src/main.cpp
|
view/src/main.cpp
|
||||||
view/src/Vapp.cpp
|
view/src/Vapp.cpp
|
||||||
shared/src/canvas/BackGround.cpp
|
|
||||||
shared/src/canvas/BackGroundColors.cpp
|
|
||||||
shared/src/canvas/Canvas.cpp
|
|
||||||
shared/src/canvas/Circle.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
|
|
||||||
)
|
)
|
||||||
# Add include directories
|
target_include_directories(view PRIVATE view/inc)
|
||||||
target_include_directories(view PRIVATE view/inc shared/inc)
|
target_link_libraries(view PRIVATE shared)
|
||||||
|
|
||||||
|
add_executable(slike
|
||||||
|
random/slike.cpp
|
||||||
|
)
|
||||||
|
target_link_libraries(slike PRIVATE shared)
|
||||||
14
Readme.md
14
Readme.md
@@ -1,10 +1,3 @@
|
|||||||
# how to build
|
|
||||||
```
|
|
||||||
g++ build.cpp -o build
|
|
||||||
./build
|
|
||||||
or
|
|
||||||
./build run
|
|
||||||
```
|
|
||||||
|
|
||||||
# Code style
|
# Code style
|
||||||
|
|
||||||
@@ -31,10 +24,3 @@ or
|
|||||||
- Std
|
- Std
|
||||||
- local ( form inc dir )
|
- local ( form inc dir )
|
||||||
- external raylib
|
- external raylib
|
||||||
|
|
||||||
|
|
||||||
## Generate shader .h files
|
|
||||||
```
|
|
||||||
xxd -i shaders/sun_100.fs > inc/sunShader.hpp
|
|
||||||
xxd -i shaders/sun_330.fs >> inc/sunShader.hpp
|
|
||||||
```
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include "canvas/Canvas.hpp"
|
#include "canvas/Canvas.hpp"
|
||||||
#include "DnaStore.hpp"
|
#include "DnaStore.hpp"
|
||||||
|
|
||||||
class App
|
class App
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -42,4 +43,6 @@ private:
|
|||||||
Rectangle genTextBox;
|
Rectangle genTextBox;
|
||||||
Rectangle simTextBox;
|
Rectangle simTextBox;
|
||||||
float simil = 100.0f;
|
float simil = 100.0f;
|
||||||
|
|
||||||
|
Color appColor = BLUE;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,9 +2,12 @@
|
|||||||
|
|
||||||
namespace DnaStore
|
namespace DnaStore
|
||||||
{
|
{
|
||||||
|
void init();
|
||||||
|
void deinit();
|
||||||
void load(DnaManagerData *data);
|
void load(DnaManagerData *data);
|
||||||
void saveData(DnaManagerData *data);
|
void saveData(DnaManagerData *data);
|
||||||
void saveVec(DnaManagerData *data);
|
void saveVec(DnaManagerData *data);
|
||||||
void saveGen(DnaManagerData *data);
|
void saveGen(DnaManagerData *data);
|
||||||
void sync();
|
void sync();
|
||||||
|
bool ping();
|
||||||
} // namespace DnaStore
|
} // namespace DnaStore
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ void App::init(int screenWidth, int screenHeight)
|
|||||||
this->screenWidth = screenWidth;
|
this->screenWidth = screenWidth;
|
||||||
this->screenHeight = screenHeight;
|
this->screenHeight = screenHeight;
|
||||||
this->canvas.init(screenWidth);
|
this->canvas.init(screenWidth);
|
||||||
|
DnaStore::init();
|
||||||
// int s = MeasureText("GEN 9999: 999/999", 20);
|
// int s = MeasureText("GEN 9999: 999/999", 20);
|
||||||
// TraceLog(LOG_INFO, "%d", s);
|
// TraceLog(LOG_INFO, "%d", s);
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ void App::init(int screenWidth, int screenHeight)
|
|||||||
}
|
}
|
||||||
|
|
||||||
DnaStore::load(&manager);
|
DnaStore::load(&manager);
|
||||||
simil = Similarity::calc_similarity(manager.vector, Similarity::hamming_distance);
|
simil = Similarity::calc_similarity(manager.vector);
|
||||||
upTex(Liked::tbd);
|
upTex(Liked::tbd);
|
||||||
while (!canvas.tick(canvasTexure[TOP]))
|
while (!canvas.tick(canvasTexure[TOP]))
|
||||||
{
|
{
|
||||||
@@ -114,6 +114,10 @@ void App::init(int screenWidth, int screenHeight)
|
|||||||
float recPosX = screenWidth * 0.3f;
|
float recPosX = screenWidth * 0.3f;
|
||||||
disLikeBox = {0, posY, (float)recPosX, (float)screenWidth};
|
disLikeBox = {0, posY, (float)recPosX, (float)screenWidth};
|
||||||
likeBox = {screenWidth - recPosX, posY, (float)recPosX, (float)screenWidth};
|
likeBox = {screenWidth - recPosX, posY, (float)recPosX, (float)screenWidth};
|
||||||
|
|
||||||
|
if(!DnaStore::ping()){
|
||||||
|
appColor = RED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::upTex(Liked liked)
|
void App::upTex(Liked liked)
|
||||||
@@ -128,7 +132,7 @@ void App::upTex(Liked liked)
|
|||||||
DnaStore::saveGen(&manager);
|
DnaStore::saveGen(&manager);
|
||||||
DnaManager::newGen(&manager);
|
DnaManager::newGen(&manager);
|
||||||
DnaStore::saveVec(&manager);
|
DnaStore::saveVec(&manager);
|
||||||
simil = Similarity::calc_similarity(manager.vector, Similarity::hamming_distance);
|
simil = Similarity::calc_similarity(manager.vector);
|
||||||
}
|
}
|
||||||
DnaStore::saveData(&manager);
|
DnaStore::saveData(&manager);
|
||||||
}
|
}
|
||||||
@@ -141,7 +145,7 @@ void App::upTex(Liked liked)
|
|||||||
|
|
||||||
BeginTextureMode(canvasTexure[TOP]);
|
BeginTextureMode(canvasTexure[TOP]);
|
||||||
ClearBackground(BLACK);
|
ClearBackground(BLACK);
|
||||||
DrawText("NEXT GEN", 10, 10, 20, WHITE);
|
DrawText("NEXT GEN", 10, 10, screenWidth/10, WHITE);
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,7 +206,7 @@ void App::update()
|
|||||||
|
|
||||||
void App::draw()
|
void App::draw()
|
||||||
{
|
{
|
||||||
ClearBackground(BLUE);
|
ClearBackground(appColor);
|
||||||
|
|
||||||
Rectangle source = {0, 0, (float)screenWidth, (float)-screenWidth};
|
Rectangle source = {0, 0, (float)screenWidth, (float)-screenWidth};
|
||||||
Vector2 origin = {0.0f, 0.0f};
|
Vector2 origin = {0.0f, 0.0f};
|
||||||
@@ -235,4 +239,5 @@ void App::deinit()
|
|||||||
UnloadRenderTexture(canvasTexure[i]);
|
UnloadRenderTexture(canvasTexure[i]);
|
||||||
}
|
}
|
||||||
canvas.deinit();
|
canvas.deinit();
|
||||||
|
DnaStore::deinit();
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "sys.hpp"
|
#include "sys.hpp"
|
||||||
#include "DnaStore.hpp"
|
#include "DnaStore.hpp"
|
||||||
#include "TcpSocket.hpp"
|
#include "TcpSocket.hpp"
|
||||||
|
#include "values/DnaDB.hpp"
|
||||||
|
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
|
|
||||||
@@ -16,19 +17,31 @@
|
|||||||
#define DATA_FILE_NAME "DATA.bin"
|
#define DATA_FILE_NAME "DATA.bin"
|
||||||
#define VECTOR_FILE_NAME "VECTOR.bin"
|
#define VECTOR_FILE_NAME "VECTOR.bin"
|
||||||
#define GEN_FILE_PATTRN "gen/%04d.bin"
|
#define GEN_FILE_PATTRN "gen/%04d.bin"
|
||||||
|
#define HOST_NAME "localhost"
|
||||||
|
#define DB_NAME "data.db"
|
||||||
|
|
||||||
|
DnaDB dnaDB;
|
||||||
|
|
||||||
|
void DnaStore::init(){
|
||||||
|
const char* filename = sys::transformFilePath(DB_NAME);
|
||||||
|
dnaDB.init(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DnaStore::deinit(){
|
||||||
|
dnaDB.deinit();
|
||||||
|
}
|
||||||
|
|
||||||
void DnaStore::load(DnaManagerData *data)
|
void DnaStore::load(DnaManagerData *data)
|
||||||
{
|
{
|
||||||
const char *dir = sys::transformFilePath("gen");
|
const char *dir = sys::transformFilePath("gen");
|
||||||
std::filesystem::create_directory(dir);
|
std::filesystem::create_directory(dir);
|
||||||
if (sys::fileExists(ID_FILE_NAME))
|
|
||||||
{
|
std::vector<int64_t> ids = dnaDB.getUserIds();
|
||||||
sys::loadDataFromFile(ID_FILE_NAME, &data->id, sizeof(int64_t));
|
if(!ids.empty()){
|
||||||
}
|
data->id = ids[0];
|
||||||
else
|
}else{
|
||||||
{
|
|
||||||
data->id = time(nullptr);
|
data->id = time(nullptr);
|
||||||
sys::saveDataToFile(ID_FILE_NAME, &data->id, sizeof(int64_t));
|
dnaDB.insertUser(data->id, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sys::fileExists(DATA_FILE_NAME))
|
if (sys::fileExists(DATA_FILE_NAME))
|
||||||
@@ -149,24 +162,38 @@ void DnaStore::saveGen(DnaManagerData *data)
|
|||||||
sync();
|
sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
void client(std::string prefix);
|
void client(std::string_view prefix);
|
||||||
|
|
||||||
void DnaStore::sync()
|
void DnaStore::sync()
|
||||||
{
|
{
|
||||||
const char *prefix = sys::transformFilePath("");
|
const char *prefix = sys::transformFilePath("");
|
||||||
std::string prefixs = prefix;
|
std::string_view prefixs = prefix;
|
||||||
|
|
||||||
std::thread t(client, prefixs);
|
std::thread t(client, prefixs);
|
||||||
t.detach();
|
t.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
void client(std::string prefix)
|
bool DnaStore::ping(){
|
||||||
|
int sock = TcpSocket::connectt(HOST_NAME, keyPort);
|
||||||
|
if (sock < 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t header = 0;
|
||||||
|
TcpSocket::recvt(sock, &header, sizeof(header));
|
||||||
|
TcpSocket::closet(sock);
|
||||||
|
|
||||||
|
return header == StartHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
void client(std::string_view prefix)
|
||||||
{
|
{
|
||||||
constexpr int extra_buff = 22; // len of 2**31 -> 2147483648 plus the pattern size
|
constexpr int extra_buff = 22; // len of 2**31 -> 2147483648 plus the pattern size
|
||||||
std::string buffer;
|
std::string buffer;
|
||||||
buffer.resize(prefix.size() + extra_buff);
|
buffer.resize(prefix.size() + extra_buff);
|
||||||
|
|
||||||
int sock = TcpSocket::connectt("petrovv.com", keyPort);
|
int sock = TcpSocket::connectt(HOST_NAME, keyPort);
|
||||||
if (sock < 0)
|
if (sock < 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -177,7 +204,7 @@ void client(std::string prefix)
|
|||||||
|
|
||||||
TcpSocket::closet(sock);
|
TcpSocket::closet(sock);
|
||||||
|
|
||||||
sock = TcpSocket::connectt("petrovv.com", serverPort);
|
sock = TcpSocket::connectt(HOST_NAME, serverPort);
|
||||||
|
|
||||||
if (sock < 0)
|
if (sock < 0)
|
||||||
{
|
{
|
||||||
@@ -185,7 +212,7 @@ void client(std::string prefix)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(PLATFORM_ANDROID)
|
#if defined(PLATFORM_ANDROID)
|
||||||
int ret = sprintf(buffer.data(), "%s/" ID_FILE_NAME, prefix.c_str());
|
int ret = sprintf(buffer.data(), "%s/" ID_FILE_NAME, prefix.data());
|
||||||
#else
|
#else
|
||||||
int ret = sprintf(buffer.data(), ID_FILE_NAME);
|
int ret = sprintf(buffer.data(), ID_FILE_NAME);
|
||||||
#endif
|
#endif
|
||||||
@@ -220,7 +247,7 @@ void client(std::string prefix)
|
|||||||
needed_gen = message.data;
|
needed_gen = message.data;
|
||||||
|
|
||||||
#if defined(PLATFORM_ANDROID)
|
#if defined(PLATFORM_ANDROID)
|
||||||
int ret = sprintf(buffer.data(), "%s/" GEN_FILE_PATTRN, prefix.c_str(), needed_gen);
|
int ret = sprintf(buffer.data(), "%s/" GEN_FILE_PATTRN, prefix.data(), needed_gen);
|
||||||
#else
|
#else
|
||||||
int ret = sprintf(buffer.data(), GEN_FILE_PATTRN, needed_gen);
|
int ret = sprintf(buffer.data(), GEN_FILE_PATTRN, needed_gen);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
77
random/build_sytem/build.cpp
Normal file
77
random/build_sytem/build.cpp
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
|
||||||
|
#define EXT_LINK
|
||||||
|
#define EXT_INC
|
||||||
|
#include "build.hpp"
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
|
std::vector<std::string> LINK = {"raylib/lib/libraylib.a"};
|
||||||
|
|
||||||
|
std::vector<std::string> RAYINCLUDE = {"-Iraylib/include"};
|
||||||
|
std::filesystem::path RAYLIB_DIR = "raylib";
|
||||||
|
|
||||||
|
bool build = false;
|
||||||
|
bool clear = false;
|
||||||
|
bool run = false;
|
||||||
|
|
||||||
|
int main(int argc, char const *argv[])
|
||||||
|
{
|
||||||
|
if (rebuild_my_self(__FILE__, argc, argv))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
for (int i = 1; i < argc; ++i)
|
||||||
|
{
|
||||||
|
if (!std::strcmp(argv[i], "opt"))
|
||||||
|
opt_flags = "-O3";
|
||||||
|
|
||||||
|
if (!std::strcmp(argv[i], "build"))
|
||||||
|
build = true;
|
||||||
|
|
||||||
|
if (!std::strcmp(argv[i], "run"))
|
||||||
|
run = true;
|
||||||
|
|
||||||
|
if (!std::strcmp(argv[i], "clear"))
|
||||||
|
{
|
||||||
|
clear_all_build();
|
||||||
|
clear = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clear && !build)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!std::filesystem::is_directory(RAYLIB_DIR))
|
||||||
|
{
|
||||||
|
command = {"wget", "https://github.com/raysan5/raylib/releases/download/5.5/raylib-5.5_linux_amd64.tar.gz"};
|
||||||
|
run_command(command);
|
||||||
|
command = {"tar", "-xzvf", "raylib-5.5_linux_amd64.tar.gz"};
|
||||||
|
run_command(command);
|
||||||
|
std::filesystem::rename("raylib-5.5_linux_amd64", "raylib");
|
||||||
|
std::filesystem::remove_all("raylib-5.5_linux_amd64.tar.gz");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!std::filesystem::is_directory(RAYLIB_DIR))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
std::filesystem::create_directory(OBJ_DIR);
|
||||||
|
|
||||||
|
int res = compile_src_dir(RAYINCLUDE);
|
||||||
|
switch (res)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
compile_obj_dir(LINK);
|
||||||
|
break;
|
||||||
|
case -1:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!std::filesystem::exists(BUILD_FILE))
|
||||||
|
compile_obj_dir(LINK);
|
||||||
|
|
||||||
|
if (run)
|
||||||
|
{
|
||||||
|
run_main();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
408
random/build_sytem/build.hpp
Normal file
408
random/build_sytem/build.hpp
Normal file
@@ -0,0 +1,408 @@
|
|||||||
|
#include <cstdio>
|
||||||
|
#include <cstring>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <list>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
|
// #define EXT_ARGS
|
||||||
|
// #define EXT_LINK
|
||||||
|
// #define EXT_INC
|
||||||
|
// #define EXT_OBJ
|
||||||
|
// #define Werror
|
||||||
|
// #define Wextra
|
||||||
|
|
||||||
|
std::filesystem::path OBJ_DIR = "obj";
|
||||||
|
std::filesystem::path INC_DIR = "inc";
|
||||||
|
std::filesystem::path SRC_DIR = "src";
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
std::filesystem::path BUILD_FILE = "main.exe";
|
||||||
|
std::string cpp_compiler = "zig c++";
|
||||||
|
std::string c_compiler = "zig cc";
|
||||||
|
#else
|
||||||
|
std::filesystem::path BUILD_FILE = "main";
|
||||||
|
std::string cpp_compiler = "g++";
|
||||||
|
std::string c_compiler = "gcc";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::string opt_flags = "-ggdb";
|
||||||
|
std::vector<std::string> command;
|
||||||
|
|
||||||
|
enum class Color
|
||||||
|
{
|
||||||
|
black,
|
||||||
|
red,
|
||||||
|
green,
|
||||||
|
yellow,
|
||||||
|
blue,
|
||||||
|
purple,
|
||||||
|
cyan,
|
||||||
|
white,
|
||||||
|
reset,
|
||||||
|
};
|
||||||
|
|
||||||
|
void pick_color(Color color)
|
||||||
|
{
|
||||||
|
switch (color)
|
||||||
|
{
|
||||||
|
case Color::black:
|
||||||
|
printf("\033[0;30m");
|
||||||
|
break;
|
||||||
|
case Color::red:
|
||||||
|
printf("\033[0;31m");
|
||||||
|
break;
|
||||||
|
case Color::green:
|
||||||
|
printf("\033[0;32m");
|
||||||
|
break;
|
||||||
|
case Color::yellow:
|
||||||
|
printf("\033[0;33m");
|
||||||
|
break;
|
||||||
|
case Color::blue:
|
||||||
|
printf("\033[0;34m");
|
||||||
|
break;
|
||||||
|
case Color::purple:
|
||||||
|
printf("\033[0;35m");
|
||||||
|
break;
|
||||||
|
case Color::cyan:
|
||||||
|
printf("\033[0;36m");
|
||||||
|
break;
|
||||||
|
case Color::white:
|
||||||
|
printf("\033[0;37m");
|
||||||
|
break;
|
||||||
|
case Color::reset:
|
||||||
|
printf("\033[0m");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_command(std::vector<std::string> &arguments)
|
||||||
|
{
|
||||||
|
pick_color(Color::cyan);
|
||||||
|
for (auto &&i : arguments)
|
||||||
|
{
|
||||||
|
printf("%s ", i.c_str());
|
||||||
|
}
|
||||||
|
pick_color(Color::white);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool run_command(std::vector<std::string> &arguments)
|
||||||
|
{
|
||||||
|
print_command(arguments);
|
||||||
|
std::string command = "";
|
||||||
|
|
||||||
|
for (auto &&i : arguments)
|
||||||
|
{
|
||||||
|
command += " " + i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::system(command.c_str()) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool check_if_rebuild(const std::filesystem::path &org_path, const std::filesystem::path &new_path)
|
||||||
|
{
|
||||||
|
if (!std::filesystem::exists(org_path))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!std::filesystem::exists(new_path))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
auto file_time_one = std::filesystem::last_write_time(org_path);
|
||||||
|
auto file_time_two = std::filesystem::last_write_time(new_path);
|
||||||
|
return file_time_one > file_time_two;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool try_remove(std::filesystem::path path)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
std::filesystem::remove(path);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (const std::exception &e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool rebuild_my_self(std::filesystem::path src_path, int argc, const char **exec_path)
|
||||||
|
{
|
||||||
|
std::filesystem::path exec = exec_path[0];
|
||||||
|
|
||||||
|
try_remove("old_build");
|
||||||
|
|
||||||
|
if (!check_if_rebuild(src_path, exec) && !check_if_rebuild(__FILE__, exec))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
std::filesystem::rename(exec, "old_build");
|
||||||
|
|
||||||
|
std::vector<std::string> input;
|
||||||
|
|
||||||
|
for (int i = 0; i < argc; ++i)
|
||||||
|
input.push_back(exec_path[i]);
|
||||||
|
|
||||||
|
std::vector<std::string> comand = {cpp_compiler, src_path.string(), "-o", exec_path[0], "-ggdb"};
|
||||||
|
if (!run_command(comand))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
printf("rebuild\n");
|
||||||
|
|
||||||
|
if (!run_command(input))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct all_in_directory
|
||||||
|
{
|
||||||
|
std::vector<std::filesystem::path> files;
|
||||||
|
std::vector<std::filesystem::path> dirs;
|
||||||
|
};
|
||||||
|
|
||||||
|
all_in_directory get_all_files_in_dir(std::filesystem::path directory_path)
|
||||||
|
{
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
|
all_in_directory dir;
|
||||||
|
if (!fs::is_directory(directory_path))
|
||||||
|
return dir;
|
||||||
|
|
||||||
|
std::list<fs::path> dirs;
|
||||||
|
dirs.push_back(directory_path);
|
||||||
|
dir.dirs.push_back(directory_path);
|
||||||
|
|
||||||
|
while (!dirs.empty())
|
||||||
|
{
|
||||||
|
for (const auto &entry : fs::directory_iterator(dirs.front()))
|
||||||
|
{
|
||||||
|
// Check if the entry is a regular file
|
||||||
|
if (fs::is_regular_file(entry))
|
||||||
|
{
|
||||||
|
dir.files.push_back(entry.path());
|
||||||
|
}
|
||||||
|
// Check if the entry is a directory
|
||||||
|
else if (fs::is_directory(entry))
|
||||||
|
{
|
||||||
|
dirs.push_back(entry.path());
|
||||||
|
dir.dirs.push_back(entry.path());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dirs.pop_front();
|
||||||
|
}
|
||||||
|
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> get_includes(const std::filesystem::path &path)
|
||||||
|
{
|
||||||
|
std::vector<std::string> ret;
|
||||||
|
|
||||||
|
std::ifstream ifs(path);
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
while (std::getline(ifs, line))
|
||||||
|
{
|
||||||
|
if (line.empty())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (line[0] != '#')
|
||||||
|
break;
|
||||||
|
|
||||||
|
// if include ends with " its my .h
|
||||||
|
if (line[line.size() - 1] == '\"')
|
||||||
|
{
|
||||||
|
// magic num 10 is lenOf(#include ") so start at 10 until end of
|
||||||
|
// line witch is len of line - 10 - 1 of cahar "
|
||||||
|
ret.push_back(line.substr(10, line.length() - 10 - 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear_all_build()
|
||||||
|
{
|
||||||
|
std::filesystem::remove_all(OBJ_DIR);
|
||||||
|
std::filesystem::remove_all(BUILD_FILE);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef EXT_INC
|
||||||
|
int compile_src_dir(std::vector<std::string> ext_inc)
|
||||||
|
#else
|
||||||
|
int compile_src_dir()
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
all_in_directory src_dir = get_all_files_in_dir(SRC_DIR);
|
||||||
|
all_in_directory obj_dir;
|
||||||
|
|
||||||
|
for (auto &&i : src_dir.dirs)
|
||||||
|
{
|
||||||
|
std::filesystem::create_directory(OBJ_DIR / i);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unordered_set<std::string> modified_heders;
|
||||||
|
all_in_directory inc_dir = get_all_files_in_dir(INC_DIR);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < inc_dir.files.size(); i++)
|
||||||
|
{
|
||||||
|
if (check_if_rebuild(inc_dir.files[i], BUILD_FILE))
|
||||||
|
{
|
||||||
|
std::string heder = inc_dir.files[i].string().substr(4);
|
||||||
|
modified_heders.insert(heder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
command.clear();
|
||||||
|
command.push_back(cpp_compiler);
|
||||||
|
command.push_back("-c");
|
||||||
|
int src_loc = command.size();
|
||||||
|
command.push_back("");
|
||||||
|
command.push_back("-o");
|
||||||
|
int obj_loc = command.size();
|
||||||
|
command.push_back("");
|
||||||
|
command.push_back(opt_flags);
|
||||||
|
|
||||||
|
#ifdef EXT_INC
|
||||||
|
command.insert(command.end(), ext_inc.begin(), ext_inc.end());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
command.push_back("-I" + INC_DIR.string());
|
||||||
|
command.push_back("-std=c++20");
|
||||||
|
command.push_back("-Wall");
|
||||||
|
#ifdef Wextra
|
||||||
|
command.push_back("-Wextra");
|
||||||
|
#endif
|
||||||
|
#ifdef Werror
|
||||||
|
command.push_back("-Werror");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int build = 0;
|
||||||
|
for (auto &&i : src_dir.files)
|
||||||
|
{
|
||||||
|
std::filesystem::path tmp = i;
|
||||||
|
std::filesystem::path out = OBJ_DIR / tmp.replace_extension(".o");
|
||||||
|
bool reb = false;
|
||||||
|
// check if .cpp changed
|
||||||
|
if (check_if_rebuild(i, out))
|
||||||
|
reb = true;
|
||||||
|
|
||||||
|
// if .cpp didnt change check include files changed
|
||||||
|
if (!reb)
|
||||||
|
{
|
||||||
|
std::vector<std::string> incudes = get_includes(i);
|
||||||
|
for (auto &&j : incudes)
|
||||||
|
{
|
||||||
|
if (modified_heders.find(j) != modified_heders.end())
|
||||||
|
{
|
||||||
|
reb = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reb)
|
||||||
|
{
|
||||||
|
command[src_loc] = i.string();
|
||||||
|
command[obj_loc] = out.string();
|
||||||
|
if (!run_command(command))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
build = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return build;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(EXT_LINK)
|
||||||
|
bool compile_obj_dir(std::vector<std::string> ext_link)
|
||||||
|
#else
|
||||||
|
bool compile_obj_dir()
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
all_in_directory obj_dir = get_all_files_in_dir(OBJ_DIR);
|
||||||
|
|
||||||
|
command.clear();
|
||||||
|
command.push_back(cpp_compiler);
|
||||||
|
|
||||||
|
for (auto &&i : obj_dir.files)
|
||||||
|
{
|
||||||
|
command.push_back(i.string());
|
||||||
|
}
|
||||||
|
|
||||||
|
command.push_back(opt_flags);
|
||||||
|
command.push_back("-o");
|
||||||
|
command.push_back(BUILD_FILE.string());
|
||||||
|
|
||||||
|
#if defined(EXT_LINK)
|
||||||
|
command.insert(command.end(), ext_link.begin(), ext_link.end());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return run_command(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(EXT_OBJ) && defined(EXT_INC)
|
||||||
|
void build_as_one(std::vector<std::string> ext_obj, std::vector<std::string> ext_inc)
|
||||||
|
#elif defined(EXT_OBJ)
|
||||||
|
void build_as_one(std::vector<std::string> ext_obj)
|
||||||
|
#elif defined(EXT_INC)
|
||||||
|
void build_as_one(std::vector<std::string> ext_inc)
|
||||||
|
#else
|
||||||
|
void build_as_one()
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
all_in_directory src_dir = get_all_files_in_dir(SRC_DIR);
|
||||||
|
|
||||||
|
command.clear();
|
||||||
|
command.push_back(cpp_compiler);
|
||||||
|
command.push_back("-o");
|
||||||
|
command.push_back(BUILD_FILE.string());
|
||||||
|
command.push_back(opt_flags);
|
||||||
|
|
||||||
|
#ifdef EXT_INC
|
||||||
|
command.insert(command.end(), ext_inc.begin(), ext_inc.end());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
command.push_back("-I" + INC_DIR.string());
|
||||||
|
command.push_back("-std=c++20");
|
||||||
|
command.push_back("-Wall");
|
||||||
|
#ifdef Wextra
|
||||||
|
command.push_back("-Wextra");
|
||||||
|
#endif
|
||||||
|
#ifdef Werror
|
||||||
|
command.push_back("-Werror");
|
||||||
|
#endif
|
||||||
|
for (auto &&i : src_dir.files)
|
||||||
|
{
|
||||||
|
command.push_back(i.string());
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef EXT_OBJ
|
||||||
|
command.insert(command.end(), ext_obj.begin(), ext_obj.end());
|
||||||
|
#endif
|
||||||
|
run_command(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef EXT_ARGS
|
||||||
|
bool run_main(std::vector<std::string> ext_args)
|
||||||
|
#else
|
||||||
|
bool run_main()
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
command.clear();
|
||||||
|
#ifndef _WIN32
|
||||||
|
command.push_back("./" + BUILD_FILE.string());
|
||||||
|
#else
|
||||||
|
command.push_back(BUILD_FILE.string());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef EXT_ARGS
|
||||||
|
command.insert(command.end(), ext_args.begin(), ext_args.end());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return run_command(command);
|
||||||
|
}
|
||||||
68
random/rotation_in_just_math.cpp
Normal file
68
random/rotation_in_just_math.cpp
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
|
||||||
|
#include <raymath.h>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
int main(int argc, char const *argv[])
|
||||||
|
{
|
||||||
|
std::printf("\n\n\n");
|
||||||
|
|
||||||
|
Vector2 mousePosition = {.x = 15, .y = 10};
|
||||||
|
Vector2 mouseStart;
|
||||||
|
Vector2 orgPosition = {.x = 0, .y = 10};
|
||||||
|
float screenWidth = 30;
|
||||||
|
|
||||||
|
mouseStart = mousePosition;
|
||||||
|
|
||||||
|
std::printf("MouseStart x:%f, y:%f\n", mouseStart.x, mouseStart.y);
|
||||||
|
std::printf("orgPosition x:%f, y:%f\n", orgPosition.x, orgPosition.y);
|
||||||
|
|
||||||
|
// distance betwen corner of image and mouse startPoint
|
||||||
|
float len = Vector2Distance(mouseStart, orgPosition);
|
||||||
|
std::printf("len %f\n", len);
|
||||||
|
// angle in rad betwen mouse and image corner
|
||||||
|
|
||||||
|
float atan2x = orgPosition.x - mouseStart.x;
|
||||||
|
float atan2y = orgPosition.y - mouseStart.y;
|
||||||
|
std::printf("atan2 x:%f, y:%f\n", atan2x, atan2y);
|
||||||
|
|
||||||
|
float angleOfset = std::atan2( orgPosition.y - mouseStart.y, orgPosition.x - mouseStart.x);
|
||||||
|
std::printf("angleOffset %f\n", angleOfset);
|
||||||
|
|
||||||
|
|
||||||
|
mousePosition = {.x = 20, .y = 10};
|
||||||
|
|
||||||
|
// get distance that mouse has moved from original press location
|
||||||
|
// can be positive or negative if mouse start on right side and
|
||||||
|
// end on left it will be 0 - 100 so -100 dist
|
||||||
|
float dist = mousePosition.x - mouseStart.x;
|
||||||
|
printf("dist: %f\n", dist);
|
||||||
|
// this value can get from -1 to 1 based on if we swipe left or right
|
||||||
|
float l = dist / screenWidth;
|
||||||
|
printf("l: %f\n", l);
|
||||||
|
// first convert range of -1 to 1 to 0 to 1
|
||||||
|
// then change to degres from 45 to -45
|
||||||
|
float rotation = Lerp(45.0f, -45.0f, (l + 1) / 2);
|
||||||
|
printf("rotation: %f\n", rotation);
|
||||||
|
// convert to radians
|
||||||
|
float angle = ((rotation)*PI) / 180.0f;
|
||||||
|
printf("angle: %f\n", angle);
|
||||||
|
angle += angleOfset;
|
||||||
|
|
||||||
|
printf("angle + angleOfser: %f\n", angle);
|
||||||
|
|
||||||
|
// vector betwen image corrner and mouse
|
||||||
|
Vector2 newCornerVec = {.x = len * std::cos(angle), .y = len * std::sin(angle)};
|
||||||
|
|
||||||
|
printf("newCornerVec x: %f, y:%f \n", newCornerVec.x, newCornerVec.y);
|
||||||
|
|
||||||
|
// get global vector where to draw image
|
||||||
|
|
||||||
|
Vector2 newPosition;
|
||||||
|
newPosition.x = newCornerVec.x + mousePosition.x;
|
||||||
|
newPosition.y = newCornerVec.y + mousePosition.y;
|
||||||
|
printf("New position x: %f, y:%f \n", newPosition.x, newPosition.y);
|
||||||
|
printf("Draw image at this angle %f\n", rotation + 90);
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
147
random/slike.cpp
Normal file
147
random/slike.cpp
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
#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;
|
||||||
|
}
|
||||||
@@ -6,14 +6,91 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <mutex>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
// use pthread rw_lock to lock db so you can safy clone .db file
|
// use pthread rw_lock to lock db so you can safy clone .db file
|
||||||
|
|
||||||
|
class BlockedList
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
std::mutex m;
|
||||||
|
|
||||||
|
sqlite3 *db;
|
||||||
|
sqlite3_stmt *sel_stmt;
|
||||||
|
sqlite3_stmt *ins_stmt;
|
||||||
|
sqlite3_stmt *upd_stmt;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void init()
|
||||||
|
{
|
||||||
|
int rc = sql::open(DB_NAME, &db);
|
||||||
|
if (rc)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Can't open database: %s\n", sql::errmsg(db));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sql::prepare_v2(db, get_warnings, -1, &sel_stmt, NULL);
|
||||||
|
sql::prepare_v2(db, insert_warnings, -1, &ins_stmt, NULL);
|
||||||
|
sql::prepare_v2(db, set_warnings, -1, &upd_stmt, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isBlocked(uint32_t id)
|
||||||
|
{
|
||||||
|
std::scoped_lock lock(m);
|
||||||
|
sql::bind_int64(sel_stmt, 1, id);
|
||||||
|
int64_t found = 0;
|
||||||
|
if (sql::step(sel_stmt) == SQLITE_ROW)
|
||||||
|
{
|
||||||
|
int type = sql::column_type(sel_stmt, 0);
|
||||||
|
if (type != SQL_NULL)
|
||||||
|
found = sql::column_int64(sel_stmt, 0);
|
||||||
|
}
|
||||||
|
sql::reset(sel_stmt);
|
||||||
|
|
||||||
|
return found >= 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
void addWarning(uint32_t id)
|
||||||
|
{
|
||||||
|
std::scoped_lock lock(m);
|
||||||
|
sql::bind_int64(sel_stmt, 1, id);
|
||||||
|
int64_t found = 0;
|
||||||
|
int res = sql::step(sel_stmt);
|
||||||
|
if (res == SQLITE_ROW)
|
||||||
|
{
|
||||||
|
int type = sql::column_type(sel_stmt, 0);
|
||||||
|
if (type != SQL_NULL)
|
||||||
|
{
|
||||||
|
found = sql::column_int64(sel_stmt, 0);
|
||||||
|
}
|
||||||
|
sql::reset(sel_stmt);
|
||||||
|
}
|
||||||
|
else if (res == SQL_DONE)
|
||||||
|
{
|
||||||
|
sql::bind_int64(ins_stmt, 1, id);
|
||||||
|
sql::step(ins_stmt);
|
||||||
|
sql::reset(ins_stmt);
|
||||||
|
sql::reset(sel_stmt);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sql::bind_int64(upd_stmt, 1, found + 1);
|
||||||
|
sql::bind_int64(upd_stmt, 2, id);
|
||||||
|
sql::step(upd_stmt);
|
||||||
|
sql::reset(upd_stmt);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
BlockedList blockedList;
|
||||||
|
|
||||||
// When a new client connected:
|
// When a new client connected:
|
||||||
void call(int sock, sockaddr_in newSocketInfo)
|
void call(int sock, sockaddr_in newSocketInfo)
|
||||||
{
|
{
|
||||||
std::string add = TcpSocket::remoteAddress(newSocketInfo);
|
std::string add = TcpSocket::remoteAddress(newSocketInfo);
|
||||||
printf("new: %s\n", add.c_str());
|
//printf("new: %s\n", add.c_str());
|
||||||
int64_t conf, id;
|
int64_t conf, id;
|
||||||
Message message;
|
Message message;
|
||||||
|
|
||||||
@@ -22,15 +99,17 @@ void call(int sock, sockaddr_in newSocketInfo)
|
|||||||
|
|
||||||
if (conf != StartHeader)
|
if (conf != StartHeader)
|
||||||
{
|
{
|
||||||
printf("StartHeader ERROR\n");
|
//printf("StartHeader ERROR\n");
|
||||||
TcpSocket::closet(sock);
|
TcpSocket::closet(sock);
|
||||||
|
//blockedList.addWarning(newSocketInfo.sin_addr.s_addr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id == 0)
|
if (id == 0)
|
||||||
{
|
{
|
||||||
printf("ID ERROR\n");
|
//printf("ID ERROR\n");
|
||||||
TcpSocket::closet(sock);
|
TcpSocket::closet(sock);
|
||||||
|
//blockedList.addWarning(newSocketInfo.sin_addr.s_addr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,8 +130,6 @@ void call(int sock, sockaddr_in newSocketInfo)
|
|||||||
int64_t gen = 0;
|
int64_t gen = 0;
|
||||||
while (sql::step(max_gen_stmt) != SQL_DONE)
|
while (sql::step(max_gen_stmt) != SQL_DONE)
|
||||||
{
|
{
|
||||||
int num_cols = sql::column_count(max_gen_stmt);
|
|
||||||
|
|
||||||
int type = sql::column_type(max_gen_stmt, 0);
|
int type = sql::column_type(max_gen_stmt, 0);
|
||||||
|
|
||||||
if (type == SQL_NULL)
|
if (type == SQL_NULL)
|
||||||
@@ -67,12 +144,12 @@ void call(int sock, sockaddr_in newSocketInfo)
|
|||||||
|
|
||||||
sqlite3_stmt *insert_user_stmt;
|
sqlite3_stmt *insert_user_stmt;
|
||||||
sql::prepare_v2(db, insert_user_data, -1, &insert_user_stmt, NULL);
|
sql::prepare_v2(db, insert_user_data, -1, &insert_user_stmt, NULL);
|
||||||
|
// limit how many gen they can send so some cant just come to here and start sendding random data.
|
||||||
while (ok)
|
while (ok)
|
||||||
{
|
{
|
||||||
message.mess = Mess::REQ_SEND_GEN;
|
message.mess = Mess::REQ_SEND_GEN;
|
||||||
message.data = gen;
|
message.data = gen;
|
||||||
printf("requesting gen %ld\n", gen);
|
//printf("requesting gen %ld\n", gen);
|
||||||
TcpSocket::sendt(sock, &message, sizeof(Message));
|
TcpSocket::sendt(sock, &message, sizeof(Message));
|
||||||
TcpSocket::recvt(sock, &message, sizeof(Message));
|
TcpSocket::recvt(sock, &message, sizeof(Message));
|
||||||
|
|
||||||
@@ -110,7 +187,7 @@ void call(int sock, sockaddr_in newSocketInfo)
|
|||||||
sql::finalize(insert_liked_stmt);
|
sql::finalize(insert_liked_stmt);
|
||||||
|
|
||||||
sql::close(db);
|
sql::close(db);
|
||||||
printf("del\n");
|
//printf("del\n");
|
||||||
TcpSocket::closet(sock);
|
TcpSocket::closet(sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +210,8 @@ int main()
|
|||||||
{
|
{
|
||||||
sql::init();
|
sql::init();
|
||||||
sql::create_tables();
|
sql::create_tables();
|
||||||
std::thread t(checker);
|
blockedList.init();
|
||||||
|
//std::thread t(checker);
|
||||||
std::thread l(listen_key);
|
std::thread l(listen_key);
|
||||||
// Bind the server to a port.
|
// Bind the server to a port.
|
||||||
int err = TcpSocket::listent("0.0.0.0", serverPort, call);
|
int err = TcpSocket::listent("0.0.0.0", serverPort, call);
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
#version 100
|
|
||||||
|
|
||||||
precision mediump float;
|
|
||||||
|
|
||||||
varying vec2 fragTexCoord;
|
|
||||||
varying vec4 fragColor;
|
|
||||||
|
|
||||||
|
|
||||||
uniform vec3 color;
|
|
||||||
uniform float sun_radius;
|
|
||||||
uniform float start_transperency;
|
|
||||||
|
|
||||||
vec2 offset = vec2(1.0, 1.0);
|
|
||||||
float sun_end = 1.0;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
offset.x -= fragTexCoord.x * 2.0;
|
|
||||||
offset.y -= fragTexCoord.y * 2.0;
|
|
||||||
float radius = length(offset);
|
|
||||||
|
|
||||||
if(radius < sun_radius){
|
|
||||||
|
|
||||||
gl_FragColor = vec4(color, 1.0);
|
|
||||||
|
|
||||||
}else if(radius < sun_end){
|
|
||||||
|
|
||||||
float gradient = radius;
|
|
||||||
gradient -= sun_radius;
|
|
||||||
gradient = gradient / (sun_end - sun_radius) * start_transperency;
|
|
||||||
gl_FragColor = vec4(color, start_transperency - gradient);
|
|
||||||
|
|
||||||
}else{
|
|
||||||
gl_FragColor = vec4(color, 0.0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
#version 330
|
|
||||||
|
|
||||||
in vec2 fragTexCoord;
|
|
||||||
in vec4 fragColor;
|
|
||||||
out vec4 finalColor;
|
|
||||||
|
|
||||||
uniform vec3 color;
|
|
||||||
uniform float sun_radius;
|
|
||||||
uniform float start_transperency;
|
|
||||||
vec2 offset = vec2(1.0f, 1.0f);
|
|
||||||
float sun_end = 1.0f;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
offset.x -= fragTexCoord.x * 2;
|
|
||||||
offset.y -= fragTexCoord.y * 2;
|
|
||||||
float radius = length(offset);
|
|
||||||
if(radius < sun_radius){
|
|
||||||
finalColor = vec4(color, 1.0f);
|
|
||||||
}else if(radius < sun_end){
|
|
||||||
float gradient = radius;
|
|
||||||
gradient -= sun_radius;
|
|
||||||
gradient = gradient / (sun_end - sun_radius) * start_transperency;
|
|
||||||
finalColor = vec4(color, start_transperency - gradient);
|
|
||||||
}else{
|
|
||||||
finalColor = vec4(color, 0.0f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
#include <raylib.h>
|
|
||||||
|
|
||||||
class Circle
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static void init();
|
|
||||||
static void deinit();
|
|
||||||
static void setColor(Color color);
|
|
||||||
static void setSoftEdge(bool soft);
|
|
||||||
static void draw(float x, float y, float size);
|
|
||||||
|
|
||||||
Circle() = delete;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static const int sizeTexute = 250;
|
|
||||||
static RenderTexture2D target;
|
|
||||||
static Shader shader;
|
|
||||||
|
|
||||||
static float radius;
|
|
||||||
static float start_transperency;
|
|
||||||
static float c[3];
|
|
||||||
|
|
||||||
static int radius_loc;
|
|
||||||
static int start_transperency_loc;
|
|
||||||
static int colorLoc;
|
|
||||||
};
|
|
||||||
@@ -27,12 +27,14 @@ public:
|
|||||||
private:
|
private:
|
||||||
Dna *m_dna;
|
Dna *m_dna;
|
||||||
uint128 branchSeed;
|
uint128 branchSeed;
|
||||||
|
//Texture2D texBunny;
|
||||||
|
|
||||||
Vector2 start = {0};
|
Vector2 start = {0};
|
||||||
std::list<DrawArgs> drawCalls;
|
std::list<DrawArgs> drawCalls;
|
||||||
|
|
||||||
void drawBranch();
|
void calculateBranch();
|
||||||
|
|
||||||
|
void drawBranch(Vector2 startPoint, Vector2 endPoint, Color startColor, Color endColor, float startThickness, float endThickness);
|
||||||
inline size_t getNumOfBranches(int dep);
|
inline size_t getNumOfBranches(int dep);
|
||||||
inline Color getStartColor(DrawArgs &arg);
|
inline Color getStartColor(DrawArgs &arg);
|
||||||
inline Color getEndColor(int dep, Color &start);
|
inline Color getEndColor(int dep, Color &start);
|
||||||
|
|||||||
@@ -1,88 +0,0 @@
|
|||||||
const char *sun_shader_100 = "#version 100\n\
|
|
||||||
precision mediump float;\
|
|
||||||
varying vec2 fragTexCoord;\
|
|
||||||
varying vec4 fragColor;\
|
|
||||||
uniform vec3 color;\
|
|
||||||
uniform float sun_radius;\
|
|
||||||
uniform float start_transperency;\
|
|
||||||
vec2 offset = vec2(1.0, 1.0);\
|
|
||||||
float sun_end = 1.0;\
|
|
||||||
void main()\
|
|
||||||
{\
|
|
||||||
offset.x -= fragTexCoord.x * 2.0;\
|
|
||||||
offset.y -= fragTexCoord.y * 2.0;\
|
|
||||||
float radius = length(offset);\
|
|
||||||
if (radius < sun_radius) {\
|
|
||||||
gl_FragColor = vec4(color, 1.0);\
|
|
||||||
}\
|
|
||||||
else if (radius < sun_end) {\
|
|
||||||
float gradient = radius;\
|
|
||||||
gradient -= sun_radius;\
|
|
||||||
gradient = gradient / (sun_end - sun_radius) * start_transperency;\
|
|
||||||
gl_FragColor = vec4(color, start_transperency - gradient);\
|
|
||||||
}\
|
|
||||||
else {\
|
|
||||||
gl_FragColor = vec4(color, 0.0);\
|
|
||||||
}\
|
|
||||||
}";
|
|
||||||
|
|
||||||
unsigned char shaders_sun_330_fs[] = {
|
|
||||||
0x23, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x33, 0x33, 0x30,
|
|
||||||
0x0a, 0x0a, 0x69, 0x6e, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x66, 0x72,
|
|
||||||
0x61, 0x67, 0x54, 0x65, 0x78, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x3b, 0x0a,
|
|
||||||
0x69, 0x6e, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x66, 0x72, 0x61, 0x67,
|
|
||||||
0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x3b, 0x0a, 0x6f, 0x75, 0x74, 0x20, 0x76,
|
|
||||||
0x65, 0x63, 0x34, 0x20, 0x66, 0x69, 0x6e, 0x61, 0x6c, 0x43, 0x6f, 0x6c,
|
|
||||||
0x6f, 0x72, 0x3b, 0x0a, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d,
|
|
||||||
0x20, 0x76, 0x65, 0x63, 0x33, 0x20, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x3b,
|
|
||||||
0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x66, 0x6c, 0x6f,
|
|
||||||
0x61, 0x74, 0x20, 0x73, 0x75, 0x6e, 0x5f, 0x72, 0x61, 0x64, 0x69, 0x75,
|
|
||||||
0x73, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x66,
|
|
||||||
0x6c, 0x6f, 0x61, 0x74, 0x20, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x74,
|
|
||||||
0x72, 0x61, 0x6e, 0x73, 0x70, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x79, 0x3b,
|
|
||||||
0x0a, 0x76, 0x65, 0x63, 0x32, 0x20, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74,
|
|
||||||
0x20, 0x3d, 0x20, 0x76, 0x65, 0x63, 0x32, 0x28, 0x31, 0x2e, 0x30, 0x66,
|
|
||||||
0x2c, 0x20, 0x31, 0x2e, 0x30, 0x66, 0x29, 0x3b, 0x0a, 0x66, 0x6c, 0x6f,
|
|
||||||
0x61, 0x74, 0x20, 0x73, 0x75, 0x6e, 0x5f, 0x65, 0x6e, 0x64, 0x20, 0x3d,
|
|
||||||
0x20, 0x31, 0x2e, 0x30, 0x66, 0x3b, 0x0a, 0x0a, 0x76, 0x6f, 0x69, 0x64,
|
|
||||||
0x20, 0x6d, 0x61, 0x69, 0x6e, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20,
|
|
||||||
0x20, 0x20, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x2e, 0x78, 0x20, 0x2d,
|
|
||||||
0x3d, 0x20, 0x66, 0x72, 0x61, 0x67, 0x54, 0x65, 0x78, 0x43, 0x6f, 0x6f,
|
|
||||||
0x72, 0x64, 0x2e, 0x78, 0x20, 0x2a, 0x20, 0x32, 0x3b, 0x0a, 0x20, 0x20,
|
|
||||||
0x20, 0x20, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x2e, 0x79, 0x20, 0x2d,
|
|
||||||
0x3d, 0x20, 0x66, 0x72, 0x61, 0x67, 0x54, 0x65, 0x78, 0x43, 0x6f, 0x6f,
|
|
||||||
0x72, 0x64, 0x2e, 0x79, 0x20, 0x2a, 0x20, 0x32, 0x3b, 0x0a, 0x20, 0x20,
|
|
||||||
0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x72, 0x61, 0x64, 0x69,
|
|
||||||
0x75, 0x73, 0x20, 0x3d, 0x20, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x28,
|
|
||||||
0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x20,
|
|
||||||
0x20, 0x69, 0x66, 0x28, 0x72, 0x61, 0x64, 0x69, 0x75, 0x73, 0x20, 0x3c,
|
|
||||||
0x20, 0x73, 0x75, 0x6e, 0x5f, 0x72, 0x61, 0x64, 0x69, 0x75, 0x73, 0x29,
|
|
||||||
0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x66, 0x69,
|
|
||||||
0x6e, 0x61, 0x6c, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x76,
|
|
||||||
0x65, 0x63, 0x34, 0x28, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x2c, 0x20, 0x31,
|
|
||||||
0x2e, 0x30, 0x66, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x7d, 0x65,
|
|
||||||
0x6c, 0x73, 0x65, 0x20, 0x69, 0x66, 0x28, 0x72, 0x61, 0x64, 0x69, 0x75,
|
|
||||||
0x73, 0x20, 0x3c, 0x20, 0x73, 0x75, 0x6e, 0x5f, 0x65, 0x6e, 0x64, 0x29,
|
|
||||||
0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c,
|
|
||||||
0x6f, 0x61, 0x74, 0x20, 0x67, 0x72, 0x61, 0x64, 0x69, 0x65, 0x6e, 0x74,
|
|
||||||
0x20, 0x3d, 0x20, 0x72, 0x61, 0x64, 0x69, 0x75, 0x73, 0x3b, 0x0a, 0x20,
|
|
||||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x67, 0x72, 0x61, 0x64, 0x69,
|
|
||||||
0x65, 0x6e, 0x74, 0x20, 0x2d, 0x3d, 0x20, 0x73, 0x75, 0x6e, 0x5f, 0x72,
|
|
||||||
0x61, 0x64, 0x69, 0x75, 0x73, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20,
|
|
||||||
0x20, 0x20, 0x20, 0x67, 0x72, 0x61, 0x64, 0x69, 0x65, 0x6e, 0x74, 0x20,
|
|
||||||
0x3d, 0x20, 0x67, 0x72, 0x61, 0x64, 0x69, 0x65, 0x6e, 0x74, 0x20, 0x2f,
|
|
||||||
0x20, 0x28, 0x73, 0x75, 0x6e, 0x5f, 0x65, 0x6e, 0x64, 0x20, 0x2d, 0x20,
|
|
||||||
0x73, 0x75, 0x6e, 0x5f, 0x72, 0x61, 0x64, 0x69, 0x75, 0x73, 0x29, 0x20,
|
|
||||||
0x2a, 0x20, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x74, 0x72, 0x61, 0x6e,
|
|
||||||
0x73, 0x70, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x79, 0x3b, 0x0a, 0x20, 0x20,
|
|
||||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x66, 0x69, 0x6e, 0x61, 0x6c, 0x43,
|
|
||||||
0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x76, 0x65, 0x63, 0x34, 0x28,
|
|
||||||
0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x2c, 0x20, 0x73, 0x74, 0x61, 0x72, 0x74,
|
|
||||||
0x5f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x65, 0x72, 0x65, 0x6e, 0x63,
|
|
||||||
0x79, 0x20, 0x2d, 0x20, 0x67, 0x72, 0x61, 0x64, 0x69, 0x65, 0x6e, 0x74,
|
|
||||||
0x29, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x7d, 0x65, 0x6c, 0x73, 0x65,
|
|
||||||
0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x66, 0x69,
|
|
||||||
0x6e, 0x61, 0x6c, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x76,
|
|
||||||
0x65, 0x63, 0x34, 0x28, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x2c, 0x20, 0x30,
|
|
||||||
0x2e, 0x30, 0x66, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x7d, 0x0a,
|
|
||||||
0x7d, 0x0a};
|
|
||||||
@@ -4,6 +4,12 @@ const char create_like_table[] = "CREATE TABLE IF NOT EXISTS like_table ( ID INT
|
|||||||
|
|
||||||
const char create_user_table[] = "CREATE TABLE IF NOT EXISTS user_table ( ID INTEGER PRIMARY KEY, USER_ID INTEGER, GEN INTEGER, CHECKED INTEGER);";
|
const char create_user_table[] = "CREATE TABLE IF NOT EXISTS user_table ( ID INTEGER PRIMARY KEY, USER_ID INTEGER, GEN INTEGER, CHECKED INTEGER);";
|
||||||
|
|
||||||
|
const char create_blocked_ip_table[] = "CREATE TABLE IF NOT EXISTS blocked_ip_table ( ID INTEGER PRIMARY KEY, WARNINGS INTEGER);";
|
||||||
|
|
||||||
|
const char get_warnings[] = "SELECT WARNINGS FROM blocked_ip_table WHERE ID = ?;";
|
||||||
|
const char insert_warnings[] = "INSERT INTO blocked_ip_table (ID, WARNINGS) VALUES(?, 1);";
|
||||||
|
const char set_warnings[] = "UPDATE blocked_ip_table SET WARNINGS = ? WHERE ID = ?;";
|
||||||
|
|
||||||
const char max_gen[] = "SELECT MAX(GEN) FROM user_table WHERE USER_ID = ?;";
|
const char max_gen[] = "SELECT MAX(GEN) FROM user_table WHERE USER_ID = ?;";
|
||||||
|
|
||||||
const char insert_user_data[] = "INSERT INTO user_table (USER_ID, GEN, CHECKED) VALUES(?, ?, 0);";
|
const char insert_user_data[] = "INSERT INTO user_table (USER_ID, GEN, CHECKED) VALUES(?, ?, 0);";
|
||||||
@@ -27,8 +33,10 @@ constexpr char DB_NAME[] = "data.db";
|
|||||||
struct sqlite3;
|
struct sqlite3;
|
||||||
struct sqlite3_stmt;
|
struct sqlite3_stmt;
|
||||||
|
|
||||||
|
#define SQLITE_ROW 100 /* sqlite3_step() has another row ready */
|
||||||
#define SQL_DONE 101
|
#define SQL_DONE 101
|
||||||
#define SQL_NULL 5
|
#define SQL_NULL 5
|
||||||
|
#define SQLITE_OK 0
|
||||||
|
|
||||||
namespace sql
|
namespace sql
|
||||||
{
|
{
|
||||||
@@ -36,6 +44,7 @@ namespace sql
|
|||||||
void init();
|
void init();
|
||||||
void shutdown();
|
void shutdown();
|
||||||
int open(const char *filename, sqlite3 **ppDb);
|
int open(const char *filename, sqlite3 **ppDb);
|
||||||
|
int exec(sqlite3 *db, const char *sql, int (*callback)(void *, int, char **, char **), void *first_arg, char **errmsg);
|
||||||
int prepare_v2(sqlite3 *db, const char *zSql, int nByte, sqlite3_stmt **pStmt, const char **pzTail);
|
int prepare_v2(sqlite3 *db, const char *zSql, int nByte, sqlite3_stmt **pStmt, const char **pzTail);
|
||||||
int bind_int64(sqlite3_stmt *pStmt, int column, int64_t value);
|
int bind_int64(sqlite3_stmt *pStmt, int column, int64_t value);
|
||||||
int step(sqlite3_stmt *pStmt);
|
int step(sqlite3_stmt *pStmt);
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ struct Dna
|
|||||||
uint8_t colorSet;
|
uint8_t colorSet;
|
||||||
Branch branches[MAX_DEPTH];
|
Branch branches[MAX_DEPTH];
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace DNA
|
namespace DNA
|
||||||
{
|
{
|
||||||
void newDna(Dna *dna, uint128 *state);
|
void newDna(Dna *dna, uint128 *state);
|
||||||
|
|||||||
20
shared/inc/values/DnaDB.hpp
Normal file
20
shared/inc/values/DnaDB.hpp
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#include <cinttypes>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
struct sqlite3;
|
||||||
|
|
||||||
|
class DnaDB
|
||||||
|
{
|
||||||
|
sqlite3 *db;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void init(const char *db_name = "data.db");
|
||||||
|
void deinit();
|
||||||
|
std::vector<int64_t> getUserIds();
|
||||||
|
int insertUser(int64_t id, int64_t max_gen);
|
||||||
|
int updateUser(int64_t id, int64_t max_gen);
|
||||||
|
|
||||||
|
void getGenerations();
|
||||||
|
void getLikesForGeneration();
|
||||||
|
void getVectorForGeneration();
|
||||||
|
};
|
||||||
@@ -7,9 +7,9 @@
|
|||||||
|
|
||||||
enum Liked
|
enum Liked
|
||||||
{
|
{
|
||||||
tbd,
|
tbd = 0,
|
||||||
yes,
|
yes = 1,
|
||||||
no
|
no = 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct UiUnit
|
struct UiUnit
|
||||||
|
|||||||
@@ -3,15 +3,16 @@
|
|||||||
|
|
||||||
namespace Similarity
|
namespace Similarity
|
||||||
{
|
{
|
||||||
// float euclidean_distance(Dna *d1, Dna *d2); direct distance betwen vector. wont give 0 and 1
|
float euclidean_distance(Dna *d1, Dna *d2);// direct distance betwen vector. wont give 0 and 1
|
||||||
// float dot_product(Dna *d1, Dna *d2); doent return betwen 0 to 1
|
float dot_minmax(Dna *d1, Dna *d2); // doent return betwen 0 to 1
|
||||||
float cosine_similarity(Dna *d1, Dna *d2);
|
float cosine_similarity(Dna *d1, Dna *d2);
|
||||||
float cosine_similarity_int(Dna *d1, Dna *d2);
|
float cosine_similarity_int(Dna *d1, Dna *d2);
|
||||||
float hamming_distance(Dna *d1, Dna *d2);
|
float hamming_distance(Dna *d1, Dna *d2);
|
||||||
|
float hamming_distance_without_seeds(Dna *d1, Dna *d2);
|
||||||
// float jaccard_index(Dna *d1, Dna *d2); // primerja unio genov naprimer gleda ce je gen za nebo isti z genom za barvo za liste, to nerabimo
|
// float jaccard_index(Dna *d1, Dna *d2); // primerja unio genov naprimer gleda ce je gen za nebo isti z genom za barvo za liste, to nerabimo
|
||||||
// float levenshtein_distance(Dna *d1, Dna *d2); // odstranjen ker mi vrne iste podatke kot hamming distance ki je bolj enostaven za izracun
|
float levenshtein_distance(Dna *d1, Dna *d2); // odstranjen ker mi vrne iste podatke kot hamming distance ki je bolj enostaven za izracun
|
||||||
// float needleman_wunsch(Dna *d1, Dna *d2); used for bioinformatics and aligment. Dont need its aligned alredy
|
// float needleman_wunsch(Dna *d1, Dna *d2); used for bioinformatics and aligment. Dont need its aligned alredy
|
||||||
|
|
||||||
typedef float(simil_func)(Dna *d1, Dna *d2);
|
typedef float(simil_func)(Dna *d1, Dna *d2);
|
||||||
float calc_similarity(std::vector<Dna> &vec, simil_func f);
|
float calc_similarity(std::vector<Dna> &vec, simil_func f = hamming_distance_without_seeds);
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "canvas/BackGround.hpp"
|
#include "canvas/BackGround.hpp"
|
||||||
#include "canvas/BackGroundColors.hpp"
|
#include "canvas/BackGroundColors.hpp"
|
||||||
#include "canvas/Circle.hpp"
|
|
||||||
#include "canvas/stb_perlin.h"
|
#include "canvas/stb_perlin.h"
|
||||||
|
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
@@ -44,6 +44,9 @@ Color ColorAdd(Color c1, Color c2)
|
|||||||
void BackGround::init(int canvasSize)
|
void BackGround::init(int canvasSize)
|
||||||
{
|
{
|
||||||
this->canvasSize = canvasSize;
|
this->canvasSize = canvasSize;
|
||||||
|
// resitev da ne postane tekstura okoli sonca transparentna in da se ne vidi nasledna slika
|
||||||
|
// https://github.com/raysan5/raylib/issues/3820
|
||||||
|
rlSetBlendFactorsSeparate(RL_SRC_ALPHA, RL_ONE_MINUS_SRC_ALPHA, RL_ONE, RL_ONE, RL_FUNC_ADD, RL_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackGround::deinit()
|
void BackGround::deinit()
|
||||||
@@ -52,7 +55,6 @@ void BackGround::deinit()
|
|||||||
|
|
||||||
void BackGround::draw(Dna *dna)
|
void BackGround::draw(Dna *dna)
|
||||||
{
|
{
|
||||||
Circle::setSoftEdge(true);
|
|
||||||
m_dna = dna;
|
m_dna = dna;
|
||||||
mountenSeed = dna->mountenSeed;
|
mountenSeed = dna->mountenSeed;
|
||||||
starSeed = dna->starSeed;
|
starSeed = dna->starSeed;
|
||||||
@@ -118,26 +120,45 @@ void BackGround::drawStars()
|
|||||||
|
|
||||||
void BackGround::drawSun()
|
void BackGround::drawSun()
|
||||||
{
|
{
|
||||||
int r = ((m_dna->moonY / 255.0f * (maxSizeOfMoon - minSizeOfMoon)) + minSizeOfMoon) * canvasSize;
|
int radius = ((m_dna->moonY / 255.0f * (maxSizeOfMoon - minSizeOfMoon)) + minSizeOfMoon) * canvasSize;
|
||||||
int xpos = Lerp(canvasSize * moonXOffset, canvasSize - canvasSize * moonXOffset, m_dna->moonX / 255.0f);
|
int xpos = Lerp(canvasSize * moonXOffset, canvasSize - canvasSize * moonXOffset, m_dna->moonX / 255.0f);
|
||||||
int ypos = Lerp(canvasSize * moonXOffset, maxYPosOfMoon * canvasSize, m_dna->moonY / 255.0f);
|
int ypos = Lerp(canvasSize * moonXOffset, maxYPosOfMoon * canvasSize, m_dna->moonY / 255.0f);
|
||||||
|
|
||||||
|
Color color = {0};
|
||||||
if (getColorSet() == 3)
|
if (getColorSet() == 3)
|
||||||
{
|
{
|
||||||
Circle::setColor(BackGroundColors::moonColor);
|
color = BackGroundColors::moonColor;
|
||||||
r = (((m_dna->moonSize / 255.0f) * (maxSizeOfMoon - minSizeOfMoon)) + minSizeOfMoon) * canvasSize;
|
radius = (((m_dna->moonSize / 255.0f) * (maxSizeOfMoon - minSizeOfMoon)) + minSizeOfMoon) * canvasSize;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Color color = {0};
|
|
||||||
color.r = 255;
|
color.r = 255;
|
||||||
color.g = std::lerp(200, 50, m_dna->moonY / 255.0f);
|
color.g = std::lerp(200, 50, m_dna->moonY / 255.0f);
|
||||||
color.b = std::lerp(50, 0, m_dna->moonY / 255.0f);
|
color.b = std::lerp(50, 0, m_dna->moonY / 255.0f);
|
||||||
color.a = 255;
|
|
||||||
|
|
||||||
Circle::setColor(color);
|
|
||||||
}
|
}
|
||||||
Circle::draw(xpos, ypos, r);
|
|
||||||
|
BeginBlendMode(RL_BLEND_CUSTOM_SEPARATE);
|
||||||
|
|
||||||
|
constexpr float numOfCircles = 15.0f;
|
||||||
|
constexpr float sunMin = 1.7f;
|
||||||
|
|
||||||
|
float amount = 0.0f;
|
||||||
|
color.a = 15;
|
||||||
|
for (size_t i = 0; i < numOfCircles; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
float r = Lerp(radius, radius / sunMin, amount);
|
||||||
|
DrawCircle(xpos, ypos, r, color);
|
||||||
|
amount += 1.0f / numOfCircles;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
EndBlendMode();
|
||||||
|
|
||||||
|
color.a = 255;
|
||||||
|
DrawCircle(xpos, ypos, radius / sunMin, color);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackGround::drawMounten(size_t mountenSegments, int min, int max, Color color, float scale)
|
void BackGround::drawMounten(size_t mountenSegments, int min, int max, Color color, float scale)
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
#include "canvas/Canvas.hpp"
|
#include "canvas/Canvas.hpp"
|
||||||
#include "canvas/Circle.hpp"
|
|
||||||
|
|
||||||
void Canvas::init(int size)
|
void Canvas::init(int size)
|
||||||
{
|
{
|
||||||
backGround.init(size);
|
backGround.init(size);
|
||||||
tree.init(size);
|
tree.init(size);
|
||||||
Circle::init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::newGen(RenderTexture2D &target, Dna *dna)
|
void Canvas::newGen(RenderTexture2D &target, Dna *dna)
|
||||||
@@ -30,5 +28,4 @@ bool Canvas::tick(RenderTexture2D &target)
|
|||||||
void Canvas::deinit()
|
void Canvas::deinit()
|
||||||
{
|
{
|
||||||
backGround.deinit();
|
backGround.deinit();
|
||||||
Circle::deinit();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,83 +0,0 @@
|
|||||||
#include "canvas/Circle.hpp"
|
|
||||||
#include "canvas/sunShader.hpp"
|
|
||||||
|
|
||||||
#include <raylib.h>
|
|
||||||
#include <rlgl.h>
|
|
||||||
|
|
||||||
RenderTexture2D Circle::target;
|
|
||||||
Shader Circle::shader;
|
|
||||||
float Circle::radius;
|
|
||||||
float Circle::start_transperency;
|
|
||||||
float Circle::c[3];
|
|
||||||
int Circle::radius_loc;
|
|
||||||
int Circle::start_transperency_loc;
|
|
||||||
int Circle::colorLoc;
|
|
||||||
|
|
||||||
void Circle::init()
|
|
||||||
{
|
|
||||||
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
|
|
||||||
shader = LoadShaderFromMemory(nullptr, sun_shader_100);
|
|
||||||
#else
|
|
||||||
shader = LoadShaderFromMemory(nullptr, (const char *)shaders_sun_330_fs);
|
|
||||||
#endif
|
|
||||||
target = LoadRenderTexture(sizeTexute, sizeTexute);
|
|
||||||
|
|
||||||
radius = 0.6f;
|
|
||||||
radius_loc = GetShaderLocation(shader, "sun_radius");
|
|
||||||
SetShaderValue(shader, radius_loc, &radius, SHADER_UNIFORM_FLOAT);
|
|
||||||
|
|
||||||
start_transperency = 0.40f;
|
|
||||||
start_transperency_loc = GetShaderLocation(shader, "start_transperency");
|
|
||||||
SetShaderValue(shader, start_transperency_loc, &start_transperency, SHADER_UNIFORM_FLOAT);
|
|
||||||
|
|
||||||
c[0] = 1.0f;
|
|
||||||
c[1] = 1.0f;
|
|
||||||
c[2] = 1.0f;
|
|
||||||
colorLoc = GetShaderLocation(shader, "color");
|
|
||||||
SetShaderValue(shader, colorLoc, c, SHADER_UNIFORM_VEC3);
|
|
||||||
|
|
||||||
// resitev da ne postane tekstura okoli sonca transparentna in da se ne vidi nasledna slika
|
|
||||||
// https://github.com/raysan5/raylib/issues/3820
|
|
||||||
rlSetBlendFactorsSeparate(RL_SRC_ALPHA, RL_ONE_MINUS_SRC_ALPHA, RL_ONE, RL_ONE, RL_FUNC_ADD, RL_MAX);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Circle::deinit()
|
|
||||||
{
|
|
||||||
UnloadShader(shader);
|
|
||||||
UnloadRenderTexture(target);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Circle::setColor(Color color)
|
|
||||||
{
|
|
||||||
c[0] = color.r / 255.0f;
|
|
||||||
c[1] = color.g / 255.0f;
|
|
||||||
c[2] = color.b / 255.0f;
|
|
||||||
SetShaderValue(shader, colorLoc, c, SHADER_UNIFORM_VEC3);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Circle::setSoftEdge(bool soft)
|
|
||||||
{
|
|
||||||
if (soft)
|
|
||||||
{
|
|
||||||
radius = 0.6f;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
radius = 1.0f;
|
|
||||||
}
|
|
||||||
SetShaderValue(shader, radius_loc, &radius, SHADER_UNIFORM_FLOAT);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Circle::draw(float x, float y, float size)
|
|
||||||
{
|
|
||||||
Rectangle dest = {x - size, y - size, size * 2, size * 2};
|
|
||||||
Rectangle source = {0, 0, (float)target.texture.width, (float)-target.texture.height};
|
|
||||||
Vector2 origin = {0.0f, 0.0f};
|
|
||||||
|
|
||||||
// zgorni komentar da se mesanje barv oklopi pravilno
|
|
||||||
BeginBlendMode(RL_BLEND_CUSTOM_SEPARATE);
|
|
||||||
BeginShaderMode(shader);
|
|
||||||
DrawTexturePro(target.texture, source, dest, origin, 0.0f, WHITE);
|
|
||||||
EndShaderMode();
|
|
||||||
EndBlendMode();
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#include "canvas/Tree.hpp"
|
#include "canvas/Tree.hpp"
|
||||||
#include "canvas/Circle.hpp"
|
|
||||||
|
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
#include <raymath.h>
|
#include <raymath.h>
|
||||||
|
#include <rlgl.h>
|
||||||
|
|
||||||
#define ITER_PER_FRAME 5000
|
#define ITER_PER_FRAME 5000
|
||||||
|
|
||||||
@@ -41,12 +41,11 @@ void Tree::init(int size)
|
|||||||
start.x = size / 2;
|
start.x = size / 2;
|
||||||
start.y = size;
|
start.y = size;
|
||||||
calculateLevels(size);
|
calculateLevels(size);
|
||||||
|
// texBunny = LoadTexture("dot.png"); // bug add deinit to unload texutre
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tree::draw(Dna *dna)
|
void Tree::draw(Dna *dna)
|
||||||
{
|
{
|
||||||
Circle::setSoftEdge(false);
|
|
||||||
|
|
||||||
m_dna = dna;
|
m_dna = dna;
|
||||||
branchSeed = dna->branchSeed;
|
branchSeed = dna->branchSeed;
|
||||||
drawCalls.push_back({start, 180.0f, 0});
|
drawCalls.push_back({start, 180.0f, 0});
|
||||||
@@ -58,7 +57,7 @@ bool Tree::tick()
|
|||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
while (!drawCalls.empty())
|
while (!drawCalls.empty())
|
||||||
{
|
{
|
||||||
drawBranch();
|
calculateBranch();
|
||||||
drawCalls.pop_front();
|
drawCalls.pop_front();
|
||||||
i++;
|
i++;
|
||||||
if (i >= ITER_PER_FRAME)
|
if (i >= ITER_PER_FRAME)
|
||||||
@@ -70,7 +69,7 @@ bool Tree::tick()
|
|||||||
|
|
||||||
// Private
|
// Private
|
||||||
|
|
||||||
void Tree::drawBranch()
|
void Tree::calculateBranch()
|
||||||
{
|
{
|
||||||
DrawArgs arg = drawCalls.front();
|
DrawArgs arg = drawCalls.front();
|
||||||
if (arg.dep == MAX_DEPTH)
|
if (arg.dep == MAX_DEPTH)
|
||||||
@@ -88,18 +87,14 @@ void Tree::drawBranch()
|
|||||||
|
|
||||||
Color colorStart = getStartColor(arg);
|
Color colorStart = getStartColor(arg);
|
||||||
Color colorEnd = getEndColor(arg.dep, colorStart);
|
Color colorEnd = getEndColor(arg.dep, colorStart);
|
||||||
|
// drawBranch(arg.start, end, colorStart, colorEnd, sizeStart, sizeEnd);
|
||||||
for (float i = 0; i < 1; i += fstep)
|
for (float i = 0; i < 1; i += fstep)
|
||||||
{
|
{
|
||||||
Vector2 point = Vector2Lerp(arg.start, end, i);
|
Vector2 point = Vector2Lerp(arg.start, end, i);
|
||||||
Color color = ColorLerp(colorStart, colorEnd, i);
|
Color color = ColorLerp(colorStart, colorEnd, i);
|
||||||
int size = Lerp(sizeStart, sizeEnd, i);
|
int size = Lerp(sizeStart, sizeEnd, i);
|
||||||
DrawCircleV(point, size, color); // Fester on the phone to call DrawCircle insted of the Circle shader
|
DrawCircleV(point, size, color);
|
||||||
// Circle::setColor(color);
|
// DrawTextureEx(texBunny, point,0, ((float)size) / texBunny.height, color);
|
||||||
// Circle::draw(point.x, point.y, thick); // TODO Change to BeginShaderMode and EndShaderMode only onece
|
|
||||||
|
|
||||||
// use
|
|
||||||
// DrawRectangleGradientEx
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add more branches to draw
|
// add more branches to draw
|
||||||
@@ -203,3 +198,51 @@ inline float Tree::getAngleVar(DrawArgs &arg)
|
|||||||
|
|
||||||
return angleVar;
|
return angleVar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Tree::drawBranch(Vector2 startPoint, Vector2 endPoint, Color startColor, Color endColor, float startThickness, float endThickness)
|
||||||
|
{
|
||||||
|
// 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)
|
||||||
|
Vector2 perpendicular = {-normalizedDir.y, normalizedDir.x};
|
||||||
|
|
||||||
|
// Calculate the four vertices of the quadrilateral
|
||||||
|
Vector2 topLeft = {
|
||||||
|
startPoint.x + perpendicular.x * startThickness,
|
||||||
|
startPoint.y + perpendicular.y * startThickness};
|
||||||
|
Vector2 topRight = {
|
||||||
|
endPoint.x + perpendicular.x * endThickness,
|
||||||
|
endPoint.y + perpendicular.y * endThickness};
|
||||||
|
Vector2 bottomLeft = {
|
||||||
|
startPoint.x - perpendicular.x * startThickness,
|
||||||
|
startPoint.y - perpendicular.y * startThickness};
|
||||||
|
Vector2 bottomRight = {
|
||||||
|
endPoint.x - perpendicular.x * endThickness,
|
||||||
|
endPoint.y - perpendicular.y * endThickness};
|
||||||
|
|
||||||
|
// Draw the two triangles to form the quadrilateral
|
||||||
|
rlBegin(RL_TRIANGLES);
|
||||||
|
// First triangle
|
||||||
|
rlColor4ub(startColor.r, startColor.g, startColor.b, startColor.a);
|
||||||
|
rlVertex2f(topLeft.x, topLeft.y);
|
||||||
|
rlColor4ub(endColor.r, endColor.g, endColor.b, endColor.a);
|
||||||
|
rlVertex2f(topRight.x, topRight.y);
|
||||||
|
rlColor4ub(startColor.r, startColor.g, startColor.b, startColor.a);
|
||||||
|
rlVertex2f(bottomLeft.x, bottomLeft.y);
|
||||||
|
|
||||||
|
// Second triangle
|
||||||
|
rlColor4ub(startColor.r, startColor.g, startColor.b, startColor.a);
|
||||||
|
rlVertex2f(bottomLeft.x, bottomLeft.y);
|
||||||
|
rlColor4ub(endColor.r, endColor.g, endColor.b, endColor.a);
|
||||||
|
rlVertex2f(topRight.x, topRight.y);
|
||||||
|
rlColor4ub(endColor.r, endColor.g, endColor.b, endColor.a);
|
||||||
|
rlVertex2f(bottomRight.x, bottomRight.y);
|
||||||
|
rlEnd();
|
||||||
|
}
|
||||||
@@ -50,6 +50,17 @@ namespace sql
|
|||||||
fprintf(stdout, "user_table created successfully\n");
|
fprintf(stdout, "user_table created successfully\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rc = sqlite3_exec(db, create_blocked_ip_table, nullptr, 0, &zErrMsg);
|
||||||
|
if (rc != SQLITE_OK)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "SQL error: %s\n", zErrMsg);
|
||||||
|
sqlite3_free(zErrMsg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(stdout, "blocked_ip_table created successfully\n");
|
||||||
|
}
|
||||||
|
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,6 +78,10 @@ namespace sql
|
|||||||
{
|
{
|
||||||
return sqlite3_open(filename, ppDb);
|
return sqlite3_open(filename, ppDb);
|
||||||
}
|
}
|
||||||
|
int exec(sqlite3 *db, const char *sql, int (*callback)(void *, int, char **, char **), void *first, char **errmsg)
|
||||||
|
{
|
||||||
|
return sqlite3_exec(db, sql, callback, first, errmsg);
|
||||||
|
}
|
||||||
int prepare_v2(sqlite3 *db, const char *zSql, int nByte, sqlite3_stmt **pStmt, const char **pzTail)
|
int prepare_v2(sqlite3 *db, const char *zSql, int nByte, sqlite3_stmt **pStmt, const char **pzTail)
|
||||||
{
|
{
|
||||||
return sqlite3_prepare_v2(db, zSql, nByte, pStmt, pzTail);
|
return sqlite3_prepare_v2(db, zSql, nByte, pStmt, pzTail);
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ namespace DNA
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mutate(Dna *dna, uint32_t num, uint128 *state)
|
void mutate(Dna *dna, uint32_t num, uint128 *state)
|
||||||
{
|
{
|
||||||
uint8_t *array = (uint8_t *)dna;
|
uint8_t *array = (uint8_t *)dna;
|
||||||
|
|||||||
69
shared/src/values/DnaDB.cpp
Normal file
69
shared/src/values/DnaDB.cpp
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
#include "values/DnaDB.hpp"
|
||||||
|
|
||||||
|
#include <sql.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void DnaDB::init(const char * db_name)
|
||||||
|
{
|
||||||
|
sql::init();
|
||||||
|
int res = sql::open(db_name, &db);
|
||||||
|
|
||||||
|
constexpr char create_user_table[] = "CREATE TABLE IF NOT EXISTS user_table ( ID INTEGER PRIMARY KEY, USER_ID INTEGER, MAX_GENERATION INTEGER);";
|
||||||
|
res = sql::exec(db, create_user_table, nullptr, nullptr, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DnaDB::deinit()
|
||||||
|
{
|
||||||
|
sql::close(db);
|
||||||
|
sql::shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<int64_t> DnaDB::getUserIds()
|
||||||
|
{
|
||||||
|
constexpr char sql[] = "SELECT USER_ID FROM user_table;";
|
||||||
|
sqlite3_stmt *stmt;
|
||||||
|
sql::prepare_v2(db, sql, -1, &stmt, nullptr);
|
||||||
|
std::vector<int64_t> ids;
|
||||||
|
while (sql::step(stmt) != SQL_DONE)
|
||||||
|
{
|
||||||
|
int64_t id = sql::column_int64(stmt, 0);
|
||||||
|
ids.push_back(id);
|
||||||
|
}
|
||||||
|
sql::finalize(stmt);
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DnaDB::insertUser(int64_t id, int64_t max_gen){
|
||||||
|
constexpr char sql[] = "INSERT INTO user_table (USER_ID, MAX_GENERATION) VALUES (?,?);";
|
||||||
|
sqlite3_stmt *stmt;
|
||||||
|
sql::prepare_v2(db, sql, -1, &stmt, nullptr);
|
||||||
|
sql::bind_int64(stmt, 1, id);
|
||||||
|
sql::bind_int64(stmt, 2, max_gen);
|
||||||
|
int ret = sql::step(stmt);
|
||||||
|
sql::finalize(stmt);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DnaDB::updateUser(int64_t id, int64_t max_gen){
|
||||||
|
constexpr char sql[] = "UPDATE user_table SET MAX_GENERATION = ? WHERE USER_ID = ?;";
|
||||||
|
sqlite3_stmt *stmt;
|
||||||
|
sql::prepare_v2(db, sql, -1, &stmt, nullptr);
|
||||||
|
sql::bind_int64(stmt, 1, max_gen);
|
||||||
|
sql::bind_int64(stmt, 2, id);
|
||||||
|
int ret = sql::step(stmt);
|
||||||
|
sql::finalize(stmt);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DnaDB::getGenerations()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void DnaDB::getLikesForGeneration()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void DnaDB::getVectorForGeneration()
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -1,8 +1,43 @@
|
|||||||
#include "values/Similarity.hpp"
|
#include "values/Similarity.hpp"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <numeric>
|
||||||
|
#include <raylib.h>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
namespace Similarity
|
namespace Similarity
|
||||||
{
|
{
|
||||||
|
|
||||||
|
float dot_minmax(Dna *d1, Dna *d2)
|
||||||
|
{
|
||||||
|
uint64_t max = sizeof(Dna) * 255 * 255;
|
||||||
|
uint8_t *a = (uint8_t *)d1;
|
||||||
|
uint8_t *b = (uint8_t *)d2;
|
||||||
|
uint32_t result = 0;
|
||||||
|
for (size_t i = 0; i < sizeof(Dna); ++i)
|
||||||
|
{
|
||||||
|
result += static_cast<uint32_t>(a[i]) * static_cast<uint32_t>(b[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result / (double)max;
|
||||||
|
}
|
||||||
|
|
||||||
|
float euclidean_distance(Dna *d1, Dna *d2)
|
||||||
|
{
|
||||||
|
uint8_t *a = (uint8_t *)d1;
|
||||||
|
uint8_t *b = (uint8_t *)d2;
|
||||||
|
float sum = 0.0f;
|
||||||
|
for (size_t i = 0; i < sizeof(Dna); ++i)
|
||||||
|
{
|
||||||
|
float diff = static_cast<float>(a[i]) - static_cast<float>(b[i]);
|
||||||
|
sum += diff * diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
float distance = std::sqrt(sum);
|
||||||
|
float max_distance = 255.0f * std::sqrt(static_cast<float>(sizeof(Dna)));
|
||||||
|
return 1 - (distance / max_distance);
|
||||||
|
}
|
||||||
|
|
||||||
// todo: use int8_t insted of uint8_t and map data
|
// todo: use int8_t insted of uint8_t and map data
|
||||||
// 0 -> -128
|
// 0 -> -128
|
||||||
// 255 -> 127
|
// 255 -> 127
|
||||||
@@ -31,10 +66,8 @@ namespace Similarity
|
|||||||
{
|
{
|
||||||
auto map = [](uint8_t a) -> int8_t
|
auto map = [](uint8_t a) -> int8_t
|
||||||
{ return a - 128; };
|
{ return a - 128; };
|
||||||
|
|
||||||
uint8_t *d1a = (uint8_t *)d1;
|
uint8_t *d1a = (uint8_t *)d1;
|
||||||
uint8_t *d2a = (uint8_t *)d2;
|
uint8_t *d2a = (uint8_t *)d2;
|
||||||
|
|
||||||
float mag1 = 0.0f;
|
float mag1 = 0.0f;
|
||||||
float mag2 = 0.0f;
|
float mag2 = 0.0f;
|
||||||
float dot_prod = 0.0f;
|
float dot_prod = 0.0f;
|
||||||
@@ -48,7 +81,6 @@ namespace Similarity
|
|||||||
}
|
}
|
||||||
mag1 = sqrt(mag1);
|
mag1 = sqrt(mag1);
|
||||||
mag2 = sqrt(mag2);
|
mag2 = sqrt(mag2);
|
||||||
|
|
||||||
return dot_prod / (mag1 * mag2);
|
return dot_prod / (mag1 * mag2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,8 +99,62 @@ namespace Similarity
|
|||||||
return 1 - (distance / sizeof(Dna));
|
return 1 - (distance / sizeof(Dna));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float hamming_distance_without_seeds(Dna *d1, Dna *d2)
|
||||||
|
{
|
||||||
|
constexpr size_t start = sizeof(uint128) * 3;
|
||||||
|
constexpr size_t end = sizeof(Dna);
|
||||||
|
uint8_t *d1a = (uint8_t *)d1;
|
||||||
|
uint8_t *d2a = (uint8_t *)d2;
|
||||||
|
float distance = 0;
|
||||||
|
for (size_t i = start; i < end; i++)
|
||||||
|
{
|
||||||
|
if (d1a[i] != d2a[i])
|
||||||
|
{
|
||||||
|
distance++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1 - (distance / (end - start));
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *nameofFunc(simil_func f)
|
||||||
|
{
|
||||||
|
if (f == &Similarity::euclidean_distance)
|
||||||
|
{
|
||||||
|
return "eucl";
|
||||||
|
}
|
||||||
|
else if (f == &Similarity::dot_minmax)
|
||||||
|
{
|
||||||
|
return "dot";
|
||||||
|
}
|
||||||
|
else if (f == &Similarity::cosine_similarity)
|
||||||
|
{
|
||||||
|
return "cos";
|
||||||
|
}
|
||||||
|
else if (f == &Similarity::cosine_similarity_int)
|
||||||
|
{
|
||||||
|
return "cos_i";
|
||||||
|
}
|
||||||
|
else if (f == &Similarity::hamming_distance)
|
||||||
|
{
|
||||||
|
return "hamming_distance";
|
||||||
|
}
|
||||||
|
else if (f == &Similarity::hamming_distance_without_seeds)
|
||||||
|
{
|
||||||
|
return "hamming_distance_without_seeds";
|
||||||
|
}
|
||||||
|
else if (f == &Similarity::levenshtein_distance)
|
||||||
|
{
|
||||||
|
return "leven";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return "unknown nameofFunc";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
float calc_similarity(std::vector<Dna> &vec, simil_func f)
|
float calc_similarity(std::vector<Dna> &vec, simil_func f)
|
||||||
{
|
{
|
||||||
|
auto start = std::chrono::high_resolution_clock::now();
|
||||||
size_t num_pairs = (vec.size() * (vec.size() - 1)) / 2;
|
size_t num_pairs = (vec.size() * (vec.size() - 1)) / 2;
|
||||||
|
|
||||||
float total_similarity = 0.0;
|
float total_similarity = 0.0;
|
||||||
@@ -80,6 +166,47 @@ namespace Similarity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
float average_similarity = total_similarity / num_pairs;
|
float average_similarity = total_similarity / num_pairs;
|
||||||
|
|
||||||
|
auto stop = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
|
const auto int_ms = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
|
||||||
|
|
||||||
return average_similarity * 100.0f;
|
return average_similarity * 100.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float levenshtein_distance(Dna *d1, Dna *d2)
|
||||||
|
{
|
||||||
|
size_t len = sizeof(Dna);
|
||||||
|
uint8_t *a = (uint8_t *)d1;
|
||||||
|
uint8_t *b = (uint8_t *)d2;
|
||||||
|
|
||||||
|
// Create a distance matrix
|
||||||
|
static std::vector<std::vector<uint32_t>> dp(len + 1, std::vector<uint32_t>(len + 1, 0));
|
||||||
|
|
||||||
|
// Initialize the first row and column
|
||||||
|
for (size_t i = 0; i <= len; ++i)
|
||||||
|
{
|
||||||
|
dp[i][0] = i;
|
||||||
|
}
|
||||||
|
for (size_t j = 0; j <= len; ++j)
|
||||||
|
{
|
||||||
|
dp[0][j] = j;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill the distance matrix
|
||||||
|
for (size_t i = 1; i <= len; ++i)
|
||||||
|
{
|
||||||
|
for (size_t j = 1; j <= len; ++j)
|
||||||
|
{
|
||||||
|
uint32_t cost = (a[i - 1] == b[j - 1]) ? 0 : 1;
|
||||||
|
dp[i][j] = std::min({
|
||||||
|
dp[i - 1][j] + 1, // deletion
|
||||||
|
dp[i][j - 1] + 1, // insertion
|
||||||
|
dp[i - 1][j - 1] + cost // substitution
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1 - (dp[len][len] / float(len + len));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
14
tmp.txt
Normal file
14
tmp.txt
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
eucl cos cos_i hamming dot leven
|
||||||
|
91 117 181 87 41 105799
|
||||||
|
60 78 305 250 40 100331
|
||||||
|
61 78 121 105 40 97438
|
||||||
|
66 81 124 106 40 97529
|
||||||
|
60 78 127 108 40 96296
|
||||||
|
62 85 131 104 39 96456
|
||||||
|
61 81 125 106 40 96510
|
||||||
|
61 81 125 103 40 97253
|
||||||
|
61 81 125 78 40 97409
|
||||||
|
60 82 125 103 40 99816
|
||||||
|
62 81 128 81 40 98978
|
||||||
|
68 81 126 58 40 98289
|
||||||
|
61 88 130 60 39 99663
|
||||||
@@ -11,13 +11,16 @@ enum DrawingStage
|
|||||||
drawTree,
|
drawTree,
|
||||||
drawBig,
|
drawBig,
|
||||||
calSim,
|
calSim,
|
||||||
|
save,
|
||||||
done,
|
done,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
constexpr int numberOfFunc = 6;
|
||||||
|
|
||||||
class Vapp
|
class Vapp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void init();
|
void init(char* filename);
|
||||||
void update();
|
void update();
|
||||||
void draw();
|
void draw();
|
||||||
void deinit();
|
void deinit();
|
||||||
@@ -25,6 +28,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
bool showSelection;
|
bool showSelection;
|
||||||
bool showStats;
|
bool showStats;
|
||||||
|
bool saveToFile;
|
||||||
sqlite3 *db;
|
sqlite3 *db;
|
||||||
sqlite3_stmt *get_gen_num;
|
sqlite3_stmt *get_gen_num;
|
||||||
std::vector<int64_t> ids;
|
std::vector<int64_t> ids;
|
||||||
@@ -46,8 +50,9 @@ private:
|
|||||||
int drawY = 0;
|
int drawY = 0;
|
||||||
void setUpManager();
|
void setUpManager();
|
||||||
|
|
||||||
std::array<float, 3> simil;
|
std::array<float, numberOfFunc> simil;
|
||||||
std::vector<std::array<float, 3>> similTable;
|
std::vector<std::array<float, numberOfFunc>> similTable;
|
||||||
|
|
||||||
void setUpTable();
|
void setUpTable();
|
||||||
|
void drawToFile();
|
||||||
};
|
};
|
||||||
@@ -6,12 +6,13 @@
|
|||||||
#include <rlImGui.h>
|
#include <rlImGui.h>
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
const char select_user_id[] = "SELECT USER_ID FROM user_table GROUP BY USER_ID;";
|
const char select_user_id[] = "SELECT USER_ID FROM user_table GROUP BY USER_ID;";
|
||||||
|
|
||||||
constexpr int sizeOfCanvas = 1000;
|
constexpr int sizeOfCanvas = 1000;
|
||||||
|
|
||||||
void Vapp::init()
|
void Vapp::init(char *filename)
|
||||||
{
|
{
|
||||||
bigTexture = LoadRenderTexture(sizeOfCanvas * 4, sizeOfCanvas * 4);
|
bigTexture = LoadRenderTexture(sizeOfCanvas * 4, sizeOfCanvas * 4);
|
||||||
treeTexture = LoadRenderTexture(sizeOfCanvas, sizeOfCanvas);
|
treeTexture = LoadRenderTexture(sizeOfCanvas, sizeOfCanvas);
|
||||||
@@ -20,7 +21,7 @@ void Vapp::init()
|
|||||||
DnaManager::setUp(&manager, 0);
|
DnaManager::setUp(&manager, 0);
|
||||||
|
|
||||||
sql::init();
|
sql::init();
|
||||||
sql::open(DB_NAME, &db);
|
sql::open(filename, &db);
|
||||||
|
|
||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
sql::prepare_v2(db, select_user_id, -1, &stmt, NULL);
|
sql::prepare_v2(db, select_user_id, -1, &stmt, NULL);
|
||||||
@@ -100,12 +101,18 @@ void Vapp::update()
|
|||||||
break;
|
break;
|
||||||
case DrawingStage::calSim:
|
case DrawingStage::calSim:
|
||||||
|
|
||||||
simil[0] = Similarity::calc_similarity(manager.vector, Similarity::cosine_similarity);
|
simil[0] = Similarity::calc_similarity(manager.vector, Similarity::euclidean_distance);
|
||||||
simil[1] = Similarity::calc_similarity(manager.vector, Similarity::hamming_distance);
|
simil[1] = Similarity::calc_similarity(manager.vector, Similarity::cosine_similarity);
|
||||||
simil[2] = Similarity::calc_similarity(manager.vector, Similarity::cosine_similarity_int);
|
simil[2] = Similarity::calc_similarity(manager.vector, Similarity::cosine_similarity_int);
|
||||||
|
simil[3] = Similarity::calc_similarity(manager.vector, Similarity::hamming_distance);
|
||||||
|
simil[4] = Similarity::calc_similarity(manager.vector, Similarity::levenshtein_distance);
|
||||||
|
simil[5] = Similarity::calc_similarity(manager.vector, Similarity::dot_minmax);
|
||||||
|
stageOfDrawing = DrawingStage::save;
|
||||||
|
break;
|
||||||
|
case DrawingStage::save:
|
||||||
|
if(saveToFile) drawToFile();
|
||||||
stageOfDrawing = DrawingStage::done;
|
stageOfDrawing = DrawingStage::done;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DrawingStage::done:
|
case DrawingStage::done:
|
||||||
enableAll = true;
|
enableAll = true;
|
||||||
break;
|
break;
|
||||||
@@ -133,6 +140,10 @@ void Vapp::draw()
|
|||||||
{
|
{
|
||||||
setUpTable();
|
setUpTable();
|
||||||
}
|
}
|
||||||
|
if(ImGui::MenuItem("Save to File", nullptr, saveToFile, true))
|
||||||
|
{
|
||||||
|
saveToFile = !saveToFile;
|
||||||
|
}
|
||||||
ImGui::EndMainMenuBar();
|
ImGui::EndMainMenuBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,14 +185,35 @@ void Vapp::draw()
|
|||||||
if (showStats)
|
if (showStats)
|
||||||
{
|
{
|
||||||
ImGui::Begin("Status", &showStats);
|
ImGui::Begin("Status", &showStats);
|
||||||
ImGui::LabelText("##sim1", "cosine_similarity: %f", simil[0]);
|
ImGui::LabelText("##sim1", "euclidean_distance: %f", simil[0]);
|
||||||
ImGui::LabelText("##sim2", "hamming_distance: %f", simil[1]);
|
ImGui::LabelText("##sim2", "cosine_similarity: %f", simil[1]);
|
||||||
ImGui::LabelText("##sim3", "cosine_similarity_int: %f", simil[2]);
|
ImGui::LabelText("##sim3", "cosine_similarity_int: %f", simil[2]);
|
||||||
|
ImGui::LabelText("##sim4", "hamming_distance: %f", simil[3]);
|
||||||
|
ImGui::LabelText("##sim5", "levenshtein_distance: %f", simil[4]);
|
||||||
|
ImGui::LabelText("##sim6", "dot_minmax: %f", simil[5]);
|
||||||
|
|
||||||
const ImGuiTableFlags flags = ImGuiTableFlags_NoHostExtendX | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_ContextMenuInBody;
|
const ImGuiTableFlags flags = ImGuiTableFlags_NoHostExtendX | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_ContextMenuInBody;
|
||||||
const int columns = 4;
|
const int columns = numberOfFunc + 1;
|
||||||
if (ImGui::BeginTable("table1", columns, flags))
|
if (ImGui::BeginTable("table1", columns, flags))
|
||||||
{
|
{
|
||||||
|
|
||||||
|
ImGui::TableNextRow();
|
||||||
|
|
||||||
|
ImGui::TableSetColumnIndex(0);
|
||||||
|
ImGui::Text("index");
|
||||||
|
ImGui::TableSetColumnIndex(1);
|
||||||
|
ImGui::Text("euclidean_distance");
|
||||||
|
ImGui::TableSetColumnIndex(2);
|
||||||
|
ImGui::Text("cosine_similarity");
|
||||||
|
ImGui::TableSetColumnIndex(3);
|
||||||
|
ImGui::Text("cosine_similarity_int");
|
||||||
|
ImGui::TableSetColumnIndex(4);
|
||||||
|
ImGui::Text("hamming_distance");
|
||||||
|
ImGui::TableSetColumnIndex(5);
|
||||||
|
ImGui::Text("levenshtein_distance");
|
||||||
|
ImGui::TableSetColumnIndex(6);
|
||||||
|
ImGui::Text("dot_minmax");
|
||||||
|
|
||||||
for (int row = 0; row < similTable.size(); row++)
|
for (int row = 0; row < similTable.size(); row++)
|
||||||
{
|
{
|
||||||
ImGui::TableNextRow();
|
ImGui::TableNextRow();
|
||||||
@@ -279,7 +311,7 @@ void Vapp::setUpTable()
|
|||||||
UiUnit unit = DnaManager::next(&manager);
|
UiUnit unit = DnaManager::next(&manager);
|
||||||
if ((unit.index != pos))
|
if ((unit.index != pos))
|
||||||
{
|
{
|
||||||
// DOTO: SET ERROR
|
// TODO: SET ERROR
|
||||||
TraceLog(LOG_ERROR, "LOADING DNA");
|
TraceLog(LOG_ERROR, "LOADING DNA");
|
||||||
sql::finalize(get_gen_stmt);
|
sql::finalize(get_gen_stmt);
|
||||||
return;
|
return;
|
||||||
@@ -292,10 +324,13 @@ void Vapp::setUpTable()
|
|||||||
{
|
{
|
||||||
similTable.emplace_back();
|
similTable.emplace_back();
|
||||||
int s = similTable.size() - 1;
|
int s = similTable.size() - 1;
|
||||||
similTable[s][0] = Similarity::calc_similarity(manager.vector, Similarity::cosine_similarity);
|
|
||||||
similTable[s][1] = Similarity::calc_similarity(manager.vector, Similarity::hamming_distance);
|
|
||||||
similTable[s][2] = Similarity::calc_similarity(manager.vector, Similarity::cosine_similarity_int);
|
|
||||||
|
|
||||||
|
similTable[s][0] = Similarity::calc_similarity(manager.vector, Similarity::euclidean_distance);
|
||||||
|
similTable[s][1] = Similarity::calc_similarity(manager.vector, Similarity::cosine_similarity);
|
||||||
|
similTable[s][2] = Similarity::calc_similarity(manager.vector, Similarity::cosine_similarity_int);
|
||||||
|
similTable[s][3] = Similarity::calc_similarity(manager.vector, Similarity::hamming_distance);
|
||||||
|
similTable[s][4] = Similarity::calc_similarity(manager.vector, Similarity::levenshtein_distance);
|
||||||
|
similTable[s][5] = Similarity::calc_similarity(manager.vector, Similarity::dot_minmax);
|
||||||
DnaManager::newGen(&manager);
|
DnaManager::newGen(&manager);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -304,7 +339,38 @@ void Vapp::setUpTable()
|
|||||||
}
|
}
|
||||||
|
|
||||||
sql::reset(get_gen_stmt);
|
sql::reset(get_gen_stmt);
|
||||||
|
if(saveToFile)
|
||||||
|
{
|
||||||
|
int64_t id = ids[selected_id_index];
|
||||||
|
const char* buff = TextFormat("%ld.txt", id);
|
||||||
|
std::ofstream file(buff);
|
||||||
|
|
||||||
|
file << "| index | euclidean_distance | cosine_similarity | cosine_similarity_int | hamming_distance | levenshtein_distance | dot_minmax |\n";
|
||||||
|
file << "| --- | --- | --- | --- | --- | --- | --- |\n";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for (size_t i = 0; i < similTable.size(); i++)
|
||||||
|
{
|
||||||
|
file << "|" << i << "|";
|
||||||
|
for (size_t j = 0; j < similTable[i].size(); j++)
|
||||||
|
{
|
||||||
|
file << similTable[i][j] << "|";
|
||||||
|
}
|
||||||
|
file << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sql::finalize(get_gen_stmt);
|
sql::finalize(get_gen_stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Vapp::drawToFile()
|
||||||
|
{
|
||||||
|
int64_t id = ids[selected_id_index];
|
||||||
|
char buff[50];
|
||||||
|
sprintf(buff, "%ld_%d.png", id, selected_gen);
|
||||||
|
Image image = LoadImageFromTexture(bigTexture.texture);
|
||||||
|
ExportImage(image, buff);
|
||||||
|
UnloadImage(image);
|
||||||
|
}
|
||||||
@@ -2,18 +2,24 @@
|
|||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include <rlImGui.h>
|
#include <rlImGui.h>
|
||||||
#include "Vapp.hpp"
|
#include "Vapp.hpp"
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int screenWidth = 1000;
|
int screenWidth = 1000;
|
||||||
int screenHeight = 1000;
|
int screenHeight = 1000;
|
||||||
|
|
||||||
|
if(argc != 2){
|
||||||
|
printf("MISING DB FILE\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
Vapp app;
|
Vapp app;
|
||||||
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
||||||
InitWindow(screenWidth, screenHeight, "VIEW");
|
InitWindow(screenWidth, screenHeight, "VIEW");
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
rlImGuiSetup(true);
|
rlImGuiSetup(true);
|
||||||
app.init();
|
app.init(argv[1]);
|
||||||
ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||||
|
|
||||||
while (!WindowShouldClose())
|
while (!WindowShouldClose())
|
||||||
|
|||||||
Reference in New Issue
Block a user