DDraceNetwork Docs
collision.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_COLLISION_H
4#define GAME_COLLISION_H
5
6#include <base/vmath.h>
8
9#include <map>
10#include <vector>
11
12class CTile;
13class CLayers;
14class CTeleTile;
15class CSpeedupTile;
16class CSwitchTile;
17class CTuneTile;
18class CDoorTile;
19
20enum
21{
22 CANTMOVE_LEFT = 1 << 0,
24 CANTMOVE_UP = 1 << 2,
25 CANTMOVE_DOWN = 1 << 3,
26};
27
28vec2 ClampVel(int MoveRestriction, vec2 Vel);
29
30typedef bool (*CALLBACK_SWITCHACTIVE)(int Number, void *pUser);
31struct CAntibotMapData;
32
34{
35public:
36 CCollision();
38
39 void Init(CLayers *pLayers);
40 void Unload();
41 void FillAntibot(CAntibotMapData *pMapData) const;
42
43 bool CheckPoint(float x, float y) const { return IsSolid(round_to_int(x), round_to_int(y)); }
44 bool CheckPoint(vec2 Pos) const { return CheckPoint(Pos.x, Pos.y); }
45 int GetCollisionAt(float x, float y) const { return GetTile(round_to_int(x), round_to_int(y)); }
46 int GetWidth() const { return m_Width; }
47 int GetHeight() const { return m_Height; }
48 int IntersectLine(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision) const;
49 int IntersectLineTeleWeapon(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision, int *pTeleNr = nullptr) const;
50 int IntersectLineTeleHook(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision, int *pTeleNr = nullptr) const;
51 void MovePoint(vec2 *pInoutPos, vec2 *pInoutVel, float Elasticity, int *pBounces) const;
52 void MoveBox(vec2 *pInoutPos, vec2 *pInoutVel, vec2 Size, vec2 Elasticity, bool *pGrounded = nullptr) const;
53 bool TestBox(vec2 Pos, vec2 Size) const;
54
55 // DDRace
56 void SetCollisionAt(float x, float y, int Index);
57 void SetDCollisionAt(float x, float y, int Type, int Flags, int Number);
58 int GetDTileIndex(int Index) const;
59 int GetDTileFlags(int Index) const;
60 int GetDTileNumber(int Index) const;
61 int GetFCollisionAt(float x, float y) const { return GetFTile(round_to_int(x), round_to_int(y)); }
62 int IntersectNoLaser(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision) const;
63 int IntersectNoLaserNW(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision) const;
64 int IntersectAir(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision) const;
65 int GetIndex(int x, int y) const;
66 int GetIndex(vec2 PrevPos, vec2 Pos) const;
67 int GetFIndex(int x, int y) const;
68
69 int GetMoveRestrictions(CALLBACK_SWITCHACTIVE pfnSwitchActive, void *pUser, vec2 Pos, float Distance = 18.0f, int OverrideCenterTileIndex = -1) const;
70 int GetMoveRestrictions(vec2 Pos, float Distance = 18.0f) const
71 {
72 return GetMoveRestrictions(nullptr, nullptr, Pos, Distance);
73 }
74
75 int GetTile(int x, int y) const;
76 int GetFTile(int x, int y) const;
77 int Entity(int x, int y, int Layer) const;
78 int GetPureMapIndex(float x, float y) const;
79 int GetPureMapIndex(vec2 Pos) const { return GetPureMapIndex(Pos.x, Pos.y); }
80 std::vector<int> GetMapIndices(vec2 PrevPos, vec2 Pos, unsigned MaxIndices = 0) const;
81 int GetMapIndex(vec2 Pos) const;
82 bool TileExists(int Index) const;
83 bool TileExistsNext(int Index) const;
84 vec2 GetPos(int Index) const;
85 int GetTileIndex(int Index) const;
86 int GetFTileIndex(int Index) const;
87 int GetTileFlags(int Index) const;
88 int GetFTileFlags(int Index) const;
89 int IsTeleport(int Index) const;
90 int IsEvilTeleport(int Index) const;
91 bool IsCheckTeleport(int Index) const;
92 bool IsCheckEvilTeleport(int Index) const;
93 int IsTeleportWeapon(int Index) const;
94 int IsTeleportHook(int Index) const;
95 int IsTeleCheckpoint(int Index) const;
96 int IsSpeedup(int Index) const;
97 int IsTune(int Index) const;
98 void GetSpeedup(int Index, vec2 *pDir, int *pForce, int *pMaxSpeed) const;
99 int GetSwitchType(int Index) const;
100 int GetSwitchNumber(int Index) const;
101 int GetSwitchDelay(int Index) const;
102
103 int IsSolid(int x, int y) const;
104 bool IsThrough(int x, int y, int OffsetX, int OffsetY, vec2 Pos0, vec2 Pos1) const;
105 bool IsHookBlocker(int x, int y, vec2 Pos0, vec2 Pos1) const;
106 int IsWallJump(int Index) const;
107 int IsNoLaser(int x, int y) const;
108 int IsFNoLaser(int x, int y) const;
109
110 int IsTimeCheckpoint(int Index) const;
111 int IsFTimeCheckpoint(int Index) const;
112
113 int IsMover(int x, int y, int *pFlags) const;
114
115 vec2 CpSpeed(int index, int Flags = 0) const;
116
117 const CLayers *Layers() const { return m_pLayers; }
118 const CTile *GameLayer() const { return m_pTiles; }
119 const CTeleTile *TeleLayer() const { return m_pTele; }
120 const CSpeedupTile *SpeedupLayer() const { return m_pSpeedup; }
121 const CTile *FrontLayer() const { return m_pFront; }
122 const CSwitchTile *SwitchLayer() const { return m_pSwitch; }
123 const CTuneTile *TuneLayer() const { return m_pTune; }
124
126
137 vec2 TeleAllGet(int Number, size_t Offset);
138
143 size_t TeleAllSize(int Number);
144
145 const std::vector<vec2> &TeleIns(int Number) { return m_TeleIns[Number]; }
146 const std::vector<vec2> &TeleOuts(int Number) { return m_TeleOuts[Number]; }
147 const std::vector<vec2> &TeleCheckOuts(int Number) { return m_TeleCheckOuts[Number]; }
148 const std::vector<vec2> &TeleOthers(int Number) { return m_TeleOthers[Number]; }
149
150private:
152
155
163
164 // TILE_TELEIN
165 std::map<int, std::vector<vec2>> m_TeleIns;
166 // TILE_TELEOUT
167 std::map<int, std::vector<vec2>> m_TeleOuts;
168 // TILE_TELECHECKOUT
169 std::map<int, std::vector<vec2>> m_TeleCheckOuts;
170 // TILE_TELEINEVIL, TILE_TELECHECK, TILE_TELECHECKIN, TILE_TELECHECKINEVIL
171 std::map<int, std::vector<vec2>> m_TeleOthers;
172};
173
174void ThroughOffset(vec2 Pos0, vec2 Pos1, int *pOffsetX, int *pOffsetY);
175#endif
Definition: collision.h:34
const CSpeedupTile * SpeedupLayer() const
Definition: collision.h:120
int IsTeleportHook(int Index) const
Definition: collision.cpp:712
bool TileExists(int Index) const
Definition: collision.cpp:843
CLayers * m_pLayers
Definition: collision.h:151
int GetTileFlags(int Index) const
Definition: collision.cpp:985
int IntersectNoLaser(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision) const
Definition: collision.cpp:1156
std::map< int, std::vector< vec2 > > m_TeleIns
Definition: collision.h:165
std::map< int, std::vector< vec2 > > m_TeleOuts
Definition: collision.h:167
int GetSwitchDelay(int Index) const
Definition: collision.cpp:778
int GetFIndex(int x, int y) const
Definition: collision.cpp:1036
int GetTile(int x, int y) const
Definition: collision.cpp:315
~CCollision()
Definition: collision.cpp:45
CTuneTile * m_pTune
Definition: collision.h:161
int IsMover(int x, int y, int *pFlags) const
Definition: collision.cpp:789
std::vector< int > GetMapIndices(vec2 PrevPos, vec2 Pos, unsigned MaxIndices=0) const
Definition: collision.cpp:919
vec2 GetPos(int Index) const
Definition: collision.cpp:961
void Init(CLayers *pLayers)
Definition: collision.cpp:50
const CTuneTile * TuneLayer() const
Definition: collision.h:123
int GetFTileFlags(int Index) const
Definition: collision.cpp:992
int GetWidth() const
Definition: collision.h:46
int GetDTileIndex(int Index) const
Definition: collision.cpp:1101
int GetDTileFlags(int Index) const
Definition: collision.cpp:1117
int IsWallJump(int Index) const
Definition: collision.cpp:631
void GetSpeedup(int Index, vec2 *pDir, int *pForce, int *pMaxSpeed) const
Definition: collision.cpp:745
int IsSpeedup(int Index) const
Definition: collision.cpp:723
int GetIndex(int x, int y) const
Definition: collision.cpp:999
bool IsCheckEvilTeleport(int Index) const
Definition: collision.cpp:680
CTeleTile * m_pTele
Definition: collision.h:157
int GetTileIndex(int Index) const
Definition: collision.cpp:971
const std::vector< vec2 > & TeleCheckOuts(int Number)
Definition: collision.h:147
int GetFTileIndex(int Index) const
Definition: collision.cpp:978
int IntersectAir(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision) const
Definition: collision.cpp:1216
std::map< int, std::vector< vec2 > > m_TeleOthers
Definition: collision.h:171
int IsSolid(int x, int y) const
Definition: collision.cpp:599
CSpeedupTile * m_pSpeedup
Definition: collision.h:158
CSwitchTile * m_pSwitch
Definition: collision.h:160
bool IsThrough(int x, int y, int OffsetX, int OffsetY, vec2 Pos0, vec2 Pos1) const
Definition: collision.cpp:605
size_t TeleAllSize(int Number)
Definition: collision.cpp:1300
void Unload()
Definition: collision.cpp:151
int IsTeleCheckpoint(int Index) const
Definition: collision.cpp:687
int IsNoLaser(int x, int y) const
Definition: collision.cpp:639
int m_Width
Definition: collision.h:153
CDoorTile * m_pDoor
Definition: collision.h:162
const CTile * GameLayer() const
Definition: collision.h:118
int GetPureMapIndex(vec2 Pos) const
Definition: collision.h:79
int IsFTimeCheckpoint(int Index) const
Definition: collision.cpp:1258
int IntersectLineTeleWeapon(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision, int *pTeleNr=nullptr) const
Definition: collision.cpp:421
CTile * m_pFront
Definition: collision.h:159
bool CheckPoint(vec2 Pos) const
Definition: collision.h:44
int GetMapIndex(vec2 Pos) const
Definition: collision.cpp:907
int GetMoveRestrictions(CALLBACK_SWITCHACTIVE pfnSwitchActive, void *pUser, vec2 Pos, float Distance=18.0f, int OverrideCenterTileIndex=-1) const
Definition: collision.cpp:266
void FillAntibot(CAntibotMapData *pMapData) const
Definition: collision.cpp:174
int m_HighestSwitchNumber
Definition: collision.h:125
vec2 CpSpeed(int index, int Flags=0) const
Definition: collision.cpp:803
bool IsCheckTeleport(int Index) const
Definition: collision.cpp:673
int GetHeight() const
Definition: collision.h:47
const std::vector< vec2 > & TeleOthers(int Number)
Definition: collision.h:148
int GetMoveRestrictions(vec2 Pos, float Distance=18.0f) const
Definition: collision.h:70
void MoveBox(vec2 *pInoutPos, vec2 *pInoutVel, vec2 Size, vec2 Elasticity, bool *pGrounded=nullptr) const
Definition: collision.cpp:522
int IntersectLineTeleHook(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision, int *pTeleNr=nullptr) const
Definition: collision.cpp:361
void SetDCollisionAt(float x, float y, int Type, int Flags, int Number)
Definition: collision.cpp:1089
bool CheckPoint(float x, float y) const
Definition: collision.h:43
bool IsHookBlocker(int x, int y, vec2 Pos0, vec2 Pos1) const
Definition: collision.cpp:616
int IntersectNoLaserNW(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision) const
Definition: collision.cpp:1187
int IsFNoLaser(int x, int y) const
Definition: collision.cpp:644
int GetDTileNumber(int Index) const
Definition: collision.cpp:1108
int GetPureMapIndex(float x, float y) const
Definition: collision.cpp:836
bool TileExistsNext(int Index) const
Definition: collision.cpp:865
int IntersectLine(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision) const
Definition: collision.cpp:330
int IsTune(int Index) const
Definition: collision.cpp:734
CTile * m_pTiles
Definition: collision.h:156
CCollision()
Definition: collision.cpp:39
int GetSwitchNumber(int Index) const
Definition: collision.cpp:767
const CTeleTile * TeleLayer() const
Definition: collision.h:119
void SetCollisionAt(float x, float y, int Index)
Definition: collision.cpp:1081
int IsEvilTeleport(int Index) const
Definition: collision.cpp:660
const std::vector< vec2 > & TeleOuts(int Number)
Definition: collision.h:146
int GetSwitchType(int Index) const
Definition: collision.cpp:756
int GetCollisionAt(float x, float y) const
Definition: collision.h:45
int IsTeleportWeapon(int Index) const
Definition: collision.cpp:701
const CTile * FrontLayer() const
Definition: collision.h:121
void MovePoint(vec2 *pInoutPos, vec2 *pInoutVel, float Elasticity, int *pBounces) const
Definition: collision.cpp:470
int IsTimeCheckpoint(int Index) const
Definition: collision.cpp:1247
int GetFTile(int x, int y) const
Definition: collision.cpp:1043
int m_Height
Definition: collision.h:154
vec2 TeleAllGet(int Number, size_t Offset)
Definition: collision.cpp:1269
std::map< int, std::vector< vec2 > > m_TeleCheckOuts
Definition: collision.h:169
const std::vector< vec2 > & TeleIns(int Number)
Definition: collision.h:145
const CSwitchTile * SwitchLayer() const
Definition: collision.h:122
const CLayers * Layers() const
Definition: collision.h:117
bool TestBox(vec2 Pos, vec2 Size) const
Definition: collision.cpp:508
int GetFCollisionAt(float x, float y) const
Definition: collision.h:61
int IsTeleport(int Index) const
Definition: collision.cpp:649
int Entity(int x, int y, int Layer) const
Definition: collision.cpp:1055
Definition: mapitems.h:557
Definition: layers.h:13
Definition: mapitems.h:539
Definition: mapitems.h:548
Definition: mapitems.h:532
Definition: mapitems.h:236
Definition: mapitems.h:565
T x
Definition: vmath.h:19
T y
Definition: vmath.h:23
@ CANTMOVE_LEFT
Definition: collision.h:22
@ CANTMOVE_UP
Definition: collision.h:24
@ CANTMOVE_DOWN
Definition: collision.h:25
@ CANTMOVE_RIGHT
Definition: collision.h:23
vec2 ClampVel(int MoveRestriction, vec2 Vel)
Definition: collision.cpp:18
void ThroughOffset(vec2 Pos0, vec2 Pos1, int *pOffsetX, int *pOffsetY)
Definition: collision.cpp:1124
bool(* CALLBACK_SWITCHACTIVE)(int Number, void *pUser)
Definition: collision.h:30
constexpr int round_to_int(float f)
Definition: math.h:14
Definition: antibot_data.h:17