A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
MapdataArea.hh
1#pragma once
2
3#include "game/system/map/MapdataAccessorBase.hh"
4
5#include <egg/math/Vector.hh>
6
7namespace System {
8
9class MapdataPointInfo;
10
12public:
13 struct SData {
14 s8 shape;
15 s8 type;
16 u8 _02[0x03 - 0x02];
17 u8 priority;
18 EGG::Vector3f position;
19 EGG::Vector3f rotation;
20 EGG::Vector3f scale;
21 s16 parameters[2];
22 // Pre Revision 2200: End of structure
23 s8 railId;
24 u8 _2d[0x30 - 0x2d];
25 };
26
27 enum class Shape {
28 Box = 0,
29 Cylinder = 1,
30 };
31
32 enum class Type {
33 MovingRoad = 3,
34 };
35
36 MapdataAreaBase(const SData *data, s16 index);
37 ~MapdataAreaBase() = default;
38 void read(EGG::Stream &stream);
39
40 virtual bool testImpl(const EGG::Vector3f &pos) const = 0;
41
43 [[nodiscard]] bool test(const EGG::Vector3f &pos) const {
44 return (m_position - pos).squaredLength() > m_sqBoundingSphereRadius ? false :
45 testImpl(pos);
46 }
47
48 [[nodiscard]] MapdataPointInfo *getPointInfo() const;
49
50 [[nodiscard]] Type type() const {
51 return m_type;
52 }
53
54 [[nodiscard]] u8 priority() const {
55 return m_priority;
56 }
57
58 [[nodiscard]] s16 param(size_t i) const {
59 ASSERT(i < m_params.size());
60 return m_params[i];
61 }
62
63 [[nodiscard]] s16 index() const {
64 return m_index;
65 }
66
67protected:
68 const SData *m_rawData;
69 Type m_type;
70 u8 m_priority;
71 EGG::Vector3f m_position;
72 EGG::Vector3f m_rotation;
73 EGG::Vector3f m_scale;
74 std::array<s16, 2> m_params;
75 s8 m_railId;
76
77 EGG::Vector3f m_right;
78 EGG::Vector3f m_up;
79 EGG::Vector3f m_forward;
80 EGG::Vector3f m_dimensions;
81 f32 m_ellipseRadiusSq;
82 f32 m_ellipseAspectRatio;
84 s16 m_index;
85};
86
88public:
89 MapdataAreaBox(const SData *data, s16 index);
90 ~MapdataAreaBox() = default;
91
92 [[nodiscard]] bool testImpl(const EGG::Vector3f &pos) const override;
93};
94
96public:
97 MapdataAreaCylinder(const SData *data, s16 index);
98 ~MapdataAreaCylinder() = default;
99
100 [[nodiscard]] bool testImpl(const EGG::Vector3f &pos) const override;
101};
102
103class MapdataAreaAccessor : public MapdataAccessorBase<MapdataAreaBase, MapdataAreaBase::SData> {
104public:
106 ~MapdataAreaAccessor() override;
107
108 void init(const MapdataAreaBase::SData *start, u16 count);
109 void sort();
110
111 [[nodiscard]] MapdataAreaBase *getSorted(u16 i) const {
112 ASSERT(m_sortedEntries.data());
113 return i < m_entryCount ? m_sortedEntries[i] : nullptr;
114 }
115
116private:
117 std::span<MapdataAreaBase *> m_sortedEntries;
118};
119
120} // namespace System
A stream of data, abstracted to allow for continuous seeking.
Definition Stream.hh:10
f32 m_sqBoundingSphereRadius
Used to phase out intersection tests early.
High-level handling for generic system operations, such as input reading, race configuration,...
Definition CourseMap.cc:5
A 3D float vector.
Definition Vector.hh:88