#include #include #include "App.hpp" #include "timing.hpp" #include #include Font fontTtf; void DrawTextB(const char *text, float posX, float posY, int fontSize, Color color) { DrawTextEx(fontTtf, text, (Vector2){ posX, posY }, fontSize, 1, color); } void App::init(int screenWidth, int screenHeight) { fontTtf = LoadFontEx("res/CascadiaCode.ttf", 32, 0, 0); SetTextLineSpacing(16); this->screenWidth = screenWidth; this->screenHeight = screenHeight; this->canvas.init(screenWidth); canvasTexure = LoadRenderTexture(screenWidth, screenWidth); DnaStore::load(&manager); upTex(Liked::tbd); while (!canvas.tick(canvasTexure)) { // wait to finish drawing } float posY = (screenHeight - screenWidth) / 2.0f; destA = {0, posY, (float)screenWidth, (float)screenWidth}; } void App::upTex(Liked liked) { if (liked != Liked::tbd) { unit.liked = liked; bool ng = DnaManager::like(unit, &manager); if (ng) { DnaStore::saveGen(&manager); DnaManager::newGen(&manager); DnaStore::saveVec(&manager); } DnaStore::saveData(&manager); } unit = DnaManager::next(&manager); if (unit.dna != nullptr) { canvas.newGen(canvasTexure, unit.dna); return; } BeginTextureMode(canvasTexure); ClearBackground(BLACK); DrawText("NEXT GEN", 10, 10, screenWidth/10, WHITE); EndTextureMode(); } void App::update(){} enum class Rend_type{ every_frame, in_one_frame, over_frames, }; constexpr Rend_type rend_type = Rend_type::over_frames; void App::draw() { if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) { TraceLog(LOG_INFO, "CLICK"); upTex(Liked::yes); if constexpr (rend_type == Rend_type::in_one_frame){ while (!canvas.tick(canvasTexure)) { // wait to finish drawing } } } if constexpr (rend_type == Rend_type::over_frames){ canvas.tick(canvasTexure); } ClearBackground(BLUE); int fps = GetFPS(); const char* fpstext = TextFormat("%04d FPS", fps); DrawTextB(fpstext, 10, 10, 36, BLACK); const char* ctext = TextFormat("%04ld Circles", canvas.tree.circles); DrawTextB(ctext, 10, 50, 36, BLACK); Rectangle source = {0, 0, (float)screenWidth, (float)-screenWidth}; Vector2 origin = {0.0f, 0.0f}; if constexpr (rend_type == Rend_type::every_frame){ canvas.newGen(canvasTexure, unit.dna); while (!canvas.tick(canvasTexure)) { // wait to finish drawing } } DrawTexturePro(canvasTexure.texture, source, destA, origin, 360, WHITE); } void App::deinit() { UnloadRenderTexture(canvasTexure); UnloadFont(fontTtf); canvas.deinit(); }