DDraceNetwork Docs
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
77 /*
78 Function: InterserctCharacters
79 Finds the CCharacters that intersects the line. // made for types lasers=1 and doors=0
80
81 Arguments:
82 Pos0 - Start position
83 Pos1 - End position
84 Radius - How for from the line the CCharacter is allowed to be.
85 NewPos - Intersection position
86 pNotThis - Entity to ignore intersecting with
87
88 Returns:
89 Returns a pointer to the closest hit or NULL of there is no intersection.
90 */
91 CCharacter *IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, vec2 &NewPos, const CCharacter *pNotThis = nullptr, int CollideWith = -1, const CCharacter *pThisOnly = nullptr);
92 /*
93 Function: ClosestCharacter
94 Finds the closest CCharacter to a specific point.
95
96 Arguments:
97 Pos - The center position.
98 Radius - How far off the CCharacter is allowed to be
99 pNotThis - Entity to ignore
100
101 Returns:
102 Returns a pointer to the closest CCharacter or NULL if no CCharacter is close enough.
103 */
104 CCharacter *ClosestCharacter(vec2 Pos, float Radius, const CEntity *pNotThis);
105
106 /*
107 Function: InsertEntity
108 Adds an entity to the world.
109
110 Arguments:
111 pEntity - Entity to add
112 */
113 void InsertEntity(CEntity *pEntity);
114
115 /*
116 Function: RemoveEntity
117 Removes an entity from the world.
118
119 Arguments:
120 pEntity - Entity to remove
121 */
122 void RemoveEntity(CEntity *pEntity);
123
124 void RemoveEntitiesFromPlayer(int PlayerId);
125 void RemoveEntitiesFromPlayers(int PlayerIds[], int NumPlayers);
126
127 /*
128 Function: Snap
129 Calls Snap on all the entities in the world to create
130 the snapshot.
131
132 Arguments:
133 SnappingClient - ID of the client which snapshot
134 is being created.
135 */
136 void Snap(int SnappingClient);
137
138 /*
139 Function: PostSnap
140 Called after all clients received their snapshot.
141 */
142 void PostSnap();
143
144 /*
145 Function: Tick
146 Calls Tick on all the entities in the world to progress
147 the world to the next tick.
148 */
149 void Tick();
150
151 /*
152 Function: SwapClients
153 Calls SwapClients on all the entities in the world to ensure that /swap
154 command is handled safely.
155 */
156 void SwapClients(int Client1, int Client2);
157
158 /*
159 Function: BlocksSave
160 Checks if any entity would block /save
161 */
162 ESaveResult BlocksSave(int ClientId);
163
164 // DDRace
165 void ReleaseHooked(int ClientId);
166
167 /*
168 Function: IntersectedCharacters
169 Finds all CCharacters that intersect the line.
170
171 Arguments:
172 Pos0 - Start position
173 Pos1 - End position
174 Radius - How for from the line the CCharacter is allowed to be.
175 pNotThis - Entity to ignore intersecting with
176
177 Returns:
178 Returns list with all Characters on line.
179 */
180 std::vector<CCharacter *> IntersectedCharacters(vec2 Pos0, vec2 Pos1, float Radius, const CEntity *pNotThis = nullptr);
181
183
186 CTuningParams *GetTuning(int i) { return &TuningList()[i]; }
187};
188
189#endif
Definition: character.h:30
Definition: config.h:23
Definition: entity.h:13
Definition: gamecontext.h:79
Definition: gameworld.h:17
void Snap(int SnappingClient)
Definition: gameworld.cpp:109
bool m_Paused
Definition: gameworld.h:50
CTuningParams * TuningList()
Definition: gameworld.h:185
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:81
class IServer * Server()
Definition: gameworld.h:47
class CConfig * Config()
Definition: gameworld.h:46
CTuningParams * m_pTuningList
Definition: gameworld.h:102
void SetGameServer(CGameContext *pGameServer)
Definition: gameworld.cpp:38
CEntity * m_pNextTraverseEntity
Definition: gameworld.h:109
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:34
@ ENTTYPE_CHARACTER
Definition: gameworld.h:30
@ NUM_ENTTYPES
Definition: gameworld.h:31
@ ENTTYPE_FLAG
Definition: gameworld.h:29
@ ENTTYPE_LASER
Definition: gameworld.h:22
@ ENTTYPE_PROJECTILE
Definition: gameworld.h:21
@ ENTTYPE_PICKUP
Definition: gameworld.h:28
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:110
ESaveResult BlocksSave(int ClientId)
Definition: gameworld.cpp:273
void SwapClients(int Client1, int Client2)
Definition: gameworld.cpp:288
CTuningParams * GetTuning(int i)
Definition: gameworld.h:186
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
void ReleaseHooked(int ClientId)
void RemoveEntity(CEntity *pEntity)
bool m_ResetRequested
Definition: gameworld.h:49
void Reset()
Definition: gameworld.cpp:145
Definition: gamecore.h:41
Definition: gamecore.h:144
Definition: server.h:30
ESaveResult
Definition: save.h:23