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> |
9 | #include <engine/shared/uuid_manager.h> |
10 | |
11 | #include <cstdint> |
12 | |
13 | enum |
14 | { |
15 | MAX_TIMELINE_MARKERS = 64 |
16 | }; |
17 | |
18 | static const unsigned char [7] = {'T', 'W', 'D', 'E', 'M', 'O', 0}; |
19 | |
20 | constexpr int g_DemoSpeeds = 22; |
21 | extern const double g_aSpeeds[g_DemoSpeeds]; |
22 | |
23 | typedef 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" |
28 | extern const CUuid SHA256_EXTENSION; |
29 | |
30 | struct |
31 | { |
32 | unsigned char [7]; |
33 | unsigned char ; |
34 | char [64]; |
35 | char [64]; |
36 | unsigned char [sizeof(int32_t)]; |
37 | unsigned char [sizeof(int32_t)]; |
38 | char [8]; |
39 | unsigned char [sizeof(int32_t)]; |
40 | char [20]; |
41 | |
42 | bool () const; |
43 | }; |
44 | |
45 | struct CTimelineMarkers |
46 | { |
47 | unsigned char m_aNumTimelineMarkers[sizeof(int32_t)]; |
48 | unsigned char m_aTimelineMarkers[MAX_TIMELINE_MARKERS][sizeof(int32_t)]; |
49 | }; |
50 | |
51 | struct CMapInfo |
52 | { |
53 | char m_aName[MAX_MAP_LENGTH]; |
54 | SHA256_DIGEST m_Sha256; |
55 | unsigned m_Crc; |
56 | unsigned m_Size; |
57 | }; |
58 | |
59 | class IDemoPlayer : public IInterface |
60 | { |
61 | MACRO_INTERFACE("demoplayer" ) |
62 | public: |
63 | class CInfo |
64 | { |
65 | public: |
66 | bool m_Paused; |
67 | float m_Speed; |
68 | |
69 | int m_FirstTick; |
70 | int m_CurrentTick; |
71 | int m_LastTick; |
72 | |
73 | int m_NumTimelineMarkers; |
74 | int m_aTimelineMarkers[MAX_TIMELINE_MARKERS]; |
75 | }; |
76 | |
77 | enum ETickOffset |
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 (class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, int StorageType, CDemoHeader *, CTimelineMarkers *pTimelineMarkers, CMapInfo *pMapInfo, IOHANDLE *pFile = nullptr, char *pErrorMessage = nullptr, size_t ErrorMessageSize = 0) const = 0; |
99 | }; |
100 | |
101 | class IDemoRecorder : public IInterface |
102 | { |
103 | MACRO_INTERFACE("demorecorder" ) |
104 | public: |
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 | |
118 | class IDemoEditor : public IInterface |
119 | { |
120 | MACRO_INTERFACE("demoeditor" ) |
121 | public: |
122 | virtual bool Slice(const char *pDemo, const char *pDst, int StartTick, int EndTick, DEMOFUNC_FILTER pfnFilter, void *pUser) = 0; |
123 | }; |
124 | |
125 | #endif |
126 | |