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>
|
2011-03-13 09:41:10 +00:00
|
|
|
#include <engine/shared/protocol.h>
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2011-03-13 09:41:10 +00:00
|
|
|
#include "snapshot.h"
|
2010-05-29 07:25:38 +00:00
|
|
|
|
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;
|
2010-12-07 23:48:02 +00:00
|
|
|
int m_FirstTick;
|
2010-05-29 07:25:38 +00:00
|
|
|
unsigned char m_aLastSnapshotData[CSnapshot::MAX_SIZE];
|
|
|
|
class CSnapshotDelta *m_pSnapshotDelta;
|
2012-01-10 22:13:19 +00:00
|
|
|
int m_NumTimelineMarkers;
|
|
|
|
int m_aTimelineMarkers[MAX_TIMELINE_MARKERS];
|
2017-07-08 11:38:27 +00:00
|
|
|
bool m_NoMapData;
|
2014-12-02 14:44:54 +00:00
|
|
|
unsigned int m_MapSize;
|
|
|
|
unsigned char *m_pMapData;
|
2017-02-28 09:08:14 +00:00
|
|
|
|
|
|
|
DEMOFUNC_FILTER m_pfnFilter;
|
|
|
|
void *m_pUser;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void WriteTickMarker(int Tick, int Keyframe);
|
|
|
|
void Write(int Type, const void *pData, int Size);
|
|
|
|
public:
|
2017-07-08 11:38:27 +00:00
|
|
|
CDemoRecorder(class CSnapshotDelta *pSnapshotDelta, bool NoMapData = false);
|
2014-09-26 00:05:22 +00:00
|
|
|
CDemoRecorder() {}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2017-07-08 20:09:03 +00:00
|
|
|
int Start(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, const char *pNetversion, const char *pMap, unsigned MapCrc, const char *pType, unsigned int MapSize, unsigned char *pMapData, IOHANDLE MapFile = 0, DEMOFUNC_FILTER pfnFilter = 0, void *pUser = 0);
|
2017-07-08 11:38:27 +00:00
|
|
|
int Stop();
|
2012-01-10 22:13:19 +00:00
|
|
|
void AddDemoMarker();
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
void RecordSnapshot(int Tick, const void *pData, int Size);
|
|
|
|
void RecordMessage(const void *pData, int Size);
|
|
|
|
|
|
|
|
bool IsRecording() const { return m_File != 0; }
|
2010-12-07 23:48:02 +00:00
|
|
|
|
2011-03-13 09:41:10 +00:00
|
|
|
int Length() const { return (m_LastTickMarker - m_FirstTick)/SERVER_TICK_SPEED; }
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class CDemoPlayer : public IDemoPlayer
|
|
|
|
{
|
|
|
|
public:
|
2016-04-27 15:05:30 +00:00
|
|
|
class IListener
|
2010-05-29 07:25:38 +00:00
|
|
|
{
|
|
|
|
public:
|
2016-04-27 15:05:30 +00:00
|
|
|
virtual ~IListener() {}
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void OnDemoPlayerSnapshot(void *pData, int Size) = 0;
|
|
|
|
virtual void OnDemoPlayerMessage(void *pData, int Size) = 0;
|
|
|
|
};
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
struct CPlaybackInfo
|
|
|
|
{
|
|
|
|
CDemoHeader m_Header;
|
2013-02-25 23:00:38 +00:00
|
|
|
CTimelineMarkers m_TimelineMarkers;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
IDemoPlayer::CInfo m_Info;
|
|
|
|
|
|
|
|
int64 m_LastUpdate;
|
|
|
|
int64 m_CurrentTime;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
int m_SeekablePoints;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
int m_NextTick;
|
|
|
|
int m_PreviousTick;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
float m_IntraTick;
|
|
|
|
float m_TickTime;
|
|
|
|
};
|
|
|
|
|
2014-08-12 14:21:06 +00:00
|
|
|
struct CMapInfo
|
|
|
|
{
|
|
|
|
char m_aName[128];
|
|
|
|
int m_Crc;
|
|
|
|
int m_Size;
|
|
|
|
};
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
private:
|
2016-04-27 15:05:30 +00:00
|
|
|
IListener *m_pListener;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Playback
|
|
|
|
struct CKeyFrame
|
|
|
|
{
|
|
|
|
long m_Filepos;
|
|
|
|
int m_Tick;
|
|
|
|
};
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
struct CKeyFrameSearch
|
|
|
|
{
|
|
|
|
CKeyFrame m_Frame;
|
|
|
|
CKeyFrameSearch *m_pNext;
|
2011-04-13 18:37:12 +00:00
|
|
|
};
|
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;
|
2010-09-06 19:36:39 +00:00
|
|
|
char m_aFilename[256];
|
2010-05-29 07:25:38 +00:00
|
|
|
CKeyFrame *m_pKeyFrames;
|
2014-08-12 14:21:06 +00:00
|
|
|
CMapInfo m_MapInfo;
|
2016-10-28 07:31:22 +00:00
|
|
|
int m_SpeedIndex;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
CPlaybackInfo m_Info;
|
2011-03-12 17:07:57 +00:00
|
|
|
int m_DemoType;
|
2010-05-29 07:25:38 +00:00
|
|
|
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:
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CDemoPlayer(class CSnapshotDelta *m_pSnapshotDelta);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2016-04-27 15:05:30 +00:00
|
|
|
void SetListener(IListener *pListener);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
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();
|
2011-04-13 18:37:12 +00:00
|
|
|
int Stop();
|
2010-05-29 07:25:38 +00:00
|
|
|
void SetSpeed(float Speed);
|
2016-10-28 07:31:22 +00:00
|
|
|
void SetSpeedIndex(int Offset);
|
2012-01-10 22:13:19 +00:00
|
|
|
int SetPos(float Percent);
|
2010-05-29 07:25:38 +00:00
|
|
|
const CInfo *BaseInfo() const { return &m_Info.m_Info; }
|
2011-06-09 20:44:22 +00:00
|
|
|
void GetDemoName(char *pBuffer, int BufferSize) const;
|
2011-03-13 09:41:10 +00:00
|
|
|
bool GetDemoInfo(class IStorage *pStorage, const char *pFilename, int StorageType, CDemoHeader *pDemoHeader) const;
|
2014-08-12 14:21:06 +00:00
|
|
|
const char *GetDemoFileName() { return m_aFilename; };
|
2011-03-12 17:07:57 +00:00
|
|
|
int GetDemoType() const;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2014-08-12 14:21:06 +00:00
|
|
|
int Update(bool RealTime=true);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
const CPlaybackInfo *Info() const { return &m_Info; }
|
2014-04-26 19:00:14 +00:00
|
|
|
virtual bool IsPlaying() const { return m_File != 0; }
|
2014-08-12 14:21:06 +00:00
|
|
|
const CMapInfo *GetMapInfo() { return &m_MapInfo; };
|
|
|
|
};
|
|
|
|
|
2016-04-27 15:05:30 +00:00
|
|
|
class CDemoEditor : public IDemoEditor, public CDemoPlayer::IListener
|
2014-08-12 14:21:06 +00:00
|
|
|
{
|
|
|
|
CDemoPlayer *m_pDemoPlayer;
|
|
|
|
CDemoRecorder *m_pDemoRecorder;
|
|
|
|
IConsole *m_pConsole;
|
|
|
|
IStorage *m_pStorage;
|
|
|
|
class CSnapshotDelta *m_pSnapshotDelta;
|
|
|
|
const char *m_pNetVersion;
|
|
|
|
|
|
|
|
bool m_Stop;
|
|
|
|
int m_SliceFrom;
|
|
|
|
int m_SliceTo;
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual void Init(const char *pNetVersion, class CSnapshotDelta *pSnapshotDelta, class IConsole *pConsole, class IStorage *pStorage);
|
2017-02-28 09:08:14 +00:00
|
|
|
virtual void Slice(const char *pDemo, const char *pDst, int StartTick, int EndTick, DEMOFUNC_FILTER pfnFilter, void *pUser);
|
2014-08-12 14:21:06 +00:00
|
|
|
|
|
|
|
virtual void OnDemoPlayerSnapshot(void *pData, int Size);
|
|
|
|
virtual void OnDemoPlayerMessage(void *pData, int Size);
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|