A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
Rail.hh
1#pragma once
2
3#include "game/system/map/MapdataPointInfo.hh"
4
5namespace Kinoko::Field {
6
8 f32 m_length;
9 f32 m_lengthInv;
10 EGG::Vector3f m_dir;
11};
12
14 EGG::Vector3f m_p0;
15 EGG::Vector3f m_p1;
16 EGG::Vector3f m_p2;
17 EGG::Vector3f m_p3;
18 f32 m_length;
19 f32 m_lengthInv;
20};
21
22class Rail {
23public:
25 virtual ~Rail();
26
27 virtual f32 getPathLength() const = 0;
28 virtual std::span<const RailLineTransition> getLinearTransitions() const = 0;
29 virtual std::span<const RailSplineTransition> getSplineTransitions() const = 0;
30 virtual s32 getEstimatorSampleCount() const = 0;
31 virtual f32 getEstimatorStep() const = 0;
32 virtual std::span<const f32> getPathPercentages() const = 0;
33
34 void addPoint(f32 scale, const EGG::Vector3f &point);
35 void checkSphereFull();
36
37 [[nodiscard]] u16 pointCount() const {
38 return m_pointCount;
39 }
40
41 [[nodiscard]] bool isOscillating() const {
42 return m_isOscillating;
43 }
44
45 [[nodiscard]] std::span<const System::MapdataPointInfo::Point> points() const {
46 return m_points.view();
47 }
48
50 [[nodiscard]] const EGG::Vector3f &pointPos(u16 idx) const {
51 ASSERT(idx < m_pointCount);
52 return m_points[idx].pos;
53 }
54
55 [[nodiscard]] const EGG::Vector3f &floorNrm(u16 idx) const {
56 ASSERT(!m_floorNrms.empty() && idx < m_floorNrms.size());
57 return m_floorNrms[idx];
58 }
59
60protected:
61 virtual void onPointsChanged() = 0;
62 virtual void onPointAdded() = 0;
63
64 u16 m_pointCount;
65 bool m_isOscillating;
66 owning_span<System::MapdataPointInfo::Point> m_points;
67 f32 m_someScale;
68
69private:
70 u16 m_idx;
71 u16 m_pointCapacity;
72 bool m_hasCheckedCol;
73 owning_span<EGG::Vector3f> m_floorNrms;
74};
75
76class RailLine : public Rail {
77public:
79 ~RailLine() override;
80
82 [[nodiscard]] s32 getEstimatorSampleCount() const override {
83 return 0;
84 }
85
87 [[nodiscard]] f32 getEstimatorStep() const override {
88 return 0.0f;
89 }
90
93 [[nodiscard]] std::span<const f32> getPathPercentages() const override {
94 static owning_span<f32> EMPTY_PERCENTAGES;
95 return EMPTY_PERCENTAGES.view();
96 }
97
98private:
100 [[nodiscard]] f32 getPathLength() const override {
101 return m_pathLength;
102 }
103
105 [[nodiscard]] std::span<const RailLineTransition> getLinearTransitions() const override {
106 return m_transitions.view();
107 }
108
111 [[nodiscard]] std::span<const RailSplineTransition> getSplineTransitions() const override {
112 static owning_span<RailSplineTransition> EMPTY_TRANSITIONS;
113 return EMPTY_TRANSITIONS.view();
114 }
115
116 void onPointsChanged() override {}
117 void onPointAdded() override {}
118
119 u16 m_dirCount;
120 owning_span<RailLineTransition> m_transitions;
121 f32 m_pathLength;
122};
123
124class RailSpline : public Rail {
125public:
127 ~RailSpline() override;
128
130 [[nodiscard]] s32 getEstimatorSampleCount() const override {
131 return m_estimatorSampleCount;
132 }
133
135 [[nodiscard]] f32 getEstimatorStep() const override {
136 return m_estimatorStep;
137 }
138
140 [[nodiscard]] std::span<const f32> getPathPercentages() const override {
141 return m_pathPercentages.view();
142 }
143
144private:
146 [[nodiscard]] f32 getPathLength() const override {
147 return m_pathLength;
148 }
149
151 [[nodiscard]] std::span<const RailLineTransition> getLinearTransitions() const override {
152 static owning_span<RailLineTransition> EMPTY_TRANSITIONS;
153 return EMPTY_TRANSITIONS.view();
154 }
155
157 [[nodiscard]] std::span<const RailSplineTransition> getSplineTransitions() const override {
158 return m_transitions.view();
159 }
160
161 void onPointsChanged() override;
162 void onPointAdded() override;
163
164 void invalidateTransitions(bool lastOnly);
165 void calcCubicBezierControlPoints(const EGG::Vector3f &p0, const EGG::Vector3f &p1,
166 const EGG::Vector3f &p2, const EGG::Vector3f &p3, s32 count,
167 RailSplineTransition &transition);
168 [[nodiscard]] f32 estimateLength(const RailSplineTransition &transition, s32 count);
169 [[nodiscard]] EGG::Vector3f calcCubicBezierP1(const EGG::Vector3f &p0, const EGG::Vector3f &p1,
170 const EGG::Vector3f &p2) const;
171 [[nodiscard]] EGG::Vector3f calcCubicBezierP2(const EGG::Vector3f &p0, const EGG::Vector3f &p1,
172 const EGG::Vector3f &p2) const;
173 [[nodiscard]] EGG::Vector3f cubicBezier(f32 t, const RailSplineTransition &transition) const;
174
175 u16 m_transitionCount;
177 u32 m_estimatorSampleCount;
178 f32 m_estimatorStep;
179 owning_span<f32> m_pathPercentages;
180 s32 m_segmentCount;
181 f32 m_pathLength;
182 bool m_doNotAllocatePathPercentages;
183};
184
185} // namespace Kinoko::Field
std::span< const f32 > getPathPercentages() const override
In the base game we return a nullptr. To mimic this, return an empty vector.
Definition Rail.hh:93
std::span< const RailSplineTransition > getSplineTransitions() const override
In the base game we return a nullptr. To mimic this, return an empty vector.
Definition Rail.hh:111
A contiguous storage container that manages the lifecycle of a buffer of a given size.
Definition Types.hh:29
std::span< const T > view() const
Returns a read-only view of the entire buffer.
Definition Types.hh:157
Pertains to collision.
A 3D float vector.
Definition Vector.hh:107