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_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;
15
17{
18public:
19 enum
20 {
32 };
33
36
37 CGameWorld();
39
40 CEntity *FindFirst(int Type);
41 CEntity *FindLast(int Type);
42 int FindEntities(vec2 Pos, float Radius, CEntity **ppEnts, int Max, int Type);
43 CCharacter *IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, vec2 &NewPos, const CCharacter *pNotThis = nullptr, int CollideWith = -1, const CCharacter *pThisOnly = nullptr);
44 void InsertEntity(CEntity *pEntity, bool Last = false);
45 void RemoveEntity(CEntity *pEntity);
46 void RemoveCharacter(CCharacter *pChar);
47 void Tick();
48
49 // DDRace
50 void ReleaseHooked(int ClientId);
51 std::vector<CCharacter *> IntersectedCharacters(vec2 Pos0, vec2 Pos1, float Radius, const CEntity *pNotThis = nullptr);
52
55
56 // getter for server variables
57 int GameTick() { return m_GameTick; }
60 CTeamsCore *Teams() { return &m_Teams; }
61 std::vector<SSwitchers> &Switchers() { return m_Core.m_vSwitchers; }
63 CEntity *GetEntity(int Id, int EntityType);
64 CCharacter *GetCharacterById(int Id) { return (Id >= 0 && Id < MAX_CLIENTS) ? m_apCharacters[Id] : nullptr; }
65
66 // from gamecontext
67 void CreateExplosion(vec2 Pos, int Owner, int Weapon, bool NoDamage, int ActivatedTeam, CClientMask Mask);
68
69 // for client side prediction
70 struct
71 {
74 bool m_IsFNG;
85
89
91
92 bool IsLocalTeam(int OwnerId) const;
93 void OnModified() const;
94 void NetObjBegin(CTeamsCore Teams, int LocalClientId);
95 void NetCharAdd(int ObjId, CNetObj_Character *pChar, CNetObj_DDNetCharacter *pExtended, int GameTeam, bool IsLocal);
96 void NetObjAdd(int ObjId, int ObjType, const void *pObjData, const CNetObj_EntityEx *pDataEx);
97 void NetObjEnd();
98 void CopyWorld(CGameWorld *pFrom);
99 CEntity *FindMatch(int ObjId, int ObjType, const void *pObjData);
100 void Clear();
101
104 CTuningParams *GetTuning(int i) { return &TuningList()[i]; }
105
106private:
107 void RemoveEntities();
108
111
113};
114
116{
117public:
118 std::list<int> m_Ids; // reverse of the order in the gameworld, since entities will be inserted in reverse
120 {
121 Reset();
122 }
123 void Reset()
124 {
125 m_Ids.clear();
126 for(int i = 0; i < MAX_CLIENTS; i++)
127 m_Ids.push_back(i);
128 }
129 void GiveStrong(int c)
130 {
131 if(0 <= c && c < MAX_CLIENTS)
132 {
133 m_Ids.remove(c);
134 m_Ids.push_front(c);
135 }
136 }
137 void GiveWeak(int c)
138 {
139 if(0 <= c && c < MAX_CLIENTS)
140 {
141 m_Ids.remove(c);
142 m_Ids.push_back(c);
143 }
144 }
145 bool HasStrongAgainst(int From, int To)
146 {
147 for(int i : m_Ids)
148 {
149 if(i == To)
150 return false;
151 else if(i == From)
152 return true;
153 }
154 return false;
155 }
156};
157
158#endif
Definition: gameworld.h:116
void GiveStrong(int c)
Definition: gameworld.h:129
void Reset()
Definition: gameworld.h:123
void GiveWeak(int c)
Definition: gameworld.h:137
bool HasStrongAgainst(int From, int To)
Definition: gameworld.h:145
std::list< int > m_Ids
Definition: gameworld.h:118
CCharOrder()
Definition: gameworld.h:119
Definition: character.h:30
Definition: collision.h:34
Definition: entity.h:13
Definition: gameworld.h:17
bool m_InfiniteAmmo
Definition: gameworld.h:75
void CopyWorld(CGameWorld *pFrom)
Definition: gameworld.cpp:582
void CreateExplosion(vec2 Pos, int Owner, int Weapon, bool NoDamage, int ActivatedTeam, CClientMask Mask)
Definition: gameworld.cpp:332
CGameWorld * m_pParent
Definition: gameworld.h:87
CTuningParams * TuningList()
Definition: gameworld.h:103
bool m_IsDDRace
Definition: gameworld.h:72
void OnModified() const
Definition: gameworld.cpp:698
bool m_BugDDRaceInput
Definition: gameworld.h:82
CCharacter * IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, vec2 &NewPos, const CCharacter *pNotThis=nullptr, int CollideWith=-1, const CCharacter *pThisOnly=nullptr)
Definition: gameworld.cpp:247
bool m_IsSolo
Definition: gameworld.h:80
bool m_UseTuneZones
Definition: gameworld.h:81
CCharacter * m_apCharacters[MAX_CLIENTS]
Definition: gameworld.h:112
CGameWorld * m_pChild
Definition: gameworld.h:88
void Clear()
Definition: gameworld.cpp:704
CTuningParams * Tuning()
Definition: gameworld.cpp:319
void InsertEntity(CEntity *pEntity, bool Last=false)
Definition: gameworld.cpp:81
CTuningParams * m_pTuningList
Definition: gameworld.h:102
bool m_IsFNG
Definition: gameworld.h:74
void RemoveCharacter(CCharacter *pChar)
Definition: gameworld.cpp:160
CEntity * m_pNextTraverseEntity
Definition: gameworld.h:109
bool m_PredictWeapons
Definition: gameworld.h:78
void Tick()
Definition: gameworld.cpp:185
bool m_IsVanilla
Definition: gameworld.h:73
void RemoveEntities()
Definition: gameworld.cpp:170
int GameTickSpeed()
Definition: gameworld.h:58
CGameWorld()
Definition: gameworld.cpp:22
CEntity * FindMatch(int ObjId, int ObjType, const void *pObjData)
Definition: gameworld.cpp:636
CEntity * FindFirst(int Type)
Definition: gameworld.cpp:46
struct CGameWorld::@169 m_WorldConfig
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
~CGameWorld()
Definition: gameworld.cpp:34
int m_PredictFreeze
Definition: gameworld.h:77
int m_GameTick
Definition: gameworld.h:53
std::vector< SSwitchers > & Switchers()
Definition: gameworld.h:61
CEntity * FindLast(int Type)
Definition: gameworld.cpp:51
CEntity * m_apFirstEntityTypes[NUM_ENTTYPES]
Definition: gameworld.h:110
void NetObjAdd(int ObjId, int ObjType, const void *pObjData, const CNetObj_EntityEx *pDataEx)
Definition: gameworld.cpp:413
CCharacter * GetCharacterById(int Id)
Definition: gameworld.h:64
void NetCharAdd(int ObjId, CNetObj_Character *pChar, CNetObj_DDNetCharacter *pExtended, int GameTeam, bool IsLocal)
Definition: gameworld.cpp:392
CTuningParams * GetTuning(int i)
Definition: gameworld.h:104
CTeamsCore * Teams()
Definition: gameworld.h:60
CCollision * Collision()
Definition: gameworld.h:59
void NetObjBegin(CTeamsCore Teams, int LocalClientId)
Definition: gameworld.cpp:377
bool m_PredictTiles
Definition: gameworld.h:76
bool IsLocalTeam(int OwnerId) const
Definition: gameworld.cpp:372
CEntity * GetEntity(int Id, int EntityType)
Definition: gameworld.cpp:324
std::vector< CCharacter * > IntersectedCharacters(vec2 Pos0, vec2 Pos1, float Radius, const CEntity *pNotThis=nullptr)
Definition: gameworld.cpp:285
int GameTick()
Definition: gameworld.h:57
int FindEntities(vec2 Pos, float Radius, CEntity **ppEnts, int Max, int Type)
Definition: gameworld.cpp:60
@ ENTTYPE_LIGHT
Definition: gameworld.h:25
@ ENTTYPE_PLASMA
Definition: gameworld.h:27
@ ENTTYPE_GUN
Definition: gameworld.h:26
@ ENTTYPE_DOOR
Definition: gameworld.h:23
@ ENTTYPE_DRAGGER
Definition: gameworld.h:24
bool m_IsValidCopy
Definition: gameworld.h:86
void NetObjEnd()
Definition: gameworld.cpp:547
CTeamsCore m_Teams
Definition: gameworld.h:35
int m_LocalClientId
Definition: gameworld.h:90
void ReleaseHooked(int ClientId)
Definition: gameworld.cpp:307
CCollision * m_pCollision
Definition: gameworld.h:54
void RemoveEntity(CEntity *pEntity)
Definition: gameworld.cpp:125
bool m_PredictDDRace
Definition: gameworld.h:79
bool m_NoWeakHookAndBounce
Definition: gameworld.h:83
Definition: teamscore.h:25
Definition: gamecore.h:41
Definition: gamecore.h:144
std::vector< SSwitchers > m_vSwitchers
Definition: gamecore.h:172
std::bitset< MAX_CLIENTS > CClientMask
Definition: protocol.h:132
@ SERVER_TICK_SPEED
Definition: protocol.h:80
@ MAX_CLIENTS
Definition: protocol.h:88
Definition: protocol.h:455
Definition: protocol.h:513
Definition: protocol.h:661