From 107bd6cff593da2c6bf3f5ad16eefeac79e20ef3 Mon Sep 17 00:00:00 2001 From: Sara Gerretsen Date: Mon, 22 Sep 2025 19:18:44 +0200 Subject: [PATCH] feat: improved simulation frame delta controls --- src/application.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/src/application.cpp b/src/application.cpp index b6b2559..f722afe 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -11,6 +11,9 @@ static bool isSimulating{ false }; static void SetSimulatingButton(Clay_ElementId element, Clay_PointerData pointer, intptr_t data) { if (pointer.state == CLAY_POINTER_DATA_PRESSED_THIS_FRAME) { isSimulating = data == 1; + if (isSimulating) { + simulation::drawDebugInfo = false; + } } } @@ -48,6 +51,67 @@ static void StepControl() { } } +static void DebugInfoLegend() { + CLAY_AUTO_ID(style::PanelContainer(1, { + .layout = { + .padding = { + .left = 20, .right = 0, .top = 0, .bottom = 0 + }, + .childGap = 10, + .layoutDirection = CLAY_TOP_TO_BOTTOM, + } + })) { + CLAY_AUTO_ID({ + .layout = { + .childGap = 10, + }, + }) { + CLAY_AUTO_ID({ + .layout = { + .sizing = { CLAY_SIZING_FIXED(20), CLAY_SIZING_FIXED(20) } + }, + .border = { {255, 0, 255, 255 }, CLAY_BORDER_OUTSIDE(3) } + }); + elements::Body(CLAY_STRING("Underpopulated"), { + .textColor = style::TextColors(0) + }); + } + CLAY_AUTO_ID({ + .layout = { + .childGap = 10, + } + }) { + CLAY_AUTO_ID({ + .layout = { + .sizing = { CLAY_SIZING_FIXED(20), CLAY_SIZING_FIXED(20) } + }, + .border = { {255, 0, 0, 255 }, CLAY_BORDER_OUTSIDE(3) } + }); + elements::Body(CLAY_STRING("Overpopulated"), { + .textColor = style::TextColors(0) + }); + } + CLAY_AUTO_ID({ + .layout = { + .childGap = 10, + } + }) { + CLAY_AUTO_ID({ + .layout = { + .sizing = { CLAY_SIZING_FIXED(20), CLAY_SIZING_FIXED(20) } + }, + .border = { {0, 255, 0, 255 }, CLAY_BORDER_OUTSIDE(3) } + }); + elements::Body(CLAY_STRING("Born"), { + .textColor = style::TextColors(0) + }); + } + elements::Body(CLAY_STRING("Warning: Drawing simulation changes\ngreatly lowers performance"), { + .textColor = style::TextColors(3) + }); + } +} + static void PrimaryControls() { static bool isOpen{ true }; if (isOpen) { @@ -67,12 +131,17 @@ static void PrimaryControls() { }) { StepControl(); if (!isSimulating) { - elements::TextButton(CLAY_STRING("Randomize"), style::actionButton, &RandomizeFieldButton); + CLAY_AUTO_ID(style::PanelContainer(1, {})) { + elements::TextButton(CLAY_STRING("Randomize"), style::actionButton, &RandomizeFieldButton); + } } - elements::Toggle(CLAY_STRING("Debug Info"), style::actionButton, simulation::drawDebugInfo); + elements::Toggle(CLAY_STRING("Show Changes"), style::actionButton, simulation::drawDebugInfo); } } } + if (simulation::drawDebugInfo) { + DebugInfoLegend(); + } } Clay_RenderCommandArray RenderApplication() {