NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
d_rail.hpp
1#pragma once
2#include <game/bases/d_cd.hpp>
3
4/**
5 * @brief Manages movement along rails.
6 */
7class dRail_c {
8public:
9 virtual ~dRail_c() {} ///< Destroys the rail handler.
10 virtual void calcSpeed(); ///< Calculates and applies the new speed based on the current and next node.
11
12 /**
13 * @brief Initializes the rail with the specified ID and parameters.
14 * @param id The ID of the rail to use.
15 * @param pos Pointer to the position vector of the object on the rail.
16 * @param speed Pointer to the speed vector of the object on the rail.
17 * @param speedF Pointer to the forward speed of the object on the rail.
18 * @param startIndex The starting node index on the rail.
19 * @param reverse Whether the object should travel the rail in reverse.
20 * @return Whether the rail was successfully initialized.
21 */
22 bool set(u8 id, mVec3_c *pos, mVec3_c *speed, float *speedF, u16 startIndex, u8 reverse);
23
24 /// @brief Advances the node index to the next target point.
25 /// @return Whether the end of the rail has been reached.
26 bool calcNextPoint();
27 void calcTargetPos(); ///< Calculates the target position based on the next node.
28 bool execute(); ///< Executes the rail movement logic. Returns whether a target node has been reached.
29 bool checkArrive(); ///< Checks whether the rail has arrived at the next target node.
30
31 static sRailInfoData *getRailInfoP(u8 id); ///< Gets the rail data for the specified ID.
32
33 /// @unofficial
35 RAIL_FLAG_LOOP = BIT_FLAG(1),
36 RAIL_FLAG_DELAYING = BIT_FLAG(2),
37 RAIL_FLAG_DISABLED = BIT_FLAG(3)
38 };
39
40 /// @unofficial
42 NODE_FLAG_1 = BIT_FLAG(0)
43 };
44
45 sRailNodeData *mpNodes; ///< The array of rail nodes.
46 mVec2_c mTargetPos; ///< The position of the next node.
47 mVec3_c *mpPos; ///< Reference to the position of the object on the rail.
48 mVec3_c *mpSpeed; ///< Reference to the speed vector of the object on the rail.
49 float *mpSpeedF; ///< Reference to the forward speed of the object on the rail.
50 u16 mCount; ///< The number of nodes in the rail.
51 short mIdxCurr; ///< The current node index.
52 short mIdxNext; ///< The next node index.
53 u16 mDelayTimer; ///< By how many frames to delay before starting movement from a node.
54 u16 mAngle; ///< The current angle of movement.
55 u16 mFlags; ///< The rail flags.
56 u16 mNodeFlags; ///< The current node flags.
57 u8 mReverse; ///< Whether to go through the rail in reverse.
58 int mAngleCalcTimer; ///< Cooldown timer for angle recalculation.
59 bool mBounce; ///< Whether to reverse direction at the ends of the rail (only applicable if not looping).
60};
Manages movement along rails.
Definition d_rail.hpp:7
void calcTargetPos()
Calculates the target position based on the next node.
Definition d_rail.cpp:85
NODE_FLAGS_e
Definition d_rail.hpp:41
bool set(u8 id, mVec3_c *pos, mVec3_c *speed, float *speedF, u16 startIndex, u8 reverse)
Initializes the rail with the specified ID and parameters.
Definition d_rail.cpp:16
u16 mFlags
The rail flags.
Definition d_rail.hpp:55
float * mpSpeedF
Reference to the forward speed of the object on the rail.
Definition d_rail.hpp:49
mVec3_c * mpSpeed
Reference to the speed vector of the object on the rail.
Definition d_rail.hpp:48
bool calcNextPoint()
Advances the node index to the next target point.
Definition d_rail.cpp:53
mVec3_c * mpPos
Reference to the position of the object on the rail.
Definition d_rail.hpp:47
short mIdxCurr
The current node index.
Definition d_rail.hpp:51
virtual ~dRail_c()
Destroys the rail handler.
Definition d_rail.hpp:9
short mIdxNext
The next node index.
Definition d_rail.hpp:52
u16 mAngle
The current angle of movement.
Definition d_rail.hpp:54
bool mBounce
Whether to reverse direction at the ends of the rail (only applicable if not looping).
Definition d_rail.hpp:59
virtual void calcSpeed()
Calculates and applies the new speed based on the current and next node.
Definition d_rail.cpp:95
bool execute()
Executes the rail movement logic. Returns whether a target node has been reached.
Definition d_rail.cpp:133
u16 mCount
The number of nodes in the rail.
Definition d_rail.hpp:50
RAIL_FLAGS_e
Definition d_rail.hpp:34
mVec2_c mTargetPos
The position of the next node.
Definition d_rail.hpp:46
u8 mReverse
Whether to go through the rail in reverse.
Definition d_rail.hpp:57
sRailNodeData * mpNodes
The array of rail nodes.
Definition d_rail.hpp:45
u16 mNodeFlags
The current node flags.
Definition d_rail.hpp:56
static sRailInfoData * getRailInfoP(u8 id)
Gets the rail data for the specified ID.
Definition d_rail.cpp:4
int mAngleCalcTimer
Cooldown timer for angle recalculation.
Definition d_rail.hpp:58
u16 mDelayTimer
By how many frames to delay before starting movement from a node.
Definition d_rail.hpp:53
bool checkArrive()
Checks whether the rail has arrived at the next target node.
Definition d_rail.cpp:170
A two-dimensional floating point vector.
Definition m_vec.hpp:9
A three-dimensional floating point vector.
Definition m_vec.hpp:100