fix: stepping being inconsistent while running

This commit is contained in:
Sara Gerretsen 2025-09-22 21:43:43 +02:00
parent 7c580462b3
commit 1ce447208b

View file

@ -30,13 +30,11 @@ static void StepSimulationButton(Clay_ElementId element, Clay_PointerData pointe
} }
static void StepControl() { static void StepControl() {
static uint64_t lastStep = 0; CLAY_AUTO_ID(style::PanelContainer(1, {
if (isSimulating) { .layout = {
double deltaTime{ (double)(SDL_GetTicks() - lastStep) * 0.001 }; .sizing = { CLAY_SIZING_GROW(), CLAY_SIZING_FIT() },
if (deltaTime > 0.16) { },
simulation::Step(); })) {
}
}
CLAY_AUTO_ID({ CLAY_AUTO_ID({
.layout = { .layout = {
.childGap = 16 .childGap = 16
@ -50,6 +48,7 @@ static void StepControl() {
} }
} }
} }
}
static void DebugInfoLegend() { static void DebugInfoLegend() {
CLAY_AUTO_ID(style::PanelContainer(1, { CLAY_AUTO_ID(style::PanelContainer(1, {
@ -131,7 +130,11 @@ static void PrimaryControls() {
}) { }) {
StepControl(); StepControl();
if (!isSimulating) { if (!isSimulating) {
CLAY_AUTO_ID(style::PanelContainer(1, {})) { CLAY_AUTO_ID(style::PanelContainer(1, {
.layout = {
.sizing = { CLAY_SIZING_GROW(), CLAY_SIZING_FIT() }
}
})) {
elements::TextButton(CLAY_STRING("Randomize"), style::actionButton, &RandomizeFieldButton); elements::TextButton(CLAY_STRING("Randomize"), style::actionButton, &RandomizeFieldButton);
} }
} }
@ -145,6 +148,13 @@ static void PrimaryControls() {
} }
Clay_RenderCommandArray RenderApplication() { Clay_RenderCommandArray RenderApplication() {
static uint64_t lastStep = 0;
if (isSimulating) {
double deltaTime{ (double)(SDL_GetTicks() - lastStep) * 0.001 };
if (deltaTime > 0.16) {
simulation::Step();
}
}
Clay_BeginLayout(); Clay_BeginLayout();
CLAY(CLAY_ID("OuterContainer"), style::Window()) { CLAY(CLAY_ID("OuterContainer"), style::Window()) {
simulation::SetSimulationHovered(Clay_Hovered()); simulation::SetSimulationHovered(Clay_Hovered());