ref: fb00bf8354efee1847cbec3370f7a34eef745d3a
parent: 59a80b5a902d51d03fb079b0ec5560d450f92731
author: Simon Howard <fraggle@gmail.com>
date: Sat Mar 29 20:24:49 EDT 2014
hexen: Make -playdemo cope with paths. Vanilla Hexen makes you specify the demo name to play by giving the plain lump name, eg. heretic -playdemo mydemo to load mydemo.lmp. It doesn't work if you specify the extension or the full file path. As a convenience and to match the behavior of Chocolate Doom, allow paths and extensions. Also rework the code for other games so that they're slightly more consistent. This fixes #301.
--- a/src/doom/d_main.c
+++ b/src/doom/d_main.c
@@ -1359,6 +1359,8 @@
if (p)
{
+ // With Vanilla you have to specify the file without extension,
+ // but make that optional.
if (M_StringEndsWith(myargv[p + 1], ".lmp"))
{
M_StringCopy(file, myargv[p + 1], sizeof(file));
@@ -1365,7 +1367,7 @@
}
else
{
- snprintf(file, sizeof(file), "%s.lmp", myargv[p+1]);
+ DEH_snprintf(file, sizeof(file), "%s.lmp", myargv[p+1]);
}
if (D_AddFile(file))
@@ -1372,8 +1374,6 @@
{
M_StringCopy(demolumpname, lumpinfo[numlumps - 1].name,
sizeof(demolumpname));
-
- printf("Playing demo %s.\n", file);
}
else
{
@@ -1383,6 +1383,8 @@
M_StringCopy(demolumpname, myargv[p + 1], sizeof(demolumpname));
}
+
+ printf("Playing demo %s.\n", file);
}
I_AtExit((atexit_func_t) G_CheckDemoStatus, true);
--- a/src/heretic/d_main.c
+++ b/src/heretic/d_main.c
@@ -1006,13 +1006,15 @@
if (p)
{
- if (!M_StringEndsWith(myargv[p + 1], ".lmp"))
+ // In Vanilla, the filename must be specified without .lmp,
+ // but make that optional.
+ if (M_StringEndsWith(myargv[p + 1], ".lmp"))
{
- DEH_snprintf(file, sizeof(file), "%s.lmp", myargv[p + 1]);
+ M_StringCopy(file, myargv[p + 1], sizeof(file));
}
else
{
- M_StringCopy(file, myargv[p + 1], sizeof(file));
+ DEH_snprintf(file, sizeof(file), "%s.lmp", myargv[p + 1]);
}
if (D_AddFile(file))
@@ -1019,13 +1021,15 @@
{
M_StringCopy(demolumpname, lumpinfo[numlumps - 1].name,
sizeof(demolumpname));
-
- DEH_printf("Playing demo %s.\n", file);
}
else
{
+ // The file failed to load, but copy the original arg as a
+ // demo name to make tricks like -playdemo demo1 possible.
M_StringCopy(demolumpname, myargv[p + 1], sizeof(demolumpname));
}
+
+ printf("Playing demo %s.\n", file);
}
if (W_CheckNumForName(DEH_String("E2M1")) == -1)
--- a/src/hexen/h2_main.c
+++ b/src/hexen/h2_main.c
@@ -102,6 +102,7 @@
GameMode_t gamemode;
char *iwadfile;
+static char demolumpname[9]; // Demo lump to start playing.
boolean nomonsters; // checkparm of -nomonsters
boolean respawnparm; // checkparm of -respawn
boolean randomclass; // checkparm of -randclass
@@ -382,7 +383,7 @@
if (p)
{
singledemo = true; // Quit after one demo
- G_DeferedPlayDemo(myargv[p + 1]);
+ G_DeferedPlayDemo(demolumpname);
H2_GameLoop(); // Never returns
}
@@ -389,7 +390,7 @@
p = M_CheckParmWithArgs("-timedemo", 1);
if (p)
{
- G_TimeDemo(myargv[p + 1]);
+ G_TimeDemo(demolumpname);
H2_GameLoop(); // Never returns
}
@@ -553,13 +554,26 @@
M_StringCopy(file, myargv[p+1], sizeof(file));
- if (!M_StringEndsWith(file, ".lmp"))
+ // With Vanilla Hexen you have to specify the file without
+ // extension, but make that optional.
+ if (!M_StringEndsWith(myargv[p+1], ".lmp"))
{
M_StringConcat(file, ".lmp", sizeof(file));
}
- W_AddFile(file);
- ST_Message("Playing demo %s.\n", file);
+ if (W_AddFile(file) != NULL)
+ {
+ M_StringCopy(demolumpname, lumpinfo[numlumps - 1].name,
+ sizeof(demolumpname));
+ }
+ else
+ {
+ // The file failed to load, but copy the original arg as a
+ // demo name to make tricks like -playdemo demo1 possible.
+ M_StringCopy(demolumpname, myargv[p+1], sizeof(demolumpname));
+ }
+
+ ST_Message("Playing demo %s.\n", myargv[p+1]);
}
if (M_ParmExists("-testcontrols"))
--- a/src/strife/d_main.c
+++ b/src/strife/d_main.c
@@ -1606,13 +1606,15 @@
if (p)
{
- if (!strcasecmp(myargv[p+1] + strlen(myargv[p+1]) - 4, ".lmp"))
+ // With Vanilla you have to specify the file without extension,
+ // but make that optional.
+ if (M_StringEndsWith(myargv[p + 1], ".lmp"))
{
M_StringCopy(file, myargv[p + 1], sizeof(file));
}
else
{
- snprintf(file, sizeof(file), "%s.lmp", myargv[p+1]);
+ DEH_snprintf(file, sizeof(file), "%s.lmp", myargv[p+1]);
}
if (D_AddFile (file))
@@ -1619,8 +1621,6 @@
{
M_StringCopy(demolumpname, lumpinfo[numlumps - 1].name,
sizeof(demolumpname));
-
- printf("Playing demo %s.\n", file);
}
else
{
@@ -1631,6 +1631,7 @@
M_StringCopy(demolumpname, myargv[p + 1], sizeof(demolumpname));
}
+ printf("Playing demo %s.\n", file);
}
I_AtExit((atexit_func_t) G_CheckDemoStatus, true);