A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
ObjectFlamePoleV.hh
1#pragma once
2
3#include "game/field/StateManager.hh"
4#include "game/field/obj/ObjectCollidable.hh"
5
6namespace Field {
7
8class ObjectFlamePoleV final : public ObjectCollidable, public StateManager {
9public:
11 ~ObjectFlamePoleV() override;
12
13 void init() override;
14 void calc() override;
15
17 [[nodiscard]] u32 loadFlags() const override {
18 return 1;
19 }
20
22 [[nodiscard]] const char *getResources() const override {
23 return "FlamePole_v";
24 }
25
27 [[nodiscard]] const char *getKclName() const override {
28 return "FlamePoleEff";
29 }
30
31private:
33 void enterBeforeErupting() {
34 enableCollision();
35 }
36
38 void enterErupting() {
39 m_currOffsetY = 0.0f;
41 }
42
44 void enterErupted() {}
45
47 void enterLowering() {
48 m_loweringStartOffsetY = m_currOffsetY;
50 }
51
53 void enterDormant() {
54 disableCollision();
55 }
56
58 void calcBeforeErupting() {
59 if (static_cast<f32>(m_currentFrame) >= BEFORE_ERUPT_FRAMES) {
60 m_nextStateId = 1;
61 }
62 }
63
65 void calcErupting() {
66 if (static_cast<f32>(m_currentFrame) >= ERUPT_FRAMES) {
67 m_nextStateId = 2;
68 }
69
70 m_currOffsetY =
71 CalcParabolicDisplacement(m_initEruptingVel, m_eruptionDecel, m_currentFrame);
72 }
73
74 void calcErupted();
75 void calcLowering();
76
78 void calcDormant() {
79 if (m_currentFrame >= static_cast<u32>(m_dormantFrames)) {
80 m_nextStateId = 0;
81 }
82 }
83
86 static void CalcEruptionKinematics(f32 t, f32 maxHeight, f32 &initVel, f32 &accel) {
87 f32 doublePeak = 2.0f * maxHeight;
88 initVel = doublePeak / t;
89 accel = initVel * initVel / doublePeak;
90 }
91
92 const u32 m_initDelay;
93 const s32 m_cycleDuration;
94 const s32 m_dormantFrames;
95 const f32 m_scaleFactor;
96 const f32 m_initPosY;
99 f32 m_initEruptingVel;
101 const bool m_isBig;
102 f32 m_currOffsetY;
103 f32 m_loweringStartOffsetY;
104
105 static constexpr f32 ERUPT_FRAMES = 60.0f;
106 static constexpr f32 BEFORE_ERUPT_FRAMES = 50.0f;
107 static constexpr f32 FALL_FRAMES = 180.0f;
108
109 static constexpr std::array<StateManagerEntry, 5> STATE_ENTRIES = {{
110 {StateEntry<ObjectFlamePoleV, &ObjectFlamePoleV::enterBeforeErupting,
111 &ObjectFlamePoleV::calcBeforeErupting>(0)},
112 {StateEntry<ObjectFlamePoleV, &ObjectFlamePoleV::enterErupting,
113 &ObjectFlamePoleV::calcErupting>(1)},
114 {StateEntry<ObjectFlamePoleV, &ObjectFlamePoleV::enterErupted,
115 &ObjectFlamePoleV::calcErupted>(2)},
116 {StateEntry<ObjectFlamePoleV, &ObjectFlamePoleV::enterLowering,
117 &ObjectFlamePoleV::calcLowering>(3)},
118 {StateEntry<ObjectFlamePoleV, &ObjectFlamePoleV::enterDormant,
119 &ObjectFlamePoleV::calcDormant>(4)},
120 }};
121};
122
123} // namespace Field
static f32 CalcParabolicDisplacement(f32 initVel, f32 accel, u32 frame)
Solves the standard kinematic equation .
f32 m_eruptionDecel
Effectively the gravity coefficient when erupting.
static constexpr f32 ERUPT_FRAMES
Frames it takes to raise to max height.
static constexpr f32 FALL_FRAMES
Frames it takes to lower into the ground.
f32 m_maxOffsetY
Max height offset of the pole.
f32 m_fallSpeed
Rate at which the pole lowers.
static void CalcEruptionKinematics(f32 t, f32 maxHeight, f32 &initVel, f32 &accel)
Computes initVel and accel such that it takes t frames and the peak is maxHeight.
static constexpr f32 BEFORE_ERUPT_FRAMES
Delay before pole starts erupting.
Base class that represents different "states" for an object.
Pertains to collision.