From 2e367845750452436f2cd7b4b48856079cc396ed Mon Sep 17 00:00:00 2001 From: helixhorned Date: Mon, 24 Sep 2012 21:09:27 +0000 Subject: [PATCH] Add the option of starting demo profiling from the command line. EDuke32 will exit afterwards. git-svn-id: https://svn.eduke32.com/eduke32@3024 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/demo.c | 16 ++++++++++++---- polymer/eduke32/source/demo.h | 2 +- polymer/eduke32/source/game.c | 29 ++++++++++++++++++++++++++++- polymer/eduke32/source/osdcmds.c | 2 +- 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/polymer/eduke32/source/demo.c b/polymer/eduke32/source/demo.c index 7f5bad2b5..f334c5390 100644 --- a/polymer/eduke32/source/demo.c +++ b/polymer/eduke32/source/demo.c @@ -229,9 +229,11 @@ error_wopen_demo: // demo_profile: < 0: prepare static int32_t g_demo_playFirstFlag, g_demo_profile, g_demo_stopProfile; -void Demo_PlayFirst(int32_t prof) +static int32_t g_demo_exitAfter; +void Demo_PlayFirst(int32_t prof, int32_t exitafter) { g_demo_playFirstFlag = 1; + g_demo_exitAfter = exitafter; Bassert(prof >= 0); g_demo_profile = -prof; // prepare } @@ -449,8 +451,9 @@ static void Demo_FinishProfile(void) { double totalprofms = gms+dms1+dms2; double totalms = gethitickms()-g_prof.starthitickms; - OSD_Printf("== demo %d: non-profiled time overhead: %.02f %%\n", - dn, 100.0*totalms/totalprofms - 100.0); + if (totalprofms != 0) + OSD_Printf("== demo %d: non-profiled time overhead: %.02f %%\n", + dn, 100.0*totalms/totalprofms - 100.0); } } @@ -469,9 +472,14 @@ int32_t G_PlaybackDemo(void) if (ready2send) return 0; - g_demo_profile = 0; + if (!g_demo_playFirstFlag) + g_demo_profile = 0; RECHECK: + if (g_demo_playFirstFlag) + g_demo_playFirstFlag = 0; + else if (g_demo_exitAfter) + G_GameExit(" "); #if KRANDDEBUG if (foundemo) diff --git a/polymer/eduke32/source/demo.h b/polymer/eduke32/source/demo.h index 57b7852ed..96c012e68 100644 --- a/polymer/eduke32/source/demo.h +++ b/polymer/eduke32/source/demo.h @@ -48,7 +48,7 @@ void G_CloseDemoWrite(void); void G_DemoRecord(void); void G_OpenDemoWrite(void); -void Demo_PlayFirst(int32_t prof); +void Demo_PlayFirst(int32_t prof, int32_t exitafter); int32_t Demo_IsProfiling(void); diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index ec7b5542b..6d4378126 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -8943,10 +8943,37 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) ud.m_coop--; break; case 'd': + { + char *colon = Bstrchr(c, ':'); + int32_t framespertic=-1, numrepeats=1; + c++; + + if (colon && colon != c) + { + // -d:[,] + // profiling options + *(colon++) = 0; + Bsscanf(colon, "%u,%u", &framespertic, &numrepeats); + } + maybe_append_ext(g_firstDemoFile, sizeof(g_firstDemoFile), c, ".edm"); - initprintf("Play demo %s.\n",g_firstDemoFile); + + if (framespertic < 0) + { + initprintf("Play demo %s.\n", g_firstDemoFile); + } + else + { + framespertic = clamp(framespertic, 0, 8)+1; + // TODO: repeat count and gathering statistics. + initprintf("Profile demo %s, %d frames/gametic, repeated 1x.\n", g_firstDemoFile, + framespertic-1); + Demo_PlayFirst(framespertic, 1); + g_noLogo = 1; + } break; + } case 'g': c++; if (*c) diff --git a/polymer/eduke32/source/osdcmds.c b/polymer/eduke32/source/osdcmds.c index d105398be..134e4677b 100644 --- a/polymer/eduke32/source/osdcmds.c +++ b/polymer/eduke32/source/osdcmds.c @@ -332,7 +332,7 @@ static int32_t osdcmd_demo(const osdfuncparm_t *parm) else // demo file name passed maybe_append_ext(g_firstDemoFile, sizeof(g_firstDemoFile), parm->parms[0], ".edm"); - Demo_PlayFirst(clamp(prof, -1, 8)+1); + Demo_PlayFirst(clamp(prof, -1, 8)+1, 0); } return OSDCMD_OK;