diff --git a/src/twn_loop.c b/src/twn_loop.c index eecdf36..396c3ab 100644 --- a/src/twn_loop.c +++ b/src/twn_loop.c @@ -193,9 +193,9 @@ static bool initialize(void) { return false; } - /* TODO: recognize cli parameter to turn it on on release */ - /* debug mode _defaults_ to being enabled on debug builds. */ - /* you should be able to enable it at runtime on any build */ + /* debug mode defaults to being enabled on debug builds. */ + /* pass --debug to enable it on release builds */ + /* or, on debug builds, pass --release to disable it */ #ifndef NDEBUG ctx.game.debug = true; #else @@ -403,12 +403,33 @@ int enter_loop(int argc, char **argv) { if (!initialize()) 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 (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)) { CRY_PHYSFS("Data dir mount override failed."); 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; } }