DDraceNetwork 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 {
76 bool m_IsFNG;
88
92
94
95 bool IsLocalTeam(int OwnerId) const;
96 void OnModified() const;
97 void NetObjBegin(CTeamsCore Teams, int LocalClientId);
98 void NetCharAdd(int ObjId, CNetObj_Character *pChar, CNetObj_DDNetCharacter *pExtended, int GameTeam, bool IsLocal);
99 void NetObjAdd(int ObjId, int ObjType, const void *pObjData, const CNetObj_EntityEx *pDataEx);
100 void NetObjEnd();
101 void CopyWorld(CGameWorld *pFrom);
102 CEntity *FindMatch(int ObjId, int ObjType, const void *pObjData);
103 void Clear();
104
105 const CTuningParams *TuningList() const { return m_pTuningList; }
107 const CTuningParams *GlobalTuning() const { return &TuningList()[0]; }
109 const CTuningParams *GetTuning(int i) const { return &TuningList()[i]; }
110 CTuningParams *GetTuning(int i) { return &TuningList()[i]; }
111
112 bool EmulateBug(int Bug) const;
113
115 {
116 public:
118 vec2 m_Pos; // NetEvent's Pos are integers
119 int m_Id; // identifier to prevent adding the same event multiple times
121
123 bool m_Handled = false;
124
125 CPredictedEvent(int EventId, vec2 Pos, int Id, int Tick, int ExtraInfo = -1) :
126 m_EventId(EventId), m_Pos(vec2((int)Pos.x, (int)Pos.y)), m_Id(Id), m_Tick(Tick), m_ExtraInfo(ExtraInfo)
127 {
128 }
129 };
130
131 std::vector<CPredictedEvent> m_PredictedEvents;
132
133 void CreatePredictedEvent(const CPredictedEvent &NewEvent);
134 bool CheckPredictedEventHandled(const CPredictedEvent &CheckEvent);
136
137 void CreatePredictedSound(vec2 Pos, int SoundId, int Id = -1);
138 void CreatePredictedExplosionEvent(vec2 Pos, int Id = -1);
139 void CreatePredictedHammerHitEvent(vec2 Pos, int Id = -1);
140 void CreatePredictedDamageIndEvent(vec2 Pos, float Angle, int Amount, int Id = -1);
141
142private:
143 void RemoveEntities();
144
147
149
153};
154
156{
157public:
158 std::list<int> m_Ids; // reverse of the order in the gameworld, since entities will be inserted in reverse
160 {
161 Reset();
162 }
163 void Reset()
164 {
165 m_Ids.clear();
166 for(int i = 0; i < MAX_CLIENTS; i++)
167 m_Ids.push_back(i);
168 }
169 void GiveStrong(int c)
170 {
171 if(0 <= c && c < MAX_CLIENTS)
172 {
173 m_Ids.remove(c);
174 m_Ids.push_front(c);
175 }
176 }
177 void GiveWeak(int c)
178 {
179 if(0 <= c && c < MAX_CLIENTS)
180 {
181 m_Ids.remove(c);
182 m_Ids.push_back(c);
183 }
184 }
185 bool HasStrongAgainst(int From, int To)
186 {
187 for(int i : m_Ids)
188 {
189 if(i == To)
190 return false;
191 else if(i == From)
192 return true;
193 }
194 return false;
195 }
196};
197
198#endif
void GiveStrong(int c)
Definition gameworld.h:169
void Reset()
Definition gameworld.h:163
void GiveWeak(int c)
Definition gameworld.h:177
bool HasStrongAgainst(int From, int To)
Definition gameworld.h:185
std::list< int > m_Ids
Definition gameworld.h:158
CCharOrder()
Definition gameworld.h:159
Definition character.h:24
Definition collision.h:35
Definition entity.h:13
Definition gameworld.h:115
int m_Tick
Definition gameworld.h:120
int m_EventId
Definition gameworld.h:117
bool m_Handled
Definition gameworld.h:123
int m_Id
Definition gameworld.h:119
vec2 m_Pos
Definition gameworld.h:118
int m_ExtraInfo
Definition gameworld.h:122
CPredictedEvent(int EventId, vec2 Pos, int Id, int Tick, int ExtraInfo=-1)
Definition gameworld.h:125
void CreatePredictedDamageIndEvent(vec2 Pos, float Angle, int Amount, int Id=-1)
Definition gameworld.cpp:843
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:265
bool m_InfiniteAmmo
Definition gameworld.h:77
struct CGameWorld::@374364017024323233174015331257003214132352245305 m_WorldConfig
int GameTick() const
Definition gameworld.h:59
void CopyWorld(CGameWorld *pFrom)
Definition gameworld.cpp:629
CGameWorld * m_pParent
Definition gameworld.h:90
CTuningParams * TuningList()
Definition gameworld.h:106
bool m_IsDDRace
Definition gameworld.h:74
void OnModified() const
Definition gameworld.cpp:761
bool m_BugDDRaceInput
Definition gameworld.h:84
CCharacter * IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, vec2 &NewPos, const CCharacter *pNotThis=nullptr, int CollideWith=-1, const CCharacter *pThisOnly=nullptr)
Definition gameworld.cpp:260
void CreatePredictedExplosionEvent(vec2 Pos, int Id=-1)
Definition gameworld.cpp:831
bool m_IsSolo
Definition gameworld.h:82
bool m_UseTuneZones
Definition gameworld.h:83
const CTuningParams * GetTuning(int i) const
Definition gameworld.h:109
CCharacter * m_apCharacters[MAX_CLIENTS]
Definition gameworld.h:148
CGameWorld * m_pChild
Definition gameworld.h:91
void Clear()
Definition gameworld.cpp:767
CTuningParams * GlobalTuning()
Definition gameworld.h:108
void InsertEntity(CEntity *pEntity, bool Last=false)
Definition gameworld.cpp:95
bool CheckPredictedEventHandled(const CPredictedEvent &CheckEvent)
Definition gameworld.cpp:800
CTuningParams * m_pTuningList
Definition gameworld.h:151
bool m_IsFNG
Definition gameworld.h:76
void RemoveCharacter(CCharacter *pChar)
Definition gameworld.cpp:174
CEntity * m_pNextTraverseEntity
Definition gameworld.h:145
void PlayPredictedEvents(int Tick)
void CreateExplosion(vec2 Pos, int Owner, int Weapon, bool NoDamage, int ActivatedTeam, CClientMask Mask, int Id=-1)
Definition gameworld.cpp:344
bool m_PredictWeapons
Definition gameworld.h:80
void Tick()
Definition gameworld.cpp:199
bool m_IsVanilla
Definition gameworld.h:75
void RemoveEntities()
Definition gameworld.cpp:184
CGameWorld()
Definition gameworld.cpp:29
CEntity * FindMatch(int ObjId, int ObjType, const void *pObjData)
Definition gameworld.cpp:683
CEntity * FindFirst(int Type)
Definition gameworld.cpp:60
CWorldCore m_Core
Definition gameworld.h:35
~CGameWorld()
Definition gameworld.cpp:41
int m_PredictFreeze
Definition gameworld.h:79
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:105
CEntity * FindLast(int Type)
Definition gameworld.cpp:65
CEntity * m_apFirstEntityTypes[NUM_ENTTYPES]
Definition gameworld.h:146
int GameTickSpeed() const
Definition gameworld.h:60
void CreatePredictedHammerHitEvent(vec2 Pos, int Id=-1)
Definition gameworld.cpp:837
void Init(CCollision *pCollision, CTuningParams *pTuningList, const CMapBugs *pMapBugs)
Definition gameworld.cpp:53
void NetObjAdd(int ObjId, int ObjType, const void *pObjData, const CNetObj_EntityEx *pDataEx)
Definition gameworld.cpp:431
CCharacter * GetCharacterById(int Id)
Definition gameworld.h:66
void CreatePredictedSound(vec2 Pos, int SoundId, int Id=-1)
Definition gameworld.cpp:822
void NetCharAdd(int ObjId, CNetObj_Character *pChar, CNetObj_DDNetCharacter *pExtended, int GameTeam, bool IsLocal)
Definition gameworld.cpp:410
CTuningParams * GetTuning(int i)
Definition gameworld.h:110
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:395
bool m_PredictTiles
Definition gameworld.h:78
bool IsLocalTeam(int OwnerId) const
Definition gameworld.cpp:390
CEntity * GetEntity(int Id, int EntityType)
Definition gameworld.cpp:336
std::vector< CCharacter * > IntersectedCharacters(vec2 Pos0, vec2 Pos1, float Radius, const CEntity *pNotThis=nullptr)
Definition gameworld.cpp:302
int FindEntities(vec2 Pos, float Radius, CEntity **ppEnts, int Max, int Type)
Definition gameworld.cpp:74
bool m_IsValidCopy
Definition gameworld.h:89
const CMapBugs * m_pMapBugs
Definition gameworld.h:152
void NetObjEnd()
Definition gameworld.cpp:594
bool m_PredictEvents
Definition gameworld.h:86
CTeamsCore m_Teams
Definition gameworld.h:36
int m_LocalClientId
Definition gameworld.h:93
void ReleaseHooked(int ClientId)
Definition gameworld.cpp:324
CCollision * m_pCollision
Definition gameworld.h:150
void RemoveEntity(CEntity *pEntity)
Definition gameworld.cpp:139
bool m_PredictDDRace
Definition gameworld.h:81
@ 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:780
const CTuningParams * GlobalTuning() const
Definition gameworld.h:107
std::vector< CPredictedEvent > m_PredictedEvents
Definition gameworld.h:131
bool m_NoWeakHookAndBounce
Definition gameworld.h:85
bool EmulateBug(int Bug) const
Definition gameworld.cpp:775
Definition mapbugs.h:22
Definition teamscore.h:25
Definition gamecore.h:43
Definition gamecore.h:148
std::bitset< MAX_CLIENTS > CClientMask
Definition protocol.h:166
@ SERVER_TICK_SPEED
Definition protocol.h:81
@ MAX_CLIENTS
Definition protocol.h:89
Definition protocol.h:520
Definition protocol.h:568
Definition protocol.h:747
vector2_base< float > vec2
Definition vmath.h:161