DDraceNetwork Docs
demo.h
Go to the documentation of this file.
1/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2/* If you are missing that file, acquire a complete release at teeworlds.com. */
3#ifndef ENGINE_DEMO_H
4#define ENGINE_DEMO_H
5
6#include "kernel.h"
7#include <base/hash.h>
8#include <engine/map.h>
10
11#include <cstdint>
12
13enum
14{
16};
17
18static const unsigned char gs_aHeaderMarker[7] = {'T', 'W', 'D', 'E', 'M', 'O', 0};
19
20constexpr int g_DemoSpeeds = 22;
21extern const double g_aSpeeds[g_DemoSpeeds];
22
23typedef bool (*DEMOFUNC_FILTER)(const void *pData, int DataSize, void *pUser);
24
25// TODO: Properly extend demo format using uuids
26// "6be6da4a-cebd-380c-9b5b-1289c842d780"
27// "demoitem-sha256@ddnet.tw"
28extern const CUuid SHA256_EXTENSION;
29
31{
32 unsigned char m_aMarker[7];
33 unsigned char m_Version;
34 char m_aNetversion[64];
35 char m_aMapName[64];
36 unsigned char m_aMapSize[sizeof(int32_t)];
37 unsigned char m_aMapCrc[sizeof(int32_t)];
38 char m_aType[8];
39 unsigned char m_aLength[sizeof(int32_t)];
40 char m_aTimestamp[20];
41
42 bool Valid() const;
43};
44
46{
47 unsigned char m_aNumTimelineMarkers[sizeof(int32_t)];
48 unsigned char m_aTimelineMarkers[MAX_TIMELINE_MARKERS][sizeof(int32_t)];
49};
50
52{
55 unsigned m_Crc;
56 unsigned m_Size;
57};
58
59class IDemoPlayer : public IInterface
60{
61 MACRO_INTERFACE("demoplayer")
62public:
63 class CInfo
64 {
65 public:
67 float m_Speed;
68
72
74 int m_aTimelineMarkers[MAX_TIMELINE_MARKERS];
75 };
76
78 {
79 TICK_CURRENT, // update the current tick again
80 TICK_PREVIOUS, // go to the previous tick
81 TICK_NEXT, // go to the next tick
82 };
83
84 virtual ~IDemoPlayer() {}
85 virtual void SetSpeed(float Speed) = 0;
86 virtual void SetSpeedIndex(int SpeedIndex) = 0;
87 virtual void AdjustSpeedIndex(int Offset) = 0;
88 virtual int SeekPercent(float Percent) = 0;
89 virtual int SeekTime(float Seconds) = 0;
90 virtual int SeekTick(ETickOffset TickOffset) = 0;
91 virtual int SetPos(int WantedTick) = 0;
92 virtual void Pause() = 0;
93 virtual void Unpause() = 0;
94 virtual const char *ErrorMessage() const = 0;
95 virtual bool IsPlaying() const = 0;
96 virtual const CInfo *BaseInfo() const = 0;
97 virtual void GetDemoName(char *pBuffer, size_t BufferSize) const = 0;
98 virtual bool GetDemoInfo(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, int StorageType, CDemoHeader *pDemoHeader, CTimelineMarkers *pTimelineMarkers, CMapInfo *pMapInfo, IOHANDLE *pFile = nullptr, char *pErrorMessage = nullptr, size_t ErrorMessageSize = 0) const = 0;
99};
100
102{
103 MACRO_INTERFACE("demorecorder")
104public:
105 enum class EStopMode
106 {
107 KEEP_FILE,
108 REMOVE_FILE,
109 };
110
111 virtual ~IDemoRecorder() {}
112 virtual bool IsRecording() const = 0;
113 virtual int Stop(IDemoRecorder::EStopMode Mode, const char *pTargetFilename = "") = 0;
114 virtual int Length() const = 0;
115 virtual const char *CurrentFilename() const = 0;
116};
117
119{
120 MACRO_INTERFACE("demoeditor")
121public:
122 virtual bool Slice(const char *pDemo, const char *pDst, int StartTick, int EndTick, DEMOFUNC_FILTER pfnFilter, void *pUser) = 0;
123};
124
125#endif
Definition: console.h:18
Definition: demo.h:119
virtual bool Slice(const char *pDemo, const char *pDst, int StartTick, int EndTick, DEMOFUNC_FILTER pfnFilter, void *pUser)=0
Definition: demo.h:64
float m_Speed
Definition: demo.h:67
int m_NumTimelineMarkers
Definition: demo.h:73
bool m_Paused
Definition: demo.h:66
int m_CurrentTick
Definition: demo.h:70
int m_LastTick
Definition: demo.h:71
int m_FirstTick
Definition: demo.h:69
Definition: demo.h:60
virtual ~IDemoPlayer()
Definition: demo.h:84
virtual bool GetDemoInfo(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, int StorageType, CDemoHeader *pDemoHeader, CTimelineMarkers *pTimelineMarkers, CMapInfo *pMapInfo, IOHANDLE *pFile=nullptr, char *pErrorMessage=nullptr, size_t ErrorMessageSize=0) const =0
virtual void SetSpeedIndex(int SpeedIndex)=0
virtual void Pause()=0
virtual int SeekTick(ETickOffset TickOffset)=0
virtual void GetDemoName(char *pBuffer, size_t BufferSize) const =0
virtual void SetSpeed(float Speed)=0
virtual void AdjustSpeedIndex(int Offset)=0
virtual int SetPos(int WantedTick)=0
virtual const CInfo * BaseInfo() const =0
virtual int SeekTime(float Seconds)=0
virtual bool IsPlaying() const =0
virtual const char * ErrorMessage() const =0
virtual void Unpause()=0
virtual int SeekPercent(float Percent)=0
ETickOffset
Definition: demo.h:78
@ TICK_NEXT
Definition: demo.h:81
@ TICK_PREVIOUS
Definition: demo.h:80
@ TICK_CURRENT
Definition: demo.h:79
Definition: demo.h:102
virtual int Stop(IDemoRecorder::EStopMode Mode, const char *pTargetFilename="")=0
virtual bool IsRecording() const =0
EStopMode
Definition: demo.h:106
virtual int Length() const =0
virtual ~IDemoRecorder()
Definition: demo.h:111
virtual const char * CurrentFilename() const =0
Definition: kernel.h:10
Definition: storage.h:20
bool(* DEMOFUNC_FILTER)(const void *pData, int DataSize, void *pUser)
Definition: demo.h:23
const double g_aSpeeds[g_DemoSpeeds]
Definition: demo.cpp:20
static const unsigned char gs_aHeaderMarker[7]
Definition: demo.h:18
@ MAX_TIMELINE_MARKERS
Definition: demo.h:15
const CUuid SHA256_EXTENSION
Definition: demo.cpp:21
constexpr int g_DemoSpeeds
Definition: demo.h:20
#define MACRO_INTERFACE(Name)
Definition: kernel.h:25
void * IOHANDLE
Definition: logger.h:11
@ MAX_MAP_LENGTH
Definition: map.h:12
Definition: demo.h:31
char m_aType[8]
Definition: demo.h:38
char m_aTimestamp[20]
Definition: demo.h:40
bool Valid() const
Definition: demo.cpp:34
unsigned char m_aLength[sizeof(int32_t)]
Definition: demo.h:39
unsigned char m_aMapSize[sizeof(int32_t)]
Definition: demo.h:36
unsigned char m_aMarker[7]
Definition: demo.h:32
unsigned char m_Version
Definition: demo.h:33
char m_aMapName[64]
Definition: demo.h:35
unsigned char m_aMapCrc[sizeof(int32_t)]
Definition: demo.h:37
char m_aNetversion[64]
Definition: demo.h:34
Definition: demo.h:52
char m_aName[MAX_MAP_LENGTH]
Definition: demo.h:53
unsigned m_Size
Definition: demo.h:56
unsigned m_Crc
Definition: demo.h:55
SHA256_DIGEST m_Sha256
Definition: demo.h:54
Definition: demo.h:46
unsigned char m_aTimelineMarkers[MAX_TIMELINE_MARKERS][sizeof(int32_t)]
Definition: demo.h:48
unsigned char m_aNumTimelineMarkers[sizeof(int32_t)]
Definition: demo.h:47
Definition: uuid_manager.h:17
Definition: hash.h:15