A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
KartAction.hh
1#pragma once
2
3#include "game/kart/KartObjectProxy.hh"
4
5namespace Kart {
6
7enum class Action {
8 None = -1,
9 UNK_0 = 0,
10 UNK_1 = 1,
11 UNK_2 = 2,
12 UNK_3 = 3,
13 UNK_4 = 4,
14 UNK_5 = 5,
15 UNK_6 = 6,
16 UNK_7 = 7,
17 UNK_8 = 8,
18 UNK_9 = 9,
19 UNK_12 = 12,
20 UNK_14 = 14,
21 UNK_16 = 16,
22 Max = 18,
23};
24
26public:
27 enum class eFlags {
28 Landing = 0,
29 LargeFlip = 2,
30 Rotating = 3,
31 LandingFromFlip = 5,
32 };
34
35 KartAction();
37
38 void init();
39 void calc();
40 void calcVehicleSpeed();
41 bool start(Action action);
42 void startRotation(size_t idx);
43
44 void setHitDepth(const EGG::Vector3f &hitDepth) {
45 m_hitDepth = hitDepth;
46 }
47
48 void setTranslation(const EGG::Vector3f &v) {
49 m_translation = v;
50 }
51
52 [[nodiscard]] const Flags &flags() const {
53 return m_flags;
54 }
55
56private:
58 struct ActionParams {
59 f32 startSpeedMult;
60 f32 calcSpeedMult;
61 s16 priority;
62 };
63
65 f32 initialAngleIncrement;
66 f32 minAngleIncrement;
67 f32 minMultiplier;
68 f32 initialMultiplierDecrement;
69 f32 slowdownThreshold;
70 f32 finalAngle;
71 };
72
73 // The player index sent into StartActionFunc is assumed to be cosmetic
74 typedef void (KartAction::*StartActionFunc)();
75 typedef bool (KartAction::*CalcActionFunc)();
76 typedef void (KartAction::*EndActionFunc)(bool arg);
77
78 void calcSideFromHitDepth();
79 void calcSideFromHitDepthAndTranslation();
80
81 void end();
82
83 bool calcCurrentAction();
84 void calcEndAction(bool endArg);
85 bool calcRotation();
86 void calcUp();
87 void calcLanding();
88 void startLaunch(f32 extVelScalar, f32 extVelKart, f32 extVelBike, f32 numRotations,
89 u32 param6);
90 void activateCrush(u16 timer);
91
92 void applyStartSpeed();
93 void setRotation(size_t idx);
94
95 /* ================================ *
96 * START FUNCTIONS
97 * ================================ */
98
99 void startStub();
100 void startAction1();
101 void startAction2();
102 void startAction3();
103 void startAction5();
104 void startLargeFlipAction();
105 void startAction9();
106 void startLongPressAction();
107 void startShortPressAction();
108
109 /* ================================ *
110 * CALC FUNCTIONS
111 * ================================ */
112
113 bool calcStub();
114 bool calcAction1();
115 bool calcLaunchAction();
116 bool calcLargeFlipAction();
117 bool calcPressAction();
118
119 /* ================================ *
120 * END FUNCTIONS
121 * ================================ */
122
123 void endStub(bool arg);
124 void endAction1(bool arg);
125 void endLaunchAction(bool arg);
126
127 EGG::Vector3f m_side;
128 Action m_currentAction;
129 f32 m_rotationDirection;
130 f32 m_targetRot;
131 EGG::Vector3f m_hitDepth;
132 EGG::Vector3f m_rotAxis;
133 EGG::Vector3f m_translation;
134
135 f32 m_velPitch;
136 f32 m_pitch;
137 f32 m_deltaPitch;
138 f32 m_flipPhase;
139
140 StartActionFunc m_onStart;
141 CalcActionFunc m_onCalc;
142 EndActionFunc m_onEnd;
143
144 EGG::Quatf m_rotation;
145 const ActionParams *m_actionParams;
146 u32 m_frame;
147 u32 m_crushTimer;
148 Flags m_flags;
149 f32 m_currentAngle;
150 f32 m_angleIncrement;
151 f32 m_multiplier;
152 f32 m_multiplierDecrement;
153 f32 m_finalAngle;
154 const RotationParams *m_rotationParams;
155 EGG::Vector3f m_up;
156 u16 m_framesFlipping;
157 s16 m_priority;
158
159 static constexpr size_t MAX_ACTION = static_cast<size_t>(Action::Max);
160
161 static const std::array<ActionParams, MAX_ACTION> s_actionParams;
162 static const std::array<RotationParams, 5> s_rotationParams;
163
164 static const std::array<StartActionFunc, MAX_ACTION> s_onStart;
165 static const std::array<CalcActionFunc, MAX_ACTION> s_onCalc;
166 static const std::array<EndActionFunc, MAX_ACTION> s_onEnd;
167};
168
169} // namespace Kart
void startRotation(size_t idx)
Initializes rotation parameters.
bool calcCurrentAction()
Executes a frame of the current action.
bool start(Action action)
Starts an action.
Definition KartAction.cc:49
Base class for most kart-related objects.
Pertains to kart-related functionality.
A quaternion, used to represent 3D rotation.
Definition Quat.hh:12
Wrapper around an integral type with an enum corresponding to its bits.
Definition BitFlag.hh:21
A 3D float vector.
Definition Vector.hh:88
Parameters specific to an action ID.
Definition KartAction.hh:58