2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2010-10-30 11:48:59 +00:00
|
|
|
#ifndef ENGINE_SHARED_DEMO_H
|
|
|
|
#define ENGINE_SHARED_DEMO_H
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
#include <engine/demo.h>
|
|
|
|
#include "snapshot.h"
|
|
|
|
|
|
|
|
struct CDemoHeader
|
|
|
|
{
|
2010-09-12 14:56:13 +00:00
|
|
|
unsigned char m_aMarker[7];
|
|
|
|
unsigned char m_Version;
|
2010-05-29 07:25:38 +00:00
|
|
|
char m_aNetversion[64];
|
|
|
|
char m_aMap[64];
|
|
|
|
unsigned char m_aCrc[4];
|
|
|
|
char m_aType[8];
|
|
|
|
};
|
|
|
|
|
2010-08-09 12:14:15 +00:00
|
|
|
class CDemoRecorder : public IDemoRecorder
|
2010-05-29 07:25:38 +00:00
|
|
|
{
|
2010-08-17 22:06:00 +00:00
|
|
|
class IConsole *m_pConsole;
|
2010-05-29 07:25:38 +00:00
|
|
|
IOHANDLE m_File;
|
|
|
|
int m_LastTickMarker;
|
|
|
|
int m_LastKeyFrame;
|
|
|
|
unsigned char m_aLastSnapshotData[CSnapshot::MAX_SIZE];
|
|
|
|
class CSnapshotDelta *m_pSnapshotDelta;
|
|
|
|
|
|
|
|
void WriteTickMarker(int Tick, int Keyframe);
|
|
|
|
void Write(int Type, const void *pData, int Size);
|
|
|
|
public:
|
|
|
|
CDemoRecorder(class CSnapshotDelta *pSnapshotDelta);
|
|
|
|
|
2010-08-17 22:06:00 +00:00
|
|
|
int Start(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, const char *pNetversion, const char *pMap, int MapCrc, const char *pType);
|
2010-05-29 07:25:38 +00:00
|
|
|
int Stop();
|
|
|
|
|
|
|
|
void RecordSnapshot(int Tick, const void *pData, int Size);
|
|
|
|
void RecordMessage(const void *pData, int Size);
|
|
|
|
|
|
|
|
bool IsRecording() const { return m_File != 0; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class CDemoPlayer : public IDemoPlayer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
class IListner
|
|
|
|
{
|
|
|
|
public:
|
2010-11-17 17:36:19 +00:00
|
|
|
virtual ~IListner() {}
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void OnDemoPlayerSnapshot(void *pData, int Size) = 0;
|
|
|
|
virtual void OnDemoPlayerMessage(void *pData, int Size) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CPlaybackInfo
|
|
|
|
{
|
|
|
|
CDemoHeader m_Header;
|
|
|
|
|
|
|
|
IDemoPlayer::CInfo m_Info;
|
|
|
|
|
|
|
|
int64 m_LastUpdate;
|
|
|
|
int64 m_CurrentTime;
|
|
|
|
|
|
|
|
int m_SeekablePoints;
|
|
|
|
|
|
|
|
int m_NextTick;
|
|
|
|
int m_PreviousTick;
|
|
|
|
|
|
|
|
float m_IntraTick;
|
|
|
|
float m_TickTime;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
IListner *m_pListner;
|
|
|
|
|
|
|
|
|
|
|
|
// Playback
|
|
|
|
struct CKeyFrame
|
|
|
|
{
|
|
|
|
long m_Filepos;
|
|
|
|
int m_Tick;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CKeyFrameSearch
|
|
|
|
{
|
|
|
|
CKeyFrame m_Frame;
|
|
|
|
CKeyFrameSearch *m_pNext;
|
|
|
|
};
|
|
|
|
|
2010-08-17 22:06:00 +00:00
|
|
|
class IConsole *m_pConsole;
|
2010-05-29 07:25:38 +00:00
|
|
|
IOHANDLE m_File;
|
2010-09-06 19:36:39 +00:00
|
|
|
char m_aFilename[256];
|
2010-05-29 07:25:38 +00:00
|
|
|
CKeyFrame *m_pKeyFrames;
|
|
|
|
|
|
|
|
CPlaybackInfo m_Info;
|
|
|
|
unsigned char m_aLastSnapshotData[CSnapshot::MAX_SIZE];
|
|
|
|
int m_LastSnapshotDataSize;
|
|
|
|
class CSnapshotDelta *m_pSnapshotDelta;
|
|
|
|
|
|
|
|
int ReadChunkHeader(int *pType, int *pSize, int *pTick);
|
|
|
|
void DoTick();
|
|
|
|
void ScanFile();
|
|
|
|
int NextFrame();
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
CDemoPlayer(class CSnapshotDelta *m_pSnapshotDelta);
|
|
|
|
|
|
|
|
void SetListner(IListner *pListner);
|
|
|
|
|
2010-10-06 21:07:35 +00:00
|
|
|
int Load(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, int StorageType);
|
2010-05-29 07:25:38 +00:00
|
|
|
int Play();
|
|
|
|
void Pause();
|
|
|
|
void Unpause();
|
|
|
|
int Stop();
|
|
|
|
void SetSpeed(float Speed);
|
|
|
|
int SetPos(float Precent);
|
|
|
|
const CInfo *BaseInfo() const { return &m_Info.m_Info; }
|
2010-09-06 19:36:39 +00:00
|
|
|
char *GetDemoName();
|
2010-10-09 11:27:21 +00:00
|
|
|
bool GetDemoInfo(class IStorage *pStorage, const char *pFilename, int StorageType, char *pMap, int BufferSize) const;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
int Update();
|
|
|
|
|
|
|
|
const CPlaybackInfo *Info() const { return &m_Info; }
|
|
|
|
int IsPlaying() const { return m_File != 0; }
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|