Skip to content

Commit

Permalink
watchdog: return to main menu and reset config after inactivity in ki…
Browse files Browse the repository at this point in the history
…osk mode
  • Loading branch information
Akaricchi committed May 4, 2024
1 parent 0b2280b commit 5d82a42
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/cutscenes/cutscene.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@
#include "video.h"
#include "eventloop/eventloop.h"
#include "replay/demoplayer.h"
#include "watchdog.h"

#define SKIP_DELAY 3
#define AUTO_ADVANCE_TIME_BEFORE_TEXT FPS * 2
#define AUTO_ADVANCE_TIME_MID_SCENE FPS * 20
#define AUTO_ADVANCE_TIME_CROSS_SCENE FPS * 180

// TODO maybe make transitions configurable?
#define CUTSCENE_FADE_OUT 200
enum {
CUTSCENE_FADE_OUT = 200,
CUTSCENE_INTERRUPT_FADE_OUT = 15,
};

typedef struct CutsceneBGState {
Texture *scene;
Expand Down Expand Up @@ -118,8 +122,12 @@ static bool skip_text_animation(CutsceneState *st) {
return animation_skipped;
}

static void begin_fadeout(CutsceneState *st) {
const int fade_frames = CUTSCENE_FADE_OUT;
static void begin_fadeout(CutsceneState *st, int fade_frames) {
if(st->fadeout_timer) {
log_debug("Already fading out, timer = %i", st->fadeout_timer);
return;
}

audio_bgm_stop((FPS * fade_frames) / 4000.0);
set_transition(TransFadeBlack, fade_frames, fade_frames, NO_CALLCHAIN);
st->fadeout_timer = fade_frames;
Expand Down Expand Up @@ -148,7 +156,7 @@ static void cutscene_advance(CutsceneState *st) {

if((++st->phase)->background == NULL) {
st->phase = NULL;
begin_fadeout(st);
begin_fadeout(st, CUTSCENE_FADE_OUT);
} else {
switch_bg(st, st->phase->background);
}
Expand All @@ -166,6 +174,10 @@ static void cutscene_advance(CutsceneState *st) {
reset_timers(st);
}

static void cutscene_interrupt(CutsceneState *st) {
begin_fadeout(st, CUTSCENE_INTERRUPT_FADE_OUT);
}

static bool cutscene_event(SDL_Event *evt, void *ctx) {
CutsceneState *st = ctx;

Expand All @@ -179,6 +191,10 @@ static bool cutscene_event(SDL_Event *evt, void *ctx) {
static LogicFrameAction cutscene_logic_frame(void *ctx) {
CutsceneState *st = ctx;

if(watchdog_signaled()) {
cutscene_interrupt(st);
}

update_transition();
events_poll((EventHandler[]) {
{ .proc = cutscene_event, .arg = st, .priority = EPRIO_NORMAL },
Expand Down
2 changes: 2 additions & 0 deletions src/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ typedef enum {

TE_FILEWATCH,

TE_WATCHDOG,

NUM_TAISEI_EVENTS
} TaiseiEvent;

Expand Down
22 changes: 22 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
#include "eventloop/eventloop.h"
#include "replay/demoplayer.h"
#include "replay/tsrtool.h"
#include "watchdog.h"

static bool watchdog_handler(SDL_Event *evt, void *arg) {
assert(evt->type == MAKE_TAISEI_EVENT(TE_WATCHDOG));
config_reset();
return true;
}

attr_unused
static void taisei_shutdown(void) {
Expand All @@ -48,6 +55,11 @@ static void taisei_shutdown(void) {
r_release_resources();
res_shutdown();

if(global.is_kiosk_mode) {
events_unregister_handler(watchdog_handler);
}

watchdog_shutdown();
demoplayer_shutdown();
progress_unload();
stage_objpools_shutdown();
Expand Down Expand Up @@ -380,6 +392,16 @@ static void main_post_vfsinit(CallChainResult ccr) {
time_init();
init_global(&ctx->cli);
events_init();

if(global.is_kiosk_mode) {
watchdog_init(env_get("TAISEI_KIOSK_TIMEOUT", 60 * FPS));
events_register_handler(&(EventHandler) {
.priority = EPRIO_SYSTEM,
.event_type = MAKE_TAISEI_EVENT(TE_WATCHDOG),
.proc = watchdog_handler,
});
}

video_init(&(VideoInitParams) {
.width = ctx->cli.width,
.height = ctx->cli.height,
Expand Down
7 changes: 7 additions & 0 deletions src/menu/mainmenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "stage.h"
#include "version.h"
#include "plrmodes.h"
#include "watchdog.h"

static MenuEntry *spell_practice_entry;
static MenuEntry *stage_practice_entry;
Expand Down Expand Up @@ -65,6 +66,12 @@ static void begin_main_menu(MenuData *m) {
}

static void update_main_menu(MenuData *menu) {
if(watchdog_signaled()) {
menu->cursor = 0;
}

watchdog_reset();

menu->drawdata[1] += 0.1*(menu->cursor-menu->drawdata[1]);

dynarray_foreach(&menu->entries, int i, MenuEntry *e, {
Expand Down
6 changes: 6 additions & 0 deletions src/menu/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "eventloop/eventloop.h"
#include "replay/demoplayer.h"
#include "util/graphics.h"
#include "watchdog.h"

MenuEntry *add_menu_entry(MenuData *menu, const char *name, MenuAction action, void *arg) {
return dynarray_append(&menu->entries, {
Expand Down Expand Up @@ -201,6 +202,11 @@ static LogicFrameAction menu_logic_frame(void *arg) {

menu->frames++;

if(watchdog_signaled()) {
menu->selected = -1;
close_menu(menu);
}

if(menu->state != MS_FadeOut || menu->flags & MF_AlwaysProcessInput) {
assert(menu->input);
menu->input(menu);
Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ taisei_src = files(
'version.c',
'video.c',
'video_postprocess.c',
'watchdog.c',
)

if is_developer_build
Expand Down
5 changes: 5 additions & 0 deletions src/stage.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "common_tasks.h"
#include "stageinfo.h"
#include "dynstage.h"
#include "watchdog.h"

typedef struct StageFrameState {
StageInfo *stage;
Expand Down Expand Up @@ -948,6 +949,10 @@ static LogicFrameAction stage_logic_frame(void *arg) {

stage_update_fps(fstate);

if(watchdog_signaled() && !stage_is_demo_mode()) {
global.gameover = GAMEOVER_ABORT;
}

if(stage_is_skip_mode()) {
global.plr.iddqd = true;
}
Expand Down

0 comments on commit 5d82a42

Please sign in to comment.