diff --git a/src/d_main.c b/src/d_main.c index 225a43b3..52eda4fb 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1821,7 +1821,7 @@ int demowarp = -1; void D_DoomMain(void) { - int p, slot; + int p; setbuf(stdout,NULL); @@ -2569,19 +2569,24 @@ void D_DoomMain(void) // Support -loadgame with -record and reimplement -recordfrom. //! - // @arg + // @arg // @category demo // - // Records a demo starting from a saved game. It is the same as "-loadgame - // -record ". "-loadgame -playdemo " plays back the - // demo starting from the saved game. + // Record a demo, loading from the given filename. Equivalent to -loadgame + // -record . // - if ((slot = M_CheckParm("-recordfrom")) && (p = slot+2) < myargc) - G_RecordDemo(myargv[p]); + p = M_CheckParmWithArgs("-recordfrom", 2); + if (p) + { + startloadgame = M_ParmArgToInt(p); + G_RecordDemo(myargv[p + 2]); + } else { - slot = M_CheckParm("-loadgame"); + p = M_CheckParmWithArgs("-loadgame", 1); + if (p) + startloadgame = M_ParmArgToInt(p); //! // @arg @@ -2627,11 +2632,6 @@ void D_DoomMain(void) demoskip_tics = -1; } - if (slot && ++slot < myargc) - { - startloadgame = atoi(myargv[slot]); - } - // [FG] init graphics (WIDESCREENDELTA) before HUD widgets I_InitGraphics(); diff --git a/src/g_game.c b/src/g_game.c index 52cfeaeb..524fff82 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -1699,6 +1699,7 @@ static void G_LoadGameErr(const char *msg) M_ForcedLoadGame(msg); // Print message asking for 'Y' to force if (command_loadgame) // If this was a command-line -loadgame { + G_CheckDemoStatus(); // If there was also a -record D_StartTitle(); // Start the title screen gamestate = GS_DEMOSCREEN; // And set the game state accordingly } @@ -3759,6 +3760,10 @@ boolean G_CheckDemoStatus(void) if (demorecording) { demorecording = false; + + if (!demo_p) + return false; + *demo_p++ = DEMOMARKER; G_AddDemoFooter(); diff --git a/src/m_argv.c b/src/m_argv.c index 7752cc6d..3ccc6420 100644 --- a/src/m_argv.c +++ b/src/m_argv.c @@ -98,7 +98,25 @@ int M_ParmArg2ToInt(int p) #if defined(HAVE_PARAMS_GEN) #include "params.h" -static int CheckArgs(int p, int num_args) +static int CheckArgs(int p) +{ + int i; + + ++p; + + for (i = p; i < myargc; ++i) + { + if (myargv[i][0] == '-') + break; + } + + if (i > p) + return i; + + return 0; +} + +static int CheckNumArgs(int p, int num_args) { int i; @@ -110,7 +128,7 @@ static int CheckArgs(int p, int num_args) break; } - if (i > p) + if (i == p + num_args) return i; return 0; @@ -123,7 +141,7 @@ void M_CheckCommandLine(void) while (p < myargc) { int i; - int args = -1; + int args = 0; for (i = 0; i < arrlen(params_with_args); ++i) { @@ -131,7 +149,7 @@ void M_CheckCommandLine(void) !strcasecmp(myargv[p], "-deh") || !strcasecmp(myargv[p], "-bex")) { - args = myargc; + args = -1; break; } else if (!strcasecmp(myargv[p], "-warp") || @@ -147,14 +165,23 @@ void M_CheckCommandLine(void) } } - if (args > 0) + if (args) { - int check = CheckArgs(p, args); + int check = args > 0 ? CheckNumArgs(p, args) : CheckArgs(p); if (check) { p = check; } + // -warp can have only one parameter + else if (!strcasecmp(myargv[p], "-warp")) + { + check = CheckNumArgs(p, 1); + if (!check) + I_Error("No parameter for '-warp'."); + else + p = check; + } // -turbo has default value else if (!strcasecmp(myargv[p], "-turbo")) {