DDraceNetwork Docs
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
gameworld.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_GAMEWORLD_H
4#define GAME_SERVER_GAMEWORLD_H
5
6#include <game/gamecore.h>
7
8#include "save.h"
9
10#include <vector>
11
12class CEntity;
13class CCharacter;
14
15/*
16 Class: Game World
17 Tracks all entities in the game. Propagates tick and
18 snap calls to all entities.
19*/
20class CGameWorld
21{
22public:
23 enum
24 {
31 };
32
33private:
34 void Reset();
36
39
43
44public:
46 class CConfig *Config() { return m_pConfig; }
47 class IServer *Server() { return m_pServer; }
48
52
55
56 void SetGameServer(CGameContext *pGameServer);
57
58 CEntity *FindFirst(int Type);
59
60 /*
61 Function: FindEntities
62 Finds entities close to a position and returns them in a list.
63
64 Arguments:
65 Pos - Position.
66 Radius - How close the entities have to be.
67 ppEnts - Pointer to a list that should be filled with the pointers
68 to the entities.
69 Max - Number of entities that fits into the ents array.
70 Type - Type of the entities to find.
71
72 Returns:
73 Number of entities found and added to the ents array.
74 */
75 int FindEntities(vec2 Pos, float Radius, CEntity **ppEnts, int Max, int Type);
76
92 CCharacter *IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, vec2 &NewPos, const CCharacter *pNotThis = nullptr, int CollideWith = -1, const CCharacter *pThisOnly = nullptr);
93
110 CEntity *IntersectEntity(vec2 Pos0, vec2 Pos1, float Radius, int Type, vec2 &NewPos, const CEntity *pNotThis = nullptr, int CollideWith = -1, const CEntity *pThisOnly = nullptr);
111
112 /*
113 Function: ClosestCharacter
114 Finds the closest CCharacter to a specific point.
115
116 Arguments:
117 Pos - The center position.
118 Radius - How far off the CCharacter is allowed to be
119 pNotThis - Entity to ignore
120
121 Returns:
122 Returns a pointer to the closest CCharacter or NULL if no CCharacter is close enough.
123 */
124 CCharacter *ClosestCharacter(vec2 Pos, float Radius, const CEntity *pNotThis);
125
126 /*
127 Function: InsertEntity
128 Adds an entity to the world.
129
130 Arguments:
131 pEntity - Entity to add
132 */
133 void InsertEntity(CEntity *pEntity);
134
135 /*
136 Function: RemoveEntity
137 Removes an entity from the world.
138
139 Arguments:
140 pEntity - Entity to remove
141 */
142 void RemoveEntity(CEntity *pEntity);
143
144 void RemoveEntitiesFromPlayer(int PlayerId);
145 void RemoveEntitiesFromPlayers(int PlayerIds[], int NumPlayers);
146
147 /*
148 Function: Snap
149 Calls Snap on all the entities in the world to create
150 the snapshot.
151
152 Arguments:
153 SnappingClient - ID of the client which snapshot
154 is being created.
155 */
156 void Snap(int SnappingClient);
157
158 /*
159 Function: PostSnap
160 Called after all clients received their snapshot.
161 */
162 void PostSnap();
163
164 /*
165 Function: Tick
166 Calls Tick on all the entities in the world to progress
167 the world to the next tick.
168 */
169 void Tick();
170
171 /*
172 Function: SwapClients
173 Calls SwapClients on all the entities in the world to ensure that /swap
174 command is handled safely.
175 */
176 void SwapClients(int Client1, int Client2);
177
178 /*
179 Function: BlocksSave
180 Checks if any entity would block /save
181 */
182 ESaveResult BlocksSave(int ClientId);
183
184 // DDRace
185 void ReleaseHooked(int ClientId);
186
187 /*
188 Function: IntersectedCharacters
189 Finds all CCharacters that intersect the line.
190
191 Arguments:
192 Pos0 - Start position
193 Pos1 - End position
194 Radius - How for from the line the CCharacter is allowed to be.
195 pNotThis - Entity to ignore intersecting with
196
197 Returns:
198 Returns list with all Characters on line.
199 */
200 std::vector<CCharacter *> IntersectedCharacters(vec2 Pos0, vec2 Pos1, float Radius, const CEntity *pNotThis = nullptr);
201
203
206 CTuningParams *GetTuning(int i) { return &TuningList()[i]; }
207};
208
209#endif
Definition: character.h:23
Definition: config.h:23
Definition: entity.h:13
Definition: gamecontext.h:74
Definition: gameworld.h:18
void Snap(int SnappingClient)
Definition: gameworld.cpp:109
CEntity * IntersectEntity(vec2 Pos0, vec2 Pos1, float Radius, int Type, vec2 &NewPos, const CEntity *pNotThis=nullptr, int CollideWith=-1, const CEntity *pThisOnly=nullptr)
bool m_Paused
Definition: gameworld.h:50
CTuningParams * TuningList()
Definition: gameworld.h:205
CCharacter * IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, vec2 &NewPos, const CCharacter *pNotThis=nullptr, int CollideWith=-1, const CCharacter *pThisOnly=nullptr)
CTuningParams * Tuning()
void InsertEntity(CEntity *pEntity, bool Last=false)
Definition: gameworld.cpp:83
class IServer * Server()
Definition: gameworld.h:47
class CConfig * Config()
Definition: gameworld.h:46
CTuningParams * m_pTuningList
Definition: gameworld.h:104
void SetGameServer(CGameContext *pGameServer)
Definition: gameworld.cpp:38
CEntity * m_pNextTraverseEntity
Definition: gameworld.h:114
class CConfig * m_pConfig
Definition: gameworld.h:41
void Tick()
void RemoveEntities()
class CGameContext * GameServer()
Definition: gameworld.h:45
CEntity * FindFirst(int Type)
CWorldCore m_Core
Definition: gameworld.h:35
void PostSnap()
Definition: gameworld.cpp:132
CCharacter * ClosestCharacter(vec2 Pos, float Radius, const CEntity *pNotThis)
Definition: gameworld.cpp:339
void RemoveEntitiesFromPlayer(int PlayerId)
Definition: gameworld.cpp:165
class CGameContext * m_pGameServer
Definition: gameworld.h:40
CEntity * m_apFirstEntityTypes[NUM_ENTTYPES]
Definition: gameworld.h:115
ESaveResult BlocksSave(int ClientId)
Definition: gameworld.cpp:270
void SwapClients(int Client1, int Client2)
Definition: gameworld.cpp:285
CTuningParams * GetTuning(int i)
Definition: gameworld.h:206
std::vector< CCharacter * > IntersectedCharacters(vec2 Pos0, vec2 Pos1, float Radius, const CEntity *pNotThis=nullptr)
int FindEntities(vec2 Pos, float Radius, CEntity **ppEnts, int Max, int Type)
void RemoveEntitiesFromPlayers(int PlayerIds[], int NumPlayers)
Definition: gameworld.cpp:170
class IServer * m_pServer
Definition: gameworld.h:42
@ ENTTYPE_CHARACTER
Definition: gameworld.h:31
@ NUM_ENTTYPES
Definition: gameworld.h:32
@ ENTTYPE_FLAG
Definition: gameworld.h:30
@ ENTTYPE_LASER
Definition: gameworld.h:23
@ ENTTYPE_PROJECTILE
Definition: gameworld.h:22
@ ENTTYPE_PICKUP
Definition: gameworld.h:29
void ReleaseHooked(int ClientId)
void RemoveEntity(CEntity *pEntity)
bool m_ResetRequested
Definition: gameworld.h:49
void Reset()
Definition: gameworld.cpp:145
Definition: gamecore.h:42
Definition: gamecore.h:145
Definition: server.h:31
ESaveResult
Definition: save.h:23