Simulation only runs if SPACE is held or PERIOD is pressed.
KEY_SPACE, held, will keep the simulation running. KEY_PERIOD will do exactly one iteration per press.
This commit is contained in:
18
src/main.cpp
18
src/main.cpp
@@ -154,9 +154,9 @@ int main(void)
|
|||||||
std::stringstream format_stream;
|
std::stringstream format_stream;
|
||||||
std::string format_str;
|
std::string format_str;
|
||||||
word_t format_str_width = 0;
|
word_t format_str_width = 0;
|
||||||
Fraction previous_leftmost, previous_rightmost;
|
|
||||||
|
|
||||||
// Setup timer
|
// Setup timer
|
||||||
|
bool is_playing = false;
|
||||||
auto time_current = Clock::now();
|
auto time_current = Clock::now();
|
||||||
auto time_previous = time_current;
|
auto time_previous = time_current;
|
||||||
constexpr auto time_delta = 1;
|
constexpr auto time_delta = 1;
|
||||||
@@ -166,8 +166,9 @@ int main(void)
|
|||||||
{
|
{
|
||||||
// timer logic
|
// timer logic
|
||||||
time_current = Clock::now();
|
time_current = Clock::now();
|
||||||
if (std::chrono::duration_cast<Ms>(time_current - time_previous).count() >=
|
if (is_playing &&
|
||||||
time_delta)
|
std::chrono::duration_cast<Ms>(time_current - time_previous).count() >=
|
||||||
|
time_delta)
|
||||||
{
|
{
|
||||||
time_previous = time_current;
|
time_previous = time_current;
|
||||||
state.do_iteration();
|
state.do_iteration();
|
||||||
@@ -175,7 +176,16 @@ int main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Input logic
|
// Input logic
|
||||||
if (IsKeyPressed(KEY_SPACE))
|
if (IsKeyDown(KEY_SPACE))
|
||||||
|
{
|
||||||
|
is_playing = true;
|
||||||
|
}
|
||||||
|
else if (IsKeyUp(KEY_SPACE))
|
||||||
|
{
|
||||||
|
is_playing = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsKeyPressed(KEY_PERIOD))
|
||||||
{
|
{
|
||||||
state.do_iteration();
|
state.do_iteration();
|
||||||
count += 2;
|
count += 2;
|
||||||
|
|||||||
Reference in New Issue
Block a user