Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Rubberduckycooly
GitHub Repository: Rubberduckycooly/RSDKv5-Decompilation
Path: blob/master/RSDKv5/RSDK/Scene/Collision.hpp
1167 views
1
#ifndef COLLISION_H
2
#define COLLISION_H
3
4
namespace RSDK
5
{
6
7
enum TileCollisionModes {
8
TILECOLLISION_NONE, // no tile collisions
9
TILECOLLISION_DOWN, // downwards tile collisions
10
#if RETRO_REV0U
11
TILECOLLISION_UP, // upwards tile collisions
12
#endif
13
};
14
15
enum CSides {
16
C_NONE,
17
C_TOP,
18
C_LEFT,
19
C_RIGHT,
20
C_BOTTOM,
21
};
22
23
struct CollisionSensor {
24
Vector2 position;
25
bool32 collided;
26
uint8 angle;
27
};
28
29
#if !RETRO_USE_ORIGINAL_CODE
30
#define DEBUG_HITBOX_COUNT (0x400)
31
32
struct DebugHitboxInfo {
33
uint8 type;
34
uint8 collision;
35
void *entity;
36
Hitbox hitbox;
37
Vector2 pos;
38
};
39
40
enum DebugHitboxTypes { H_TYPE_TOUCH, H_TYPE_CIRCLE, H_TYPE_BOX, H_TYPE_PLAT, H_TYPE_HAMMER };
41
42
extern bool32 showHitboxes;
43
extern int32 debugHitboxCount;
44
extern DebugHitboxInfo debugHitboxList[DEBUG_HITBOX_COUNT];
45
46
int32 AddDebugHitbox(uint8 type, uint8 dir, Entity *entity, Hitbox *hitbox);
47
#endif
48
49
extern int32 collisionTolerance;
50
#if RETRO_REV0U
51
extern bool32 useCollisionOffset;
52
#else
53
extern int32 collisionOffset;
54
#endif
55
extern int32 collisionMaskAir;
56
57
extern Hitbox collisionOuter;
58
extern Hitbox collisionInner;
59
60
extern Entity *collisionEntity;
61
62
extern CollisionSensor sensors[6];
63
64
#if RETRO_REV0U
65
extern int32 collisionMinimumDistance;
66
67
extern uint8 lowCollisionTolerance;
68
extern uint8 highCollisionTolerance;
69
70
extern uint8 floorAngleTolerance;
71
extern uint8 wallAngleTolerance;
72
extern uint8 roofAngleTolerance;
73
74
inline void SetupCollisionConfig(int32 minDistance, uint8 lowTolerance, uint8 highTolerance, uint8 floorAngleTolerance, uint8 wallAngleTolerance,
75
uint8 roofAngleTolerance)
76
{
77
collisionMinimumDistance = TO_FIXED(minDistance);
78
lowCollisionTolerance = lowTolerance;
79
highCollisionTolerance = highTolerance;
80
RSDK::floorAngleTolerance = floorAngleTolerance;
81
RSDK::wallAngleTolerance = wallAngleTolerance;
82
RSDK::roofAngleTolerance = roofAngleTolerance;
83
}
84
#endif
85
86
#if RETRO_REV0U || RETRO_USE_MOD_LOADER
87
void CopyCollisionMask(uint16 dst, uint16 src, uint8 cPlane, uint8 cMode);
88
89
inline void GetCollisionInfo(CollisionMask **masks, TileInfo **tiles)
90
{
91
if (masks)
92
*masks = (RSDK::CollisionMask *)collisionMasks;
93
94
if (tiles)
95
*tiles = (RSDK::TileInfo *)tileInfo;
96
}
97
#endif
98
99
bool32 CheckObjectCollisionTouch(Entity *thisEntity, Hitbox *thisHitbox, Entity *otherEntity, Hitbox *otherHitbox);
100
inline bool32 CheckObjectCollisionCircle(Entity *thisEntity, int32 thisRadius, Entity *otherEntity, int32 otherRadius)
101
{
102
int32 x = FROM_FIXED(thisEntity->position.x - otherEntity->position.x);
103
int32 y = FROM_FIXED(thisEntity->position.y - otherEntity->position.y);
104
int32 r = FROM_FIXED(thisRadius + otherRadius);
105
106
#if !RETRO_USE_ORIGINAL_CODE
107
if (showHitboxes) {
108
bool32 collided = x * x + y * y < r * r;
109
Hitbox thisHitbox;
110
Hitbox otherHitbox;
111
thisHitbox.left = thisRadius >> 16;
112
otherHitbox.left = otherRadius >> 16;
113
114
int32 thisHitboxID = AddDebugHitbox(H_TYPE_CIRCLE, FLIP_NONE, thisEntity, &thisHitbox);
115
int32 otherHitboxID = AddDebugHitbox(H_TYPE_CIRCLE, FLIP_NONE, otherEntity, &otherHitbox);
116
117
if (thisHitboxID >= 0 && collided)
118
debugHitboxList[thisHitboxID].collision |= 1 << (collided - 1);
119
if (otherHitboxID >= 0 && collided)
120
debugHitboxList[otherHitboxID].collision |= 1 << (collided - 1);
121
}
122
#endif
123
124
return x * x + y * y < r * r;
125
}
126
uint8 CheckObjectCollisionBox(Entity *thisEntity, Hitbox *thisHitbox, Entity *otherEntity, Hitbox *otherHitbox, bool32 setValues);
127
bool32 CheckObjectCollisionPlatform(Entity *thisEntity, Hitbox *thisHitbox, Entity *otherEntity, Hitbox *otherHitbox, bool32 setValues);
128
129
bool32 ObjectTileCollision(Entity *entity, uint16 cLayers, uint8 cMode, uint8 cPlane, int32 xOffset, int32 yOffset, bool32 setPos);
130
bool32 ObjectTileGrip(Entity *entity, uint16 cLayers, uint8 cMode, uint8 cPlane, int32 xOffset, int32 yOffset, int32 tolerance);
131
132
void ProcessObjectMovement(Entity *entity, Hitbox *outerBox, Hitbox *innerBox);
133
134
void ProcessPathGrip();
135
void ProcessAirCollision_Down();
136
#if RETRO_REV0U
137
void ProcessAirCollision_Up();
138
#endif
139
140
void SetPathGripSensors(CollisionSensor *cSensors);
141
142
void FindFloorPosition(CollisionSensor *sensor);
143
void FindLWallPosition(CollisionSensor *sensor);
144
void FindRoofPosition(CollisionSensor *sensor);
145
void FindRWallPosition(CollisionSensor *sensor);
146
147
void FloorCollision(CollisionSensor *sensor);
148
void LWallCollision(CollisionSensor *sensor);
149
void RoofCollision(CollisionSensor *sensor);
150
void RWallCollision(CollisionSensor *sensor);
151
152
#if RETRO_REV0U
153
#include "Legacy/CollisionLegacy.hpp"
154
#endif
155
156
} // namespace RSDK
157
158
#endif // !COLLISION_H
159
160