From 1ec5afe3509e9258bf59ddda46402fab276c4667 Mon Sep 17 00:00:00 2001 From: leflores Date: Fri, 17 Feb 2023 17:19:33 -0500 Subject: [PATCH 1/2] Use stdbool --- main.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/main.c b/main.c index a3f79bc..19a910d 100644 --- a/main.c +++ b/main.c @@ -2,10 +2,11 @@ #include #include #include +#include #include #include -#include +#include #include "./digits.h" @@ -155,14 +156,14 @@ int main(int argc, char **argv) { Mode mode = MODE_ASCENDING; float displayed_time = 0.0f; - int paused = 0; - int exit_after_countdown = 0; + bool paused = false; + bool exit_after_countdown = false; for (int i = 1; i < argc; ++i) { if (strcmp(argv[i], "-p") == 0) { - paused = 1; + paused = true; } else if (strcmp(argv[i], "-e") == 0) { - exit_after_countdown = 1; + exit_after_countdown = true; } else if (strcmp(argv[i], "clock") == 0) { mode = MODE_CLOCK; } else { @@ -195,7 +196,7 @@ int main(int argc, char **argv) secc(SDL_SetTextureColorMod(digits, MAIN_COLOR_R, MAIN_COLOR_G, MAIN_COLOR_B)); } - int quit = 0; + bool quit = false; size_t wiggle_index = 0; float wiggle_cooldown = WIGGLE_DURATION; float user_scale = 1.0f; @@ -206,7 +207,7 @@ int main(int argc, char **argv) while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: { - quit = 1; + quit = true; } break; case SDL_KEYDOWN: { @@ -237,10 +238,10 @@ int main(int argc, char **argv) case SDLK_F5: { displayed_time = 0.0f; - paused = 0; + paused = false; for (int i = 1; i < argc; ++i) { if (strcmp(argv[i], "-p") == 0) { - paused = 1; + paused = true; } else { displayed_time = parse_time(argv[i]); } From 3fe0325266fb608b73df0621b097ee22f2926767 Mon Sep 17 00:00:00 2001 From: leflores Date: Sat, 18 Feb 2023 02:31:45 -0500 Subject: [PATCH 2/2] Fix bad on restart --- main.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/main.c b/main.c index 19a910d..4174be9 100644 --- a/main.c +++ b/main.c @@ -6,7 +6,7 @@ #include #include -#include +#include #include "./digits.h" @@ -156,6 +156,7 @@ int main(int argc, char **argv) { Mode mode = MODE_ASCENDING; float displayed_time = 0.0f; + float start_time = 0.0f; bool paused = false; bool exit_after_countdown = false; @@ -168,7 +169,8 @@ int main(int argc, char **argv) mode = MODE_CLOCK; } else { mode = MODE_COUNTDOWN; - displayed_time = parse_time(argv[i]); + start_time = parse_time(argv[i]); + displayed_time = start_time; } } @@ -237,20 +239,10 @@ int main(int argc, char **argv) } break; case SDLK_F5: { - displayed_time = 0.0f; - paused = false; - for (int i = 1; i < argc; ++i) { - if (strcmp(argv[i], "-p") == 0) { - paused = true; - } else { - displayed_time = parse_time(argv[i]); - } - } - if (paused) { - secc(SDL_SetTextureColorMod(digits, PAUSE_COLOR_R, PAUSE_COLOR_G, PAUSE_COLOR_B)); - } else { - secc(SDL_SetTextureColorMod(digits, MAIN_COLOR_R, MAIN_COLOR_G, MAIN_COLOR_B)); + if (mode == MODE_CLOCK) { + break; } + displayed_time = start_time; } break; case SDLK_F11: {