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 uint64_t lastStep = 0;
if (isSimulating) {
double deltaTime{ (double)(SDL_GetTicks() - lastStep) * 0.001 };
if (deltaTime > 0.16) {
simulation::Step();
}
}
CLAY_AUTO_ID(style::PanelContainer(1, {
.layout = {
.sizing = { CLAY_SIZING_GROW(), CLAY_SIZING_FIT() },
},
})) {
CLAY_AUTO_ID({
.layout = {
.childGap = 16
@ -50,6 +48,7 @@ static void StepControl() {
}
}
}
}
static void DebugInfoLegend() {
CLAY_AUTO_ID(style::PanelContainer(1, {
@ -131,7 +130,11 @@ static void PrimaryControls() {
}) {
StepControl();
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);
}
}
@ -145,6 +148,13 @@ static void PrimaryControls() {
}
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(CLAY_ID("OuterContainer"), style::Window()) {
simulation::SetSimulationHovered(Clay_Hovered());