DDraceNetwork Docs
ghost.h
Go to the documentation of this file.
1/* (c) Rajh, Redix and Sushi. */
2
3#ifndef GAME_CLIENT_COMPONENTS_GHOST_H
4#define GAME_CLIENT_COMPONENTS_GHOST_H
5
9
10#include <game/client/render.h>
11
13
14enum
15{
20};
21
23{
33};
34
36{
37 int m_X;
38 int m_Y;
39 int m_VelX;
40 int m_VelY;
48};
49
51{
52 int m_Tick;
53};
54
55class CGhost : public CComponent
56{
57private:
58 enum
59 {
61 };
62
64 {
67
68 std::vector<CGhostCharacter *> m_vpChunks;
69
70 public:
73 CGhostPath(const CGhostPath &Other) = delete;
74 CGhostPath &operator=(const CGhostPath &Other) = delete;
75
76 CGhostPath(CGhostPath &&Other) noexcept;
77 CGhostPath &operator=(CGhostPath &&Other) noexcept;
78
79 void Reset(int ChunkSize = 25 * 60); // one minute with default snap rate
80 void SetSize(int Items);
81 int Size() const { return m_NumItems; }
82
83 void Add(const CGhostCharacter &Char);
84 CGhostCharacter *Get(int Index);
85 };
86
88 {
89 public:
96
98
99 bool Empty() const { return m_Path.Size() == 0; }
100 void Reset()
101 {
102 m_Path.Reset();
103 m_StartTick = -1;
104 m_PlaybackPos = -1;
105 }
106 };
107
108 static const char *ms_pGhostDir;
109
112
115
117
121 bool m_Recording = false;
122 bool m_Rendering = false;
124
125 static void GetGhostSkin(CGhostSkin *pSkin, const char *pSkinName, int UseCustomColor, int ColorBody, int ColorFeet);
126 static void GetGhostCharacter(CGhostCharacter *pGhostChar, const CNetObj_Character *pChar, const CNetObj_DDNetCharacter *pDDnetChar);
127 static void GetNetObjCharacter(CNetObj_Character *pChar, const CGhostCharacter *pGhostChar);
128
129 void GetPath(char *pBuf, int Size, const char *pPlayerName, int Time = -1) const;
130
131 void AddInfos(const CNetObj_Character *pChar, const CNetObj_DDNetCharacter *pDDnetChar);
132 int GetSlot() const;
133
134 void CheckStart();
135 void CheckStartLocal(bool Predicted);
136 void TryRenderStart(int Tick, bool ServerControl);
137
138 void StartRecord(int Tick);
139 void StopRecord(int Time = -1);
140 void StartRender(int Tick);
141 void StopRender();
142
143 void InitRenderInfos(CGhostItem *pGhost);
144
145 static void ConGPlay(IConsole::IResult *pResult, void *pUserData);
146
147public:
149
150 virtual int Sizeof() const override { return sizeof(*this); }
151
152 virtual void OnRender() override;
153 virtual void OnConsoleInit() override;
154 virtual void OnReset() override;
155 virtual void OnRefreshSkins() override;
156 virtual void OnMessage(int MsgType, void *pRawMsg) override;
157 virtual void OnMapLoad() override;
158 virtual void OnShutdown() override;
159 virtual void OnNewSnapshot() override;
160
162
163 int FreeSlots() const;
164 int Load(const char *pFilename);
165 void Unload(int Slot);
166 void UnloadAll();
167
168 void SaveGhost(CMenus::CGhostItem *pItem);
169
170 const char *GetGhostDir() const { return ms_pGhostDir; }
171
172 class IGhostLoader *GhostLoader() const { return m_pGhostLoader; }
174};
175
176#endif
Definition: component.h:20
Definition: ghost.h:88
void Reset()
Definition: ghost.h:100
CTeeRenderInfo m_RenderInfo
Definition: ghost.h:90
char m_aPlayer[MAX_NAME_LENGTH]
Definition: ghost.h:94
CGhostPath m_Path
Definition: ghost.h:92
int m_PlaybackPos
Definition: ghost.h:95
CGhostItem()
Definition: ghost.h:97
CGhostSkin m_Skin
Definition: ghost.h:91
bool Empty() const
Definition: ghost.h:99
int m_StartTick
Definition: ghost.h:93
Definition: ghost.h:64
std::vector< CGhostCharacter * > m_vpChunks
Definition: ghost.h:68
CGhostPath(const CGhostPath &Other)=delete
CGhostPath & operator=(const CGhostPath &Other)=delete
~CGhostPath()
Definition: ghost.h:72
CGhostCharacter * Get(int Index)
Definition: ghost.cpp:115
void SetSize(int Items)
Definition: ghost.cpp:94
int m_NumItems
Definition: ghost.h:66
int Size() const
Definition: ghost.h:81
int m_ChunkSize
Definition: ghost.h:65
void Add(const CGhostCharacter &Char)
Definition: ghost.cpp:109
CGhostPath()
Definition: ghost.h:71
void Reset(int ChunkSize=25 *60)
Definition: ghost.cpp:85
Definition: ghost.h:56
int FreeSlots() const
Definition: ghost.cpp:176
virtual void OnConsoleInit() override
Definition: ghost.cpp:578
int Load(const char *pFilename)
Definition: ghost.cpp:456
int GetSlot() const
Definition: ghost.cpp:168
class IGhostRecorder * m_pGhostRecorder
Definition: ghost.h:111
void AddInfos(const CNetObj_Character *pChar, const CNetObj_DDNetCharacter *pDDnetChar)
Definition: ghost.cpp:145
CGhostItem m_aActiveGhosts[MAX_ACTIVE_GHOSTS]
Definition: ghost.h:113
void StopRecord(int Time=-1)
Definition: ghost.cpp:401
int m_StartRenderTick
Definition: ghost.h:119
void StopRender()
Definition: ghost.cpp:450
void OnNewPredictedSnapshot()
Definition: ghost.cpp:291
virtual void OnRefreshSkins() override
Definition: ghost.cpp:650
void Unload(int Slot)
Definition: ghost.cpp:541
bool m_Rendering
Definition: ghost.h:122
bool m_RenderingStartedByServer
Definition: ghost.h:123
void TryRenderStart(int Tick, bool ServerControl)
Definition: ghost.cpp:260
virtual void OnMapLoad() override
Definition: ghost.cpp:642
class IGhostRecorder * GhostRecorder() const
Definition: ghost.h:173
virtual int Sizeof() const override
Definition: ghost.h:150
@ MAX_ACTIVE_GHOSTS
Definition: ghost.h:60
static void GetGhostSkin(CGhostSkin *pSkin, const char *pSkinName, int UseCustomColor, int ColorBody, int ColorFeet)
Definition: ghost.cpp:21
void StartRender(int Tick)
Definition: ghost.cpp:442
const char * GetGhostDir() const
Definition: ghost.h:170
void InitRenderInfos(CGhostItem *pGhost)
Definition: ghost.cpp:379
virtual void OnMessage(int MsgType, void *pRawMsg) override
Definition: ghost.cpp:586
void GetPath(char *pBuf, int Size, const char *pPlayerName, int Time=-1) const
Definition: ghost.cpp:125
char m_aTmpFilename[IO_MAX_PATH_LENGTH]
Definition: ghost.h:116
int m_NewRenderTick
Definition: ghost.h:118
void CheckStart()
Definition: ghost.cpp:185
void UnloadAll()
Definition: ghost.cpp:546
virtual void OnShutdown() override
Definition: ghost.cpp:637
static void ConGPlay(IConsole::IResult *pResult, void *pUserData)
Definition: ghost.cpp:572
int m_LastDeathTick
Definition: ghost.h:120
void CheckStartLocal(bool Predicted)
Definition: ghost.cpp:211
CGhostItem m_CurGhost
Definition: ghost.h:114
static void GetGhostCharacter(CGhostCharacter *pGhostChar, const CNetObj_Character *pChar, const CNetObj_DDNetCharacter *pDDnetChar)
Definition: ghost.cpp:29
virtual void OnNewSnapshot() override
Definition: ghost.cpp:272
virtual void OnReset() override
Definition: ghost.cpp:630
bool m_AllowRestart
Definition: ghost.h:148
void SaveGhost(CMenus::CGhostItem *pItem)
Definition: ghost.cpp:552
static const char * ms_pGhostDir
Definition: ghost.h:108
class IGhostLoader * m_pGhostLoader
Definition: ghost.h:110
static void GetNetObjCharacter(CNetObj_Character *pChar, const CGhostCharacter *pGhostChar)
Definition: ghost.cpp:50
class IGhostLoader * GhostLoader() const
Definition: ghost.h:172
bool m_Recording
Definition: ghost.h:121
virtual void OnRender() override
Definition: ghost.cpp:305
void StartRecord(int Tick)
Definition: ghost.cpp:389
Definition: render.h:34
Definition: console.h:45
Definition: ghost.h:32
Definition: ghost.h:19
@ MAX_NAME_LENGTH
Definition: protocol.h:97
@ GHOSTDATA_TYPE_START_TICK
Definition: ghost.h:19
@ GHOSTDATA_TYPE_CHARACTER_NO_TICK
Definition: ghost.h:17
@ GHOSTDATA_TYPE_CHARACTER
Definition: ghost.h:18
@ GHOSTDATA_TYPE_SKIN
Definition: ghost.h:16
Definition: ghost.h:36
int m_HookState
Definition: ghost.h:44
int m_HookY
Definition: ghost.h:46
int m_VelX
Definition: ghost.h:39
int m_HookX
Definition: ghost.h:45
int m_VelY
Definition: ghost.h:40
int m_Angle
Definition: ghost.h:41
int m_Direction
Definition: ghost.h:42
int m_X
Definition: ghost.h:37
int m_Weapon
Definition: ghost.h:43
int m_AttackTick
Definition: ghost.h:47
int m_Y
Definition: ghost.h:38
Definition: ghost.h:51
int m_Tick
Definition: ghost.h:52
Definition: ghost.h:23
int m_ColorBody
Definition: ghost.h:31
int m_Skin4
Definition: ghost.h:28
int m_Skin2
Definition: ghost.h:26
int m_Skin3
Definition: ghost.h:27
int m_UseCustomColor
Definition: ghost.h:30
int m_Skin1
Definition: ghost.h:25
int m_ColorFeet
Definition: ghost.h:32
int m_Skin5
Definition: ghost.h:29
int m_Skin0
Definition: ghost.h:24
Definition: menus.h:756
Definition: protocol.h:455
Definition: protocol.h:513
@ IO_MAX_PATH_LENGTH
Definition: types.h:43