DDraceNetwork Docs
entity.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 GAME_SERVER_ENTITY_H
4#define GAME_SERVER_ENTITY_H
5
6#include <base/vmath.h>
7
8#include <game/alloc.h>
9
10#include "gameworld.h"
11#include "save.h"
12
13class CCollision;
14class CGameContext;
15
16/*
17 Class: Entity
18 Basic entity class.
19*/
20class CEntity
21{
23
24private:
25 friend CGameWorld; // entity list handling
28
29 /* Identity */
32
33 int m_Id;
34 int m_ObjType;
35
36 /*
37 Variable: m_ProximityRadius
38 Contains the physical size of the entity.
39 */
41
42protected:
43 /* State */
45
46public: // TODO: Maybe make protected
47 /*
48 Variable: m_Pos
49 Contains the current posititon of the entity.
50 */
51 vec2 m_Pos;
52
53 /* Getters */
54 int GetId() const { return m_Id; }
55
56 /* Constructor */
57 CEntity(CGameWorld *pGameWorld, int Objtype, vec2 Pos = vec2(0, 0), int ProximityRadius = 0);
58
59 /* Destructor */
60 virtual ~CEntity();
61
62 /* Objects */
63 std::vector<SSwitchers> &Switchers() { return m_pGameWorld->m_Core.m_vSwitchers; }
67 CTuningParams *GetTuning(int i) { return GameWorld()->GetTuning(i); }
68 class CConfig *Config() { return m_pGameWorld->Config(); }
70 class IServer *Server() { return m_pGameWorld->Server(); }
72
73 /* Getters */
76 const vec2 &GetPos() const { return m_Pos; }
77 float GetProximityRadius() const { return m_ProximityRadius; }
78
79 /* Other functions */
80
81 /*
82 Function: Destroy
83 Destroys the entity.
84 */
85 virtual void Destroy() { delete this; }
86
87 /*
88 Function: Reset
89 Called when the game resets the map. Puts the entity
90 back to its starting state or perhaps destroys it.
91 */
92 virtual void Reset() {}
93
94 /*
95 Function: Tick
96 Called to progress the entity to the next tick. Updates
97 and moves the entity to its new state and position.
98 */
99 virtual void Tick() {}
100
101 /*
102 Function: TickDeferred
103 Called after all entities Tick() function has been called.
104 */
105 virtual void TickDeferred() {}
106
107 /*
108 Function: TickPaused
109 Called when the game is paused, to freeze the state and position of the entity.
110 */
111 virtual void TickPaused() {}
112
113 /*
114 Function: Snap
115 Called when a new snapshot is being generated for a specific
116 client.
117
118 Arguments:
119 SnappingClient - ID of the client which snapshot is
120 being generated. Could be -1 to create a complete
121 snapshot of everything in the game for demo
122 recording.
123 */
124 virtual void Snap(int SnappingClient) {}
125
126 /*
127 Function: PostSnap
128 Called after all clients received their snapshot.
129 */
130 virtual void PostSnap() {}
131
132 /*
133 Function: SwapClients
134 Called when two players have swapped their client ids.
135
136 Arguments:
137 Client1 - First client ID
138 Client2 - Second client ID
139 */
140 virtual void SwapClients(int Client1, int Client2) {}
141
142 /*
143 Function: BlocksSave
144 Called to check if a team can be saved
145
146 Arguments:
147 ClientId - Client ID
148 */
149 virtual ESaveResult BlocksSave(int ClientId) { return ESaveResult::SUCCESS; }
150
151 /*
152 Function GetOwnerId
153 Returns:
154 ClientId of the initiator from this entity. -1 created by map.
155 This is used by save/load to remove related entities to the tee.
156 CCharacter should not return the PlayerId, because they get
157 handled separately in save/load code.
158 */
159 virtual int GetOwnerId() const { return -1; }
160
161 /*
162 Function: NetworkClipped
163 Performs a series of test to see if a client can see the
164 entity.
165
166 Arguments:
167 SnappingClient - ID of the client which snapshot is
168 being generated. Could be -1 to create a complete
169 snapshot of everything in the game for demo
170 recording.
171
172 Returns:
173 True if the entity doesn't have to be in the snapshot.
174 */
175 bool NetworkClipped(int SnappingClient) const;
176 bool NetworkClipped(int SnappingClient, vec2 CheckPos) const;
177 bool NetworkClippedLine(int SnappingClient, vec2 StartPos, vec2 EndPos) const;
178
179 bool GameLayerClipped(vec2 CheckPos);
180
181 // DDRace
182
183 bool GetNearestAirPos(vec2 Pos, vec2 PrevPos, vec2 *pOutPos);
184 bool GetNearestAirPosPlayer(vec2 PlayerPos, vec2 *pOutPos);
185
186 int m_Number;
187 int m_Layer;
188};
189
190bool NetworkClipped(const CGameContext *pGameServer, int SnappingClient, vec2 CheckPos);
191bool NetworkClippedLine(const CGameContext *pGameServer, int SnappingClient, vec2 StartPos, vec2 EndPos);
192
193#endif
#define MACRO_ALLOC_HEAP()
Definition: alloc.h:21
Definition: collision.h:34
Definition: config.h:23
Definition: entity.h:13
float m_ProximityRadius
Definition: entity.h:50
CGameWorld * GameWorld()
Definition: entity.h:64
virtual ESaveResult BlocksSave(int ClientId)
Definition: entity.h:149
bool NetworkClippedLine(int SnappingClient, vec2 StartPos, vec2 EndPos) const
Definition: entity.cpp:43
class CGameContext * GameServer()
Definition: entity.h:69
int GetId() const
Definition: entity.h:28
virtual ~CEntity()
class IServer * Server()
Definition: entity.h:70
bool m_MarkedForDestroy
Definition: entity.h:23
std::vector< SSwitchers > & Switchers()
Definition: entity.h:63
const vec2 & GetPos() const
Definition: entity.h:76
CEntity * m_pNextTypeEntity
Definition: entity.h:19
bool NetworkClipped(int SnappingClient) const
Definition: entity.cpp:33
CGameWorld * m_pGameWorld
Definition: entity.h:22
CCollision * Collision()
Definition: entity.h:71
CCollision * m_pCCollision
Definition: entity.h:31
class CConfig * Config()
Definition: entity.h:68
vec2 m_Pos
Definition: entity.h:51
CTuningParams * GetTuning(int i)
Definition: entity.h:67
virtual void TickDeferred()
Definition: entity.h:105
float GetProximityRadius() const
Definition: entity.h:77
int m_Layer
Definition: entity.h:53
CTuningParams * TuningList()
Definition: entity.h:66
CEntity * m_pPrevTypeEntity
Definition: entity.h:18
CEntity * TypeNext()
Definition: entity.h:74
virtual void Tick()
Definition: entity.h:99
CEntity(CGameWorld *pGameWorld, int Objtype, vec2 Pos=vec2(0, 0), int ProximityRadius=0)
CEntity * TypePrev()
Definition: entity.h:75
virtual void Snap(int SnappingClient)
Definition: entity.h:124
virtual void PostSnap()
Definition: entity.h:130
CTuningParams * Tuning()
Definition: entity.h:65
virtual void SwapClients(int Client1, int Client2)
Definition: entity.h:140
virtual void Destroy()
Definition: entity.h:85
bool GetNearestAirPosPlayer(vec2 PlayerPos, vec2 *pOutPos)
Definition: entity.cpp:77
virtual int GetOwnerId() const
Definition: entity.h:159
bool GetNearestAirPos(vec2 Pos, vec2 PrevPos, vec2 *pOutPos)
Definition: entity.cpp:54
int m_Number
Definition: entity.h:52
int m_ObjType
Definition: entity.h:25
virtual void Reset()
Definition: entity.h:92
bool GameLayerClipped(vec2 CheckPos)
virtual void TickPaused()
Definition: entity.h:111
int m_Id
Definition: entity.h:24
Definition: gamecontext.h:79
Definition: gameworld.h:17
CTuningParams * TuningList()
Definition: gameworld.h:103
CTuningParams * Tuning()
Definition: gameworld.cpp:319
class IServer * Server()
Definition: gameworld.h:47
class CConfig * Config()
Definition: gameworld.h:46
class CGameContext * GameServer()
Definition: gameworld.h:45
CWorldCore m_Core
Definition: gameworld.h:34
CTuningParams * GetTuning(int i)
Definition: gameworld.h:104
Definition: gamecore.h:41
std::vector< SSwitchers > m_vSwitchers
Definition: gamecore.h:172
Definition: server.h:30
ESaveResult
Definition: save.h:23
bool NetworkClipped(const CGameContext *pGameServer, int SnappingClient, vec2 CheckPos)
Definition: entity.cpp:90
bool NetworkClippedLine(const CGameContext *pGameServer, int SnappingClient, vec2 StartPos, vec2 EndPos)
Definition: entity.cpp:103
vector2_base< float > vec2
Definition: vmath.h:158