DDNet documentation
Loading...
Searching...
No Matches
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_CLIENT_PREDICTION_GAMEWORLD_H
4#define GAME_CLIENT_PREDICTION_GAMEWORLD_H
5
6#include <game/gamecore.h>
7#include <game/teamscore.h>
8
9#include <list>
10#include <vector>
11
12class CCollision;
13class CCharacter;
14class CEntity;
15class CMapBugs;
16
18{
19public:
20 enum
21 {
33 };
34
37
38 CGameWorld();
40 void Init(CCollision *pCollision, CTuningParams *pTuningList, const CMapBugs *pMapBugs);
41
42 CEntity *FindFirst(int Type);
43 CEntity *FindLast(int Type);
44 int FindEntities(vec2 Pos, float Radius, CEntity **ppEnts, int Max, int Type);
45 CCharacter *IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, vec2 &NewPos, const CCharacter *pNotThis = nullptr, int CollideWith = -1, const CCharacter *pThisOnly = nullptr);
46 CEntity *IntersectEntity(vec2 Pos0, vec2 Pos1, float Radius, int Type, vec2 &NewPos, const CEntity *pNotThis = nullptr, int CollideWith = -1, const CEntity *pThisOnly = nullptr);
47 void InsertEntity(CEntity *pEntity, bool Last = false);
48 void RemoveEntity(CEntity *pEntity);
49 void RemoveCharacter(CCharacter *pChar);
50 void Tick();
51
52 // DDRace
53 void ReleaseHooked(int ClientId);
54 std::vector<CCharacter *> IntersectedCharacters(vec2 Pos0, vec2 Pos1, float Radius, const CEntity *pNotThis = nullptr);
55
57
58 // getter for server variables
59 int GameTick() const { return m_GameTick; }
60 int GameTickSpeed() const { return SERVER_TICK_SPEED; }
61 const CCollision *Collision() const { return m_pCollision; }
63 CTeamsCore *Teams() { return &m_Teams; }
64 std::vector<SSwitchers> &Switchers() { return m_Core.m_vSwitchers; }
65 CEntity *GetEntity(int Id, int EntityType);
66 CCharacter *GetCharacterById(int Id) { return (Id >= 0 && Id < MAX_CLIENTS) ? m_apCharacters[Id] : nullptr; }
67
68 // from gamecontext
69 void CreateExplosion(vec2 Pos, int Owner, int Weapon, bool NoDamage, int ActivatedTeam, CClientMask Mask, int Id = -1);
70
71 // for client side prediction
72 struct
73 {
74 bool m_IsDDRace;
75 bool m_IsVanilla;
76 bool m_IsFNG;
77 bool m_InfiniteAmmo;
78 bool m_PredictTiles;
81 bool m_PredictDDRace;
82 bool m_IsSolo;
83 bool m_UseTuneZones;
86 bool m_PredictEvents;
87 bool m_OldLaser;
89
93
95
96 bool IsLocalTeam(int OwnerId) const;
97 void OnModified() const;
98 void NetObjBegin(CTeamsCore Teams, int LocalClientId);
99 void NetCharAdd(int ObjId, CNetObj_Character *pChar, CNetObj_DDNetCharacter *pExtended, int GameTeam, bool IsLocal);
100 void NetObjAdd(int ObjId, int ObjType, const void *pObjData, const CNetObj_EntityEx *pDataEx);
101 void ResetDoorCollision();
102 void NetObjEnd();
103 void CopyWorld(CGameWorld *pFrom);
104 CEntity *FindMatch(int ObjId, int ObjType, const void *pObjData);
105 void Clear();
106
107 const CTuningParams *TuningList() const { return m_pTuningList; }
109 const CTuningParams *GlobalTuning() const { return &TuningList()[0]; }
111 const CTuningParams *GetTuning(int i) const { return &TuningList()[i]; }
112 CTuningParams *GetTuning(int i) { return &TuningList()[i]; }
113
114 bool EmulateBug(int Bug) const;
115
117 {
118 public:
120 vec2 m_Pos; // NetEvent's Pos are integers
121 int m_Id; // identifier to prevent adding the same event multiple times
123
125 bool m_Handled = false;
126
127 CPredictedEvent(int EventId, vec2 Pos, int Id, int Tick, int ExtraInfo = -1) :
128 m_EventId(EventId), m_Pos(vec2((int)Pos.x, (int)Pos.y)), m_Id(Id), m_Tick(Tick), m_ExtraInfo(ExtraInfo)
129 {
130 }
131 };
132
133 std::vector<CPredictedEvent> m_PredictedEvents;
134
135 void CreatePredictedEvent(const CPredictedEvent &NewEvent);
136 bool CheckPredictedEventHandled(const CPredictedEvent &CheckEvent);
138
139 void CreatePredictedSound(vec2 Pos, int SoundId, int Id = -1);
140 void CreatePredictedExplosionEvent(vec2 Pos, int Id = -1);
141 void CreatePredictedHammerHitEvent(vec2 Pos, int Id = -1);
142 void CreatePredictedDamageIndEvent(vec2 Pos, float Angle, int Amount, int Id = -1);
143
144private:
145 void RemoveEntities();
146
149
151
155};
156
158{
159public:
160 std::list<int> m_Ids; // reverse of the order in the gameworld, since entities will be inserted in reverse
162 {
163 Reset();
164 }
165 void Reset()
166 {
167 m_Ids.clear();
168 for(int i = 0; i < MAX_CLIENTS; i++)
169 m_Ids.push_back(i);
170 }
171 void GiveStrong(int c)
172 {
173 if(0 <= c && c < MAX_CLIENTS)
174 {
175 m_Ids.remove(c);
176 m_Ids.push_front(c);
177 }
178 }
179 void GiveWeak(int c)
180 {
181 if(0 <= c && c < MAX_CLIENTS)
182 {
183 m_Ids.remove(c);
184 m_Ids.push_back(c);
185 }
186 }
187 bool HasStrongAgainst(int From, int To)
188 {
189 for(int i : m_Ids)
190 {
191 if(i == To)
192 return false;
193 else if(i == From)
194 return true;
195 }
196 return false;
197 }
198};
199
200#endif
void GiveStrong(int c)
Definition gameworld.h:171
void Reset()
Definition gameworld.h:165
void GiveWeak(int c)
Definition gameworld.h:179
bool HasStrongAgainst(int From, int To)
Definition gameworld.h:187
std::list< int > m_Ids
Definition gameworld.h:160
CCharOrder()
Definition gameworld.h:161
Definition character.h:24
Definition collision.h:35
Definition entity.h:13
Definition gameworld.h:117
int m_Tick
Definition gameworld.h:122
int m_EventId
Definition gameworld.h:119
bool m_Handled
Definition gameworld.h:125
int m_Id
Definition gameworld.h:121
vec2 m_Pos
Definition gameworld.h:120
int m_ExtraInfo
Definition gameworld.h:124
CPredictedEvent(int EventId, vec2 Pos, int Id, int Tick, int ExtraInfo=-1)
Definition gameworld.h:127
void CreatePredictedDamageIndEvent(vec2 Pos, float Angle, int Amount, int Id=-1)
Definition gameworld.cpp:883
CEntity * IntersectEntity(vec2 Pos0, vec2 Pos1, float Radius, int Type, vec2 &NewPos, const CEntity *pNotThis=nullptr, int CollideWith=-1, const CEntity *pThisOnly=nullptr)
Definition gameworld.cpp:268
struct CGameWorld::@374364017024323233174015331257003214132352245305 m_WorldConfig
int GameTick() const
Definition gameworld.h:59
void CopyWorld(CGameWorld *pFrom)
Definition gameworld.cpp:669
CGameWorld * m_pParent
Definition gameworld.h:91
CTuningParams * TuningList()
Definition gameworld.h:108
void OnModified() const
Definition gameworld.cpp:801
CCharacter * IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, vec2 &NewPos, const CCharacter *pNotThis=nullptr, int CollideWith=-1, const CCharacter *pThisOnly=nullptr)
Definition gameworld.cpp:263
void CreatePredictedExplosionEvent(vec2 Pos, int Id=-1)
Definition gameworld.cpp:871
const CTuningParams * GetTuning(int i) const
Definition gameworld.h:111
CCharacter * m_apCharacters[MAX_CLIENTS]
Definition gameworld.h:150
CGameWorld * m_pChild
Definition gameworld.h:92
void Clear()
Definition gameworld.cpp:807
CTuningParams * GlobalTuning()
Definition gameworld.h:110
void InsertEntity(CEntity *pEntity, bool Last=false)
Definition gameworld.cpp:96
bool CheckPredictedEventHandled(const CPredictedEvent &CheckEvent)
Definition gameworld.cpp:840
CTuningParams * m_pTuningList
Definition gameworld.h:153
void RemoveCharacter(CCharacter *pChar)
Definition gameworld.cpp:177
CEntity * m_pNextTraverseEntity
Definition gameworld.h:147
void PlayPredictedEvents(int Tick)
void CreateExplosion(vec2 Pos, int Owner, int Weapon, bool NoDamage, int ActivatedTeam, CClientMask Mask, int Id=-1)
Definition gameworld.cpp:347
void Tick()
Definition gameworld.cpp:202
void RemoveEntities()
Definition gameworld.cpp:187
CGameWorld()
Definition gameworld.cpp:30
CEntity * FindMatch(int ObjId, int ObjType, const void *pObjData)
Definition gameworld.cpp:723
CEntity * FindFirst(int Type)
Definition gameworld.cpp:61
CWorldCore m_Core
Definition gameworld.h:35
int m_GameTick
Definition gameworld.h:56
@ ENTTYPE_LIGHT
Definition gameworld.h:26
@ ENTTYPE_PLASMA
Definition gameworld.h:28
@ ENTTYPE_GUN
Definition gameworld.h:27
@ ENTTYPE_DOOR
Definition gameworld.h:24
@ ENTTYPE_DRAGGER
Definition gameworld.h:25
std::vector< SSwitchers > & Switchers()
Definition gameworld.h:64
const CTuningParams * TuningList() const
Definition gameworld.h:107
CEntity * FindLast(int Type)
Definition gameworld.cpp:66
CEntity * m_apFirstEntityTypes[NUM_ENTTYPES]
Definition gameworld.h:148
int GameTickSpeed() const
Definition gameworld.h:60
void CreatePredictedHammerHitEvent(vec2 Pos, int Id=-1)
Definition gameworld.cpp:877
void Init(CCollision *pCollision, CTuningParams *pTuningList, const CMapBugs *pMapBugs)
Definition gameworld.cpp:54
void NetObjAdd(int ObjId, int ObjType, const void *pObjData, const CNetObj_EntityEx *pDataEx)
Definition gameworld.cpp:439
CCharacter * GetCharacterById(int Id)
Definition gameworld.h:66
void CreatePredictedSound(vec2 Pos, int SoundId, int Id=-1)
Definition gameworld.cpp:862
void NetCharAdd(int ObjId, CNetObj_Character *pChar, CNetObj_DDNetCharacter *pExtended, int GameTeam, bool IsLocal)
Definition gameworld.cpp:418
CTuningParams * GetTuning(int i)
Definition gameworld.h:112
CTeamsCore * Teams()
Definition gameworld.h:63
const CCollision * Collision() const
Definition gameworld.h:61
CCollision * Collision()
Definition gameworld.h:62
void NetObjBegin(CTeamsCore Teams, int LocalClientId)
Definition gameworld.cpp:403
bool IsLocalTeam(int OwnerId) const
Definition gameworld.cpp:398
CEntity * GetEntity(int Id, int EntityType)
Definition gameworld.cpp:339
std::vector< CCharacter * > IntersectedCharacters(vec2 Pos0, vec2 Pos1, float Radius, const CEntity *pNotThis=nullptr)
Definition gameworld.cpp:305
int FindEntities(vec2 Pos, float Radius, CEntity **ppEnts, int Max, int Type)
Definition gameworld.cpp:75
bool m_IsValidCopy
Definition gameworld.h:90
const CMapBugs * m_pMapBugs
Definition gameworld.h:154
void NetObjEnd()
Definition gameworld.cpp:633
void ResetDoorCollision()
Definition gameworld.cpp:610
CTeamsCore m_Teams
Definition gameworld.h:36
int m_LocalClientId
Definition gameworld.h:94
void ReleaseHooked(int ClientId)
Definition gameworld.cpp:327
CCollision * m_pCollision
Definition gameworld.h:152
void RemoveEntity(CEntity *pEntity)
Definition gameworld.cpp:142
@ 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 CreatePredictedEvent(const CPredictedEvent &NewEvent)
Definition gameworld.cpp:820
const CTuningParams * GlobalTuning() const
Definition gameworld.h:109
std::vector< CPredictedEvent > m_PredictedEvents
Definition gameworld.h:133
bool EmulateBug(int Bug) const
Definition gameworld.cpp:815
Definition mapbugs.h:22
Definition teamscore.h:26
Definition gamecore.h:42
Definition gamecore.h:149
std::vector< SSwitchers > m_vSwitchers
Definition gamecore.h:176
std::bitset< MAX_CLIENTS > CClientMask
Definition protocol.h:193
@ SERVER_TICK_SPEED
Definition protocol.h:81
@ MAX_CLIENTS
Definition protocol.h:89
vector2_base< float > vec2
Definition vmath.h:168