From 13599f56b8ec4d7db1c8672d6d11aa6844fdebc0 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Mon, 1 Oct 2012 17:52:40 +0000 Subject: [PATCH] In -d command line arg, allow specifying demo number in addition to file name. git-svn-id: https://svn.eduke32.com/eduke32@3045 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/demo.c | 19 +++++++++++++++---- polymer/eduke32/source/demo.h | 4 ++++ polymer/eduke32/source/game.c | 4 ++-- polymer/eduke32/source/osdcmds.c | 9 +-------- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/polymer/eduke32/source/demo.c b/polymer/eduke32/source/demo.c index e8e310380..4a7158efc 100644 --- a/polymer/eduke32/source/demo.c +++ b/polymer/eduke32/source/demo.c @@ -90,7 +90,7 @@ static int32_t G_OpenDemoRead(int32_t g_whichDemo) // 0 = mine } else { - Bsprintf(demofn, "edemo%03d.edm", g_whichDemo); + Bsprintf(demofn, DEMOFN_FMT, g_whichDemo); demofnptr = demofn; } @@ -175,10 +175,10 @@ void G_OpenDemoWrite(void) do { - if (demonum == 1000) + if (demonum == MAXDEMOS) return; - if (G_ModDirSnprintf(demofn, sizeof(demofn), "edemo%03d.edm", demonum)) + if (G_ModDirSnprintf(demofn, sizeof(demofn), DEMOFN_FMT, demonum)) { initprintf("Couldn't start demo writing: INTERNAL ERROR: file name too long\n"); goto error_wopen_demo; @@ -238,6 +238,17 @@ void Demo_PlayFirst(int32_t prof, int32_t exitafter) g_demo_profile = -prof; // prepare } +void Demo_SetFirst(const char *demostr) +{ + char *tailptr; + int32_t i = Bstrtol(demostr, &tailptr, 10); + + if (tailptr==demostr+Bstrlen(demostr) && (unsigned)i < MAXDEMOS) // demo number passed + Bsprintf(g_firstDemoFile, DEMOFN_FMT, i); + else // demo file name passed + maybe_append_ext(g_firstDemoFile, sizeof(g_firstDemoFile), demostr, ".edm"); +} + static uint8_t g_demo_seedbuf[RECSYNCBUFSIZ]; @@ -520,7 +531,7 @@ RECHECK: ud.recstat = 2; g_whichDemo++; - if (g_whichDemo == 1000) + if (g_whichDemo == MAXDEMOS) g_whichDemo = 1; g_player[myconnectindex].ps->gm &= ~MODE_GAME; diff --git a/polymer/eduke32/source/demo.h b/polymer/eduke32/source/demo.h index 96c012e68..3c759b454 100644 --- a/polymer/eduke32/source/demo.h +++ b/polymer/eduke32/source/demo.h @@ -23,6 +23,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef __demo_h__ #define __demo_h__ +#define DEMOFN_FMT "edemo%03d.edm" +#define MAXDEMOS 1000 + extern FILE *g_demo_filePtr; extern char g_firstDemoFile[BMAX_PATH]; @@ -49,6 +52,7 @@ void G_DemoRecord(void); void G_OpenDemoWrite(void); void Demo_PlayFirst(int32_t prof, int32_t exitafter); +void Demo_SetFirst(const char *demostr); int32_t Demo_IsProfiling(void); diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 29673f272..3c9632277 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -8075,7 +8075,7 @@ static void G_ShowParameterHelp(void) #endif "-connect [host]\tConnect to a multiplayer game\n" "-c#\t\tUse MP mode #, 1 = Dukematch, 2 = Coop, 3 = Dukematch(no spawn)\n" - "-d[file.edm]\tPlay a demo\n" + "-d[file.edm or demonum]\tPlay a demo\n" "-g[file.grp]\tLoad additional game data\n" "-h[file.def]\tLoad an alternate definitions file\n" "-j[dir]\t\tAdds a directory to EDuke32's search list\n" @@ -8957,7 +8957,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) Bsscanf(colon, "%u,%u", &framespertic, &numrepeats); } - maybe_append_ext(g_firstDemoFile, sizeof(g_firstDemoFile), c, ".edm"); + Demo_SetFirst(c); if (framespertic < 0) { diff --git a/polymer/eduke32/source/osdcmds.c b/polymer/eduke32/source/osdcmds.c index 134e4677b..e9555f499 100644 --- a/polymer/eduke32/source/osdcmds.c +++ b/polymer/eduke32/source/osdcmds.c @@ -322,16 +322,9 @@ static int32_t osdcmd_demo(const osdfuncparm_t *parm) return OSDCMD_SHOWHELP; { - char *tailptr; - const char *demostr = parm->parms[0]; - int32_t i = Bstrtol(demostr, &tailptr, 10); int32_t prof = parm->numparms==2 ? Batoi(parm->parms[1]) : -1; - if (tailptr!=demostr && i>=0 && i<=999) // demo number passed - Bsprintf(g_firstDemoFile, "edemo%03d.edm", i); - else // demo file name passed - maybe_append_ext(g_firstDemoFile, sizeof(g_firstDemoFile), parm->parms[0], ".edm"); - + Demo_SetFirst(parm->parms[0]); Demo_PlayFirst(clamp(prof, -1, 8)+1, 0); }