fix: stepping being inconsistent while running
This commit is contained in:
parent
7c580462b3
commit
1ce447208b
|
|
@ -30,23 +30,22 @@ 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) {
|
|
||||||
double deltaTime{ (double)(SDL_GetTicks() - lastStep) * 0.001 };
|
|
||||||
if (deltaTime > 0.16) {
|
|
||||||
simulation::Step();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
CLAY_AUTO_ID({
|
|
||||||
.layout = {
|
.layout = {
|
||||||
.childGap = 16
|
.sizing = { CLAY_SIZING_GROW(), CLAY_SIZING_FIT() },
|
||||||
}
|
},
|
||||||
}) {
|
})) {
|
||||||
if (isSimulating) {
|
CLAY_AUTO_ID({
|
||||||
elements::TextButton(CLAY_STRING("Pause"), style::warningButton, &SetSimulatingButton, false);
|
.layout = {
|
||||||
} else {
|
.childGap = 16
|
||||||
elements::TextButton(CLAY_STRING("Start"), style::proceedButton, &SetSimulatingButton, true);
|
}
|
||||||
elements::TextButton(CLAY_STRING("Step"), style::actionButton, &StepSimulationButton);
|
}) {
|
||||||
|
if (isSimulating) {
|
||||||
|
elements::TextButton(CLAY_STRING("Pause"), style::warningButton, &SetSimulatingButton, false);
|
||||||
|
} else {
|
||||||
|
elements::TextButton(CLAY_STRING("Start"), style::proceedButton, &SetSimulatingButton, true);
|
||||||
|
elements::TextButton(CLAY_STRING("Step"), style::actionButton, &StepSimulationButton);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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());
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue