A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
CollisionDirector.hh
1#pragma once
2
3#include "game/field/CourseColMgr.hh"
4
5#include <egg/math/Vector.hh>
6
7#define COLLISION_ARR_LENGTH 0x40
8
10namespace Field {
11
16public:
18 KCLTypeMask typeMask;
19 u16 attribute;
20 f32 dist;
21 };
22
23 void checkCourseColNarrScLocal(f32 radius, const EGG::Vector3f &pos, KCLTypeMask mask,
24 u32 timeOffset);
25
26 [[nodiscard]] bool checkSphereFull(f32 radius, const EGG::Vector3f &v0, const EGG::Vector3f &v1,
27 KCLTypeMask flags, CollisionInfo *pInfo, KCLTypeMask *pFlagsOut, u32 timeOffset);
28 [[nodiscard]] bool checkSphereFullPush(f32 radius, const EGG::Vector3f &v0,
29 const EGG::Vector3f &v1, KCLTypeMask flags, CollisionInfo *pInfo,
30 KCLTypeMask *pFlagsOut, u32 timeOffset);
31
32 [[nodiscard]] bool checkSphereCachedPartial(f32 radius, const EGG::Vector3f &pos,
33 const EGG::Vector3f &prevPos, KCLTypeMask typeMask, CollisionInfoPartial *info,
34 KCLTypeMask *typeMaskOut, u32 timeOffset);
35 [[nodiscard]] bool checkSphereCachedPartialPush(f32 radius, const EGG::Vector3f &pos,
36 const EGG::Vector3f &prevPos, KCLTypeMask typeMask, CollisionInfoPartial *info,
37 KCLTypeMask *typeMaskOut, u32 timeOffset);
38 [[nodiscard]] bool checkSphereCachedFullPush(f32 radius, const EGG::Vector3f &pos,
39 const EGG::Vector3f &prevPos, KCLTypeMask typeMask, CollisionInfo *info,
40 KCLTypeMask *typeMaskOut, u32 timeOffset);
41
42 void resetCollisionEntries(KCLTypeMask *ptr);
43 void pushCollisionEntry(f32 dist, KCLTypeMask *typeMask, KCLTypeMask kclTypeBit, u16 attribute);
44
49 ASSERT(m_collisionEntryCount > 0);
50 u16 &entryAttr = m_entries[m_collisionEntryCount - 1].attribute;
51 entryAttr = (entryAttr & 0xff1f) | (attribute << 5);
52 }
53
57 void setCurrentCollisionTrickable(bool trickable) {
58 ASSERT(m_collisionEntryCount > 0);
59 u16 &entryAttr = m_entries[m_collisionEntryCount - 1].attribute;
60 entryAttr &= 0xdfff;
61
62 if (trickable) {
63 entryAttr |= (1 << 0xd);
64 }
65 }
66
67 bool findClosestCollisionEntry(KCLTypeMask *typeMask, KCLTypeMask type);
68
70 [[nodiscard]] const CollisionEntry *closestCollisionEntry() const {
71 return m_closestCollisionEntry;
72 }
74
75 static CollisionDirector *CreateInstance();
76 static void DestroyInstance();
77
78 [[nodiscard]] static CollisionDirector *Instance() {
79 return s_instance;
80 }
81
82private:
83 CollisionDirector();
84 ~CollisionDirector() override;
85
86 const CollisionEntry *m_closestCollisionEntry;
87 std::array<CollisionEntry, COLLISION_ARR_LENGTH> m_entries;
88 size_t m_collisionEntryCount;
89
90 static CollisionDirector *s_instance;
91};
92
93} // namespace Field
An interface for ensuring certain structures and classes are destroyed with the heap.
Definition Disposer.hh:11
Manages the caching of colliding KCL triangles and exposes queries for collision checks.
void setCurrentCollisionVariant(u16 attribute)
void setCurrentCollisionTrickable(bool trickable)
void pushCollisionEntry(f32 dist, KCLTypeMask *typeMask, KCLTypeMask kclTypeBit, u16 attribute)
Called when we find a piece of collision we are touching and want to save it temporarily.
bool findClosestCollisionEntry(KCLTypeMask *typeMask, KCLTypeMask type)
Finds the closest KCL triangle out of the list of tris we are colliding with.
Pertains to collision.
A 3D float vector.
Definition Vector.hh:83