star-sim

Barnes-Hut gravity simulation.
git clone git://git.amin.space/star-sim.git
Log | Files | Refs | README | LICENSE

commit 52b3e15df141ea62f8d66f4bd1cf5266eefb58da
parent dcbbcfe4a96d152f53febe84ed130314e5d80d15
Author: amin <dev@aminmesbah.com>
Date:   Sun,  9 Jul 2017 18:14:57 +0000

Add ability to pause/unpause with the p key.

FossilOrigin-Name: f04add334a3a057d9d3e3c8055be4f51fdeccbb65bfdea79bd7470ee4685a4ea
Diffstat:
Mmain.c | 20++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/main.c b/main.c @@ -26,6 +26,7 @@ bool BRUTE_FORCE = false; bool RENDER_GRID = false; bool RENDER_TRAILS = false; bool RENDER_VIRTUAL_STARS = false; +bool PAUSED = false; #define TITLE "Stars" #define SCREEN_WIDTH 640 @@ -169,6 +170,10 @@ bool handle_event(SDL_Event *event) { RENDER_GRID = !RENDER_GRID; } + if (key_code == SDLK_p) + { + PAUSED = !PAUSED; + } if (key_code == SDLK_t) { RENDER_TRAILS = !RENDER_TRAILS; @@ -419,11 +424,18 @@ int main(void) dimension = sdl_get_window_dimension(window); - while (lag >= MS_PER_UPDATE) + if (PAUSED) + { + lag = 0; + } + else { - update(stars, NUM_STARS, qt); - //printf("\t%" PRIu64 ", %f\n", lag, MS_PER_UPDATE); - lag -= MS_PER_UPDATE; + while (lag >= MS_PER_UPDATE) + { + update(stars, NUM_STARS, qt); + //printf("\t%" PRIu64 ", %f\n", lag, MS_PER_UPDATE); + lag -= MS_PER_UPDATE; + } } if (!RENDER_TRAILS)