added demo recording button by fujnky

This commit is contained in:
oy 2010-08-09 14:14:15 +02:00
parent d471663913
commit 3797eba179
9 changed files with 49 additions and 7 deletions

View file

@ -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;

View file

@ -1537,6 +1537,7 @@ void CClient::InitEngine(const char *pAppname)
void CClient::RegisterInterfaces()
{
Kernel()->RegisterInterface(static_cast<IDemoRecorder*>(&m_DemoRecorder));
Kernel()->RegisterInterface(static_cast<IDemoPlayer*>(&m_DemoPlayer));
Kernel()->RegisterInterface(static_cast<IServerBrowser*>(&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;

View file

@ -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; }
};

View file

@ -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

View file

@ -13,7 +13,7 @@ struct CDemoHeader
char m_aType[8];
};
class CDemoRecorder
class CDemoRecorder : public IDemoRecorder
{
IOHANDLE m_File;
int m_LastTickMarker;

View file

@ -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(); }

View file

@ -1,7 +1,8 @@
#include <time.h>
#include <base/math.h>
#include <engine/demo.h>
#include <engine/serverbrowser.h>
#include <engine/textrender.h>
#include <engine/shared/config.h>
@ -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;

View file

@ -115,6 +115,7 @@ void CGameClient::OnConsoleInit()
m_pConsole = Kernel()->RequestInterface<IConsole>();
m_pStorage = Kernel()->RequestInterface<IStorage>();
m_pDemoPlayer = Kernel()->RequestInterface<IDemoPlayer>();
m_pDemoRecorder = Kernel()->RequestInterface<IDemoRecorder>();
m_pServerBrowser = Kernel()->RequestInterface<IServerBrowser>();
// setup pointers

View file

@ -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; };