From 8fba52a2bb9aaf25a27cd3181e6bfb1ef16995ac Mon Sep 17 00:00:00 2001 From: helixhorned Date: Sat, 8 Sep 2012 22:18:37 +0000 Subject: [PATCH] New OSD cmd: demo , starting one instantly from the menu. Also, correct some comments made in the demo source made earlier. Oops. git-svn-id: https://svn.eduke32.com/eduke32@3006 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/demo.c | 28 +++++++++++++++++--- polymer/eduke32/source/demo.h | 2 ++ polymer/eduke32/source/osdcmds.c | 44 ++++++++++++++++++++++++++------ 3 files changed, 62 insertions(+), 12 deletions(-) diff --git a/polymer/eduke32/source/demo.c b/polymer/eduke32/source/demo.c index b7404d272..9ec0ff8f7 100644 --- a/polymer/eduke32/source/demo.c +++ b/polymer/eduke32/source/demo.c @@ -227,6 +227,12 @@ error_wopen_demo: g_demo_cnt = 1; } +static int32_t g_demo_playFirstFlag = 0; +void Demo_PlayFirst(void) +{ + g_demo_playFirstFlag = 1; +} + static uint8_t g_demo_seedbuf[RECSYNCBUFSIZ]; @@ -379,6 +385,8 @@ RECHECK: if (foundemo == 0) { + ud.recstat = 0; + if (g_whichDemo > 1) { g_whichDemo = 1; @@ -397,6 +405,7 @@ RECHECK: else { ud.recstat = 2; + g_whichDemo++; if (g_whichDemo == 1000) g_whichDemo = 1; @@ -433,17 +442,25 @@ RECHECK: // so maybe a better name for this function would be // G_MainLoopWhenNotInGame()? + // Demo requested from the OSD, its name is in g_firstDemoFile[] + if (g_demo_playFirstFlag) + { + g_demo_playFirstFlag = 0; + g_whichDemo = 1; // force g_firstDemoFile[] + goto nextdemo_nomenu; + } + if (foundemo && (!g_demo_paused || g_demo_goalCnt)) { if (g_demo_goalCnt>0 && g_demo_goalCnt < g_demo_cnt) { - // initialize rewind or fast-forward + // initialize rewind int32_t menu = g_player[myconnectindex].ps->gm&MODE_MENU; if (g_demo_goalCnt > lastsynctic) { - // fast-forward + // we can use a previous diff if (Demo_UpdateState(0)==0) { g_demo_cnt = lastsynctic; @@ -547,10 +564,11 @@ RECHECK: corrupt: OSD_Printf(OSD_ERROR "Demo %d is corrupt (code %d).\n", g_whichDemo-1, corruptcode); nextdemo: + g_player[myconnectindex].ps->gm |= MODE_MENU; +nextdemo_nomenu: foundemo = 0; ud.reccnt = 0; kclose(g_demo_recFilePtr); g_demo_recFilePtr = -1; - g_player[myconnectindex].ps->gm |= MODE_MENU; if (g_demo_goalCnt>0) { @@ -716,6 +734,7 @@ nextdemo: if (g_player[myconnectindex].ps->gm&MODE_TYPE) { Net_EnterMessage(); + if ((g_player[myconnectindex].ps->gm&MODE_TYPE) != MODE_TYPE) g_player[myconnectindex].ps->gm = MODE_MENU; } @@ -723,6 +742,7 @@ nextdemo: { if (ud.recstat != 2) M_DisplayMenus(); + if ((g_netServer || ud.multimode > 1) && g_currentMenu != 20003 && g_currentMenu != 20005 && g_currentMenu != 210) { ControlInfo noshareinfo; @@ -754,7 +774,7 @@ nextdemo: G_HandleAsync(); - if (!ud.recstat) + if (ud.recstat==0) nextpage(); if (g_player[myconnectindex].ps->gm == MODE_GAME) diff --git a/polymer/eduke32/source/demo.h b/polymer/eduke32/source/demo.h index 3b26bcce1..9ac77bd3e 100644 --- a/polymer/eduke32/source/demo.h +++ b/polymer/eduke32/source/demo.h @@ -48,6 +48,8 @@ void G_CloseDemoWrite(void); void G_DemoRecord(void); void G_OpenDemoWrite(void); +void Demo_PlayFirst(void); + #if KRANDDEBUG int32_t krd_print(const char *filename); void krd_enable(int32_t which); diff --git a/polymer/eduke32/source/osdcmds.c b/polymer/eduke32/source/osdcmds.c index dd478df6a..a8828077d 100644 --- a/polymer/eduke32/source/osdcmds.c +++ b/polymer/eduke32/source/osdcmds.c @@ -31,6 +31,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "osd.h" #include "osdfuncs.h" #include "gamedef.h" +#include "demo.h" // g_firstDemoFile[] #include "common.h" #include @@ -211,14 +212,6 @@ static int32_t osdcmd_map(const osdfuncparm_t *parm) return OSDCMD_SHOWHELP; } -#if 0 - if (numplayers > 1) - { - OSD_Printf("Command not allowed in multiplayer\n"); - return OSDCMD_OK; - } -#endif - maybe_append_ext(filename, sizeof(filename), parm->parms[0], ".map"); if ((i = kopen4loadfrommod(filename,0)) < 0) @@ -294,6 +287,39 @@ static int32_t osdcmd_map(const osdfuncparm_t *parm) return OSDCMD_OK; } +static int32_t osdcmd_demo(const osdfuncparm_t *parm) +{ + if (numplayers > 1) + { + OSD_Printf("Command not allowed in multiplayer\n"); + return OSDCMD_OK; + } + + if (g_player[myconnectindex].ps->gm & MODE_GAME) + { + OSD_Printf("demo: Must not be in a game.\n"); + return OSDCMD_OK; + } + + if (parm->numparms != 1) + return OSDCMD_SHOWHELP; + + { + char *tailptr; + const char *demostr = parm->parms[0]; + int32_t i = Bstrtol(demostr, &tailptr, 10); + + 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_PlayFirst(); + } + + return OSDCMD_OK; +} + static int32_t osdcmd_god(const osdfuncparm_t *parm) { UNREFERENCED_PARAMETER(parm); @@ -308,6 +334,7 @@ static int32_t osdcmd_god(const osdfuncparm_t *parm) static int32_t osdcmd_noclip(const osdfuncparm_t *parm) { UNREFERENCED_PARAMETER(parm); + if (numplayers == 1 && g_player[myconnectindex].ps->gm & MODE_GAME) { osdcmd_cheatsinfo_stat.cheatnum = CHEAT_CLIP; @@ -1474,6 +1501,7 @@ int32_t registerosdcommands(void) { OSD_RegisterFunction("changelevel","changelevel : warps to the given level", osdcmd_changelevel); OSD_RegisterFunction("map","map : loads the given user map", osdcmd_map); + OSD_RegisterFunction("demo","demo : starts the given demo", osdcmd_demo); } OSD_RegisterFunction("addpath","addpath : adds path to game filesystem", osdcmd_addpath);