feat: implemented automatic stepping
This commit is contained in:
parent
266ff5de0b
commit
8b2b0ac34e
|
|
@ -6,13 +6,11 @@
|
|||
#include <clay/clay.h>
|
||||
|
||||
namespace application {
|
||||
namespace internal {
|
||||
bool isSimulating{ false };
|
||||
}
|
||||
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) {
|
||||
internal::isSimulating = data == 1;
|
||||
isSimulating = data == 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -29,12 +27,19 @@ 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({
|
||||
.layout = {
|
||||
.childGap = 16
|
||||
}
|
||||
}) {
|
||||
if (internal::isSimulating) {
|
||||
if (isSimulating) {
|
||||
elements::TextButton(CLAY_STRING("Pause"), style::warningButton, &SetSimulatingButton, false);
|
||||
} else {
|
||||
elements::TextButton(CLAY_STRING("Start"), style::proceedButton, &SetSimulatingButton, true);
|
||||
|
|
@ -61,11 +66,13 @@ static void PrimaryControls() {
|
|||
}
|
||||
}) {
|
||||
StepControl();
|
||||
if (!isSimulating) {
|
||||
elements::TextButton(CLAY_STRING("Randomize"), style::actionButton, &RandomizeFieldButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Clay_RenderCommandArray RenderApplication() {
|
||||
Clay_BeginLayout();
|
||||
|
|
|
|||
Loading…
Reference in a new issue