diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2023-10-14 00:25:32 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2023-10-14 00:25:32 -0700 |
commit | 3e6bcb386cc9df28990b9cd570f6df7617e91f91 (patch) | |
tree | 0f5c01f4a98727b0adb9b733c8ff631117e473df | |
parent | 723dc1a9bd275bb314a5e2d2673ed0ea84fee330 (diff) |
sars,hungrycat: add --wait flag
This tells sars to just wait indefinitely until an ESC is pressed
pre-fadein during the opening hungrycat context.
The --delay [seconds] flag was added to facilitate screen
captures, but it's actually rather annoying to use. This way the
sars window will just sit there ignoring any spurious events
waiting for an ESC to proceed onto DELAY->FADEIN...
Probably not useful but technically this composes with --delay as
well, such that if you have --delay and --wait specified, once
you hit ESC to leave the WAIT state, the delay will then begin.
-rw-r--r-- | src/hungrycat.c | 21 | ||||
-rw-r--r-- | src/sars.c | 4 | ||||
-rw-r--r-- | src/sars.h | 1 |
3 files changed, 22 insertions, 4 deletions
diff --git a/src/hungrycat.c b/src/hungrycat.c index d31b8e3..41474ef 100644 --- a/src/hungrycat.c +++ b/src/hungrycat.c @@ -36,6 +36,7 @@ #define HUNGRYCAT_FADE_TIMER PLAY_TICKS_TIMER0 typedef enum hungrycat_state_t { + HUNGRYCAT_STATE_WAIT, HUNGRYCAT_STATE_DELAY, HUNGRYCAT_STATE_FADEIN, HUNGRYCAT_STATE_SHOW, @@ -71,9 +72,13 @@ static void * hungrycat_init(play_t *play, int argc, char *argv[], unsigned flag static void hungrycat_enter(play_t *play, void *context) { hungrycat_t *hungrycat = context; + sars_t *sars = play_context(play, SARS_CONTEXT_SARS); assert(hungrycat); + if (!sars->wait) + hungrycat->state = HUNGRYCAT_STATE_DELAY; + play_ticks_reset(play, HUNGRYCAT_FADE_TIMER); } @@ -92,6 +97,11 @@ static void hungrycat_update(play_t *play, void *context) assert(hungrycat); switch (hungrycat->state) { + case HUNGRYCAT_STATE_WAIT: + /* just wait indefinitely until an ESC is pressed (see hungrycat_dispatch()) */ + stage_dirty(hungrycat->node); + break; + case HUNGRYCAT_STATE_DELAY: stage_dirty(hungrycat->node); if (!play_ticks_elapsed(play, HUNGRYCAT_FADE_TIMER, sars->delay_seconds * 1000)) @@ -168,11 +178,16 @@ static void hungrycat_dispatch(play_t *play, void *context, SDL_Event *event) switch (event->type) { case SDL_KEYDOWN: - if (event->key.keysym.sym == SDLK_ESCAPE) - exit(0); + if (event->key.keysym.sym == SDLK_ESCAPE) { + if (hungrycat->state != HUNGRYCAT_STATE_WAIT) + exit(0); + + hungrycat->state = HUNGRYCAT_STATE_DELAY; + } /* fallthrough */ case SDL_FINGERDOWN: - if (hungrycat->state != HUNGRYCAT_STATE_DELAY) + if (hungrycat->state != HUNGRYCAT_STATE_WAIT && + hungrycat->state != HUNGRYCAT_STATE_DELAY) play_context_enter(play, SARS_CONTEXT_GAME); break; @@ -260,10 +260,12 @@ static int sars_parse_argv(sars_t *sars, int argc, char *argv[]) sars->delay_seconds = SARS_DEFAULT_DELAY_SECS; if (i + 1 < argc && argv[i + 1][0] != '-' && argv[i + 1][1] != '-') { - /* --wait SECONDS is optionally supported */ + /* --delay SECONDS is optionally supported */ sscanf(argv[i + 1], "%u", &sars->delay_seconds); /* FIXME: parse errors */ i++; } + } else if (!strcmp(flag, "--wait")) { + sars->wait = 1; } else { warn_if(1, "Unsupported flag \"%s\", ignoring", argv[i]); } /* TODO: add --fullscreen? */ @@ -44,6 +44,7 @@ typedef struct sars_t { unsigned window_width, window_height; sars_winmode_t winmode; unsigned cheat:1; + unsigned wait:1; unsigned delay_seconds; m4f_t projection_x; |