From 3797eba179d40473e20f16d46dffc8d69e7e1b74 Mon Sep 17 00:00:00 2001 From: oy Date: Mon, 9 Aug 2010 14:14:15 +0200 Subject: added demo recording button by fujnky --- src/engine/client.h | 1 + src/engine/client/client.cpp | 16 +++++++++++----- src/engine/client/client.h | 1 + src/engine/demo.h | 9 +++++++++ src/engine/shared/demorec.h | 2 +- src/game/client/component.h | 1 + src/game/client/components/menus_ingame.cpp | 23 ++++++++++++++++++++++- src/game/client/gameclient.cpp | 1 + src/game/client/gameclient.h | 2 ++ 9 files changed, 49 insertions(+), 7 deletions(-) diff --git a/src/engine/client.h b/src/engine/client.h index 8e5a5577..fe8e91f2 100644 --- a/src/engine/client.h +++ b/src/engine/client.h @@ -74,6 +74,7 @@ public: virtual void Disconnect() = 0; virtual void Quit() = 0; virtual const char *DemoPlayer_Play(const char *pFilename) = 0; + virtual void DemoRecorder_Start(const char *pFilename) = 0; // networking virtual void EnterGame() = 0; diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 4ab8ee60..03f31770 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -1537,6 +1537,7 @@ void CClient::InitEngine(const char *pAppname) void CClient::RegisterInterfaces() { + Kernel()->RegisterInterface(static_cast(&m_DemoRecorder)); Kernel()->RegisterInterface(static_cast(&m_DemoPlayer)); Kernel()->RegisterInterface(static_cast(&m_ServerBrowser)); } @@ -1883,19 +1884,24 @@ void CClient::Con_Play(IConsole::IResult *pResult, void *pUserData) pSelf->DemoPlayer_Play(pResult->GetString(0)); } -void CClient::Con_Record(IConsole::IResult *pResult, void *pUserData) +void CClient::DemoRecorder_Start(const char *pFilename) { - CClient *pSelf = (CClient *)pUserData; - if(pSelf->State() != IClient::STATE_ONLINE) + if(State() != IClient::STATE_ONLINE) dbg_msg("demorec/record", "client is not online"); else { char aFilename[512]; - str_format(aFilename, sizeof(aFilename), "demos/%s.demo", pResult->GetString(0)); - pSelf->m_DemoRecorder.Start(pSelf->Storage(), aFilename, pSelf->GameClient()->NetVersion(), pSelf->m_aCurrentMap, pSelf->m_CurrentMapCrc, "client"); + str_format(aFilename, sizeof(aFilename), "demos/%s.demo", pFilename); + m_DemoRecorder.Start(Storage(), aFilename, GameClient()->NetVersion(), m_aCurrentMap, m_CurrentMapCrc, "client"); } } +void CClient::Con_Record(IConsole::IResult *pResult, void *pUserData) +{ + CClient *pSelf = (CClient *)pUserData; + pSelf->DemoRecorder_Start(pResult->GetString(0)); +} + void CClient::Con_StopRecord(IConsole::IResult *pResult, void *pUserData) { CClient *pSelf = (CClient *)pUserData; diff --git a/src/engine/client/client.h b/src/engine/client/client.h index 9698abbb..a27ec5fd 100644 --- a/src/engine/client/client.h +++ b/src/engine/client/client.h @@ -284,6 +284,7 @@ public: void RegisterCommands(); const char *DemoPlayer_Play(const char *pFilename); + void DemoRecorder_Start(const char *pFilename); virtual class CEngine *Engine() { return &m_Engine; } }; diff --git a/src/engine/demo.h b/src/engine/demo.h index 7b353e7c..6abc9b2d 100644 --- a/src/engine/demo.h +++ b/src/engine/demo.h @@ -26,4 +26,13 @@ public: virtual const CInfo *BaseInfo() const = 0; }; +class IDemoRecorder : public IInterface +{ + MACRO_INTERFACE("demorecorder", 0) +public: + ~IDemoRecorder() {} + virtual bool IsRecording() const = 0; + virtual int Stop() = 0; +}; + #endif diff --git a/src/engine/shared/demorec.h b/src/engine/shared/demorec.h index 0936c30c..294a088b 100644 --- a/src/engine/shared/demorec.h +++ b/src/engine/shared/demorec.h @@ -13,7 +13,7 @@ struct CDemoHeader char m_aType[8]; }; -class CDemoRecorder +class CDemoRecorder : public IDemoRecorder { IOHANDLE m_File; int m_LastTickMarker; diff --git a/src/game/client/component.h b/src/game/client/component.h index 410be623..6e4b3715 100644 --- a/src/game/client/component.h +++ b/src/game/client/component.h @@ -23,6 +23,7 @@ protected: class CRenderTools *RenderTools() const { return m_pClient->RenderTools(); } class IConsole *Console() const { return m_pClient->Console(); } class IDemoPlayer *DemoPlayer() const { return m_pClient->DemoPlayer(); } + class IDemoRecorder *DemoRecorder() const { return m_pClient->DemoRecorder(); } class IServerBrowser *ServerBrowser() const { return m_pClient->ServerBrowser(); } class CLayers *Layers() const { return m_pClient->Layers(); } class CCollision *Collision() const { return m_pClient->Collision(); } diff --git a/src/game/client/components/menus_ingame.cpp b/src/game/client/components/menus_ingame.cpp index b5543162..f1a4b0dd 100644 --- a/src/game/client/components/menus_ingame.cpp +++ b/src/game/client/components/menus_ingame.cpp @@ -1,7 +1,8 @@ +#include #include - +#include #include #include #include @@ -89,6 +90,26 @@ void CMenus::RenderGame(CUIRect MainView) } } } + + MainView.VSplitLeft(100.0f, &Button, &MainView); + MainView.VSplitLeft(150.0f, &Button, &MainView); + + static int s_DemoButton = 0; + bool Recording = DemoRecorder()->IsRecording(); + if(DoButton_Menu(&s_DemoButton, Localize(Recording ? "Stop record" : "Record demo"), 0, &Button)) // Localize("Stop record");Localize("Record demo"); + { + if(!Recording) + { + char aFilename[128]; + time_t Time; + time(&Time); + tm* TimeInfo = localtime(&Time); + strftime(aFilename, sizeof(aFilename), "demo-%Y-%m-%d_%H-%M-%S", TimeInfo); + Client()->DemoRecorder_Start(aFilename); + } + else + DemoRecorder()->Stop(); + } /* CUIRect bars; diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 2b47af1f..319cc300 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -115,6 +115,7 @@ void CGameClient::OnConsoleInit() m_pConsole = Kernel()->RequestInterface(); m_pStorage = Kernel()->RequestInterface(); m_pDemoPlayer = Kernel()->RequestInterface(); + m_pDemoRecorder = Kernel()->RequestInterface(); m_pServerBrowser = Kernel()->RequestInterface(); // setup pointers diff --git a/src/game/client/gameclient.h b/src/game/client/gameclient.h index b91b4b50..28043794 100644 --- a/src/game/client/gameclient.h +++ b/src/game/client/gameclient.h @@ -37,6 +37,7 @@ class CGameClient : public IGameClient class IConsole *m_pConsole; class IStorage *m_pStorage; class IDemoPlayer *m_pDemoPlayer; + class IDemoRecorder *m_pDemoRecorder; class IServerBrowser *m_pServerBrowser; CLayers m_Layers; @@ -68,6 +69,7 @@ public: class IConsole *Console() { return m_pConsole; } class ITextRender *TextRender() const { return m_pTextRender; } class IDemoPlayer *DemoPlayer() const { return m_pDemoPlayer; } + class IDemoRecorder *DemoRecorder() const { return m_pDemoRecorder; } class IServerBrowser *ServerBrowser() const { return m_pServerBrowser; } class CRenderTools *RenderTools() { return &m_RenderTools; } class CLayers *Layers() { return &m_Layers; }; -- cgit 1.4.1