twn_loop.c: add --debug and --release overrides, fix incorrect argv iteration

This commit is contained in:
wanp 2024-09-26 20:48:42 -03:00
parent 64d1c20b4a
commit 0e68ecbc88

View File

@ -193,9 +193,9 @@ static bool initialize(void) {
return false; return false;
} }
/* TODO: recognize cli parameter to turn it on on release */ /* debug mode defaults to being enabled on debug builds. */
/* debug mode _defaults_ to being enabled on debug builds. */ /* pass --debug to enable it on release builds */
/* you should be able to enable it at runtime on any build */ /* or, on debug builds, pass --release to disable it */
#ifndef NDEBUG #ifndef NDEBUG
ctx.game.debug = true; ctx.game.debug = true;
#else #else
@ -403,12 +403,33 @@ int enter_loop(int argc, char **argv) {
if (!initialize()) if (!initialize())
return EXIT_FAILURE; return EXIT_FAILURE;
for (int i = 1; i < (argc - 1); ++i) { /* process arguments */
for (int i = 1; i < argc; ++i) {
/* override data directory */
if (SDL_strcmp(argv[i], "--data-dir") == 0) { if (SDL_strcmp(argv[i], "--data-dir") == 0) {
if (argv[i+1] == NULL || SDL_strncmp(argv[i+1], "--", 2) == 0) {
CRY("Data dir mount override failed.", "No arguments passed (expected 1).");
return EXIT_FAILURE;
}
if (!PHYSFS_mount(argv[i+1], NULL, true)) { if (!PHYSFS_mount(argv[i+1], NULL, true)) {
CRY_PHYSFS("Data dir mount override failed."); CRY_PHYSFS("Data dir mount override failed.");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
continue;
}
/* force debug mode */
if (SDL_strcmp(argv[i], "--debug") == 0) {
ctx.game.debug = true;
continue;
}
/* force release mode */
if (SDL_strcmp(argv[i], "--release") == 0) {
ctx.game.debug = false;
continue;
} }
} }