cli: add --populate-cache

Searches the VFS for resources and attempts to load them all, then
exits. Intended to fully populate the persistent cache.
This commit is contained in:
Andrei Alexeyev 2023-05-08 04:23:08 +02:00
parent d21e81e7b6
commit e6fffc6b5f
No known key found for this signature in database
GPG key ID: 72D26128040B9690
3 changed files with 17 additions and 3 deletions

View file

@ -28,6 +28,7 @@ enum {
OPT_CUTSCENE_LIST,
OPT_FORCE_INTRO,
OPT_REREPLAY,
OPT_POPCACHE,
};
static void print_help(struct TsOption* opts) {
@ -92,6 +93,7 @@ int cli_args(int argc, char **argv, CLIAction *a) {
{{"frameskip", optional_argument, 0, 'f'}, "Disable FPS limiter, render only every %s frame", "FRAME"},
{{"credits", no_argument, 0, 'c'}, "Show the credits scene and exit"},
{{"renderer", required_argument, 0, OPT_RENDERER}, "Choose the rendering backend", renderer_list},
{{"populate-cache", no_argument, 0, OPT_POPCACHE}, "Attempt to load all available resources, populating the cache, then exit"},
{{"help", no_argument, 0, 'h'}, "Print help and exit"},
{{"version", no_argument, 0, 'v'}, "Print version and exit"},
{ 0 }
@ -246,6 +248,10 @@ int cli_args(int argc, char **argv, CLIAction *a) {
case 'v':
tsfprintf(stdout, "%s %s\n", TAISEI_VERSION_FULL, TAISEI_VERSION_BUILD_TYPE);
exit(0);
case OPT_POPCACHE:
env_set("TAISEI_AGGRESSIVE_PRELOAD", 1, true);
a->type = CLI_QuitLate;
break;
default:
UNREACHABLE;
}

View file

@ -19,6 +19,7 @@ typedef enum {
CLI_DumpStages,
CLI_DumpVFSTree,
CLI_Quit,
CLI_QuitLate,
CLI_Credits,
CLI_Cutscene,
} CLIActionType;

View file

@ -400,13 +400,20 @@ static void main_post_vfsinit(CallChainResult ccr) {
atexit(taisei_shutdown);
#endif
CallChain cc_cleanup = CALLCHAIN(main_cleanup, ctx);
if(ctx->cli.type == CLI_QuitLate) {
run_call_chain(&cc_cleanup, NULL);
return;
}
if(ctx->cli.type == CLI_PlayReplay || ctx->cli.type == CLI_VerifyReplay) {
main_replay(ctx);
return;
}
if(ctx->cli.type == CLI_Credits) {
credits_enter(CALLCHAIN(main_cleanup, ctx));
credits_enter(cc_cleanup);
eventloop_run();
return;
}
@ -420,14 +427,14 @@ static void main_post_vfsinit(CallChainResult ccr) {
}
if(ctx->cli.type == CLI_Cutscene) {
cutscene_enter(CALLCHAIN(main_cleanup, ctx), ctx->cli.cutscene);
cutscene_enter(cc_cleanup, ctx->cli.cutscene);
eventloop_run();
return;
}
#endif
if(!progress_is_cutscene_unlocked(CUTSCENE_ID_INTRO) || ctx->cli.force_intro) {
cutscene_enter(CALLCHAIN(main_mainmenu, ctx), CUTSCENE_ID_INTRO);
cutscene_enter(cc_cleanup, CUTSCENE_ID_INTRO);
eventloop_run();
return;
}