NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
d_util_frame_counter.hpp
1#pragma once
2
3#include <types.h>
4
5namespace Util {
6
7/// @brief A bidirectional frame counter.
8/// @ingroup bases
10public:
11 /// @brief The possible behaviors after the frame counter is finished.
12 enum Type_e {
13 TYPE_ONETIME, ///< Locks the frame to the target frame.
14 TYPE_LOOP, ///< Continues counting in the same direction.
15 TYPE_OSCILLATING, ///< Continues counting in the opposite direction.
16 };
17
18 FrameCounter_c(); ///< Constructs a new frame counter.
19 ~FrameCounter_c(); ///< Destroys the frame counter.
20
21 /// @brief Initializes the frame interval.
22 /// @details Sets the current frame to the start frame.
23 /// @param startFrame The start frame.
24 /// @param endFrame The end frame.
25 void init(f32 startFrame, f32 endFrame);
26
27 /// @brief Fully initializes into a valid state.
28 /// @details Sets the current frame to the start frame.
29 /// @param updateRate The update rate.
30 /// @param type The play type.
31 /// @param startFrame The start frame.
32 /// @param endFrame The end frame.
33 void play(f32 updateRate, Type_e type, f32 startFrame, f32 endFrame);
34
35 /// @brief Partially initializes into a valid state without initializing the frame interval.
36 /// @details Sets the current frame to the start frame.
37 /// @param updateRate The update rate.
38 /// @param type The play type.
39 void play(f32 updateRate, Type_e type);
40
41 /// @brief Updates the frame counter.
42 /// @details Sets finished to @p true if the counter finishes.
43 void calc();
44
45 /// @brief Gets the current frame.
46 /// @return The current frame.
47 f32 getFrame() const { return m_frame; }
48
49 /// @brief Sets the current frame.
50 /// @param frame The new current frame.
51 void setFrame(f32 frame) { m_frame = frame; }
52
53 /// @brief Gets the update rate.
54 /// @return The update rate.
55 f32 getUpdateRate() const { return m_updateRate; }
56
57 /// @brief Sets the update rate.
58 /// @param updateRate The new update rate.
59 void setUpdateRate(f32 updateRate) { m_updateRate = updateRate; }
60
61 /// @brief Gets whether the counter is finished.
62 /// @return @p true the counter is finished, otherwise @p false.
63 bool getFinished() const { return m_finished; }
64
65private:
66 /// @brief The current frame in the interval [start, end].
67 /// @details Initialized to the start frame by #init and/or #play.
68 /// Updated based on the update rate and type behavior in #calc.
69 /// Can optionally be set manually with #setFrame.
71
72 /// @brief Lower bound of the frame interval.
73 /// @details Initialized by #init and/or #play.
75
76 /// @brief Upper bound of the frame interval.
77 /// @details Initialized by #init and/or #play.
79
80 /// @brief Controls the direction and rate at which the frame updates.
81 /// @details If the update rate is positive, the target frame will be the end frame.
82 /// If the update rate is negative, the target frame will be the start frame.
83 /// Initialized by #play. Can optionally be set manually with #setUpdateRate.
85
86 /// @brief Whether or not the counter is finished.
87 /// @details Behavior is contingent on #m_type.
88 /// - #TYPE_ONETIME: the counter will be finished until there is a modified update rate or frame.
89 /// - #TYPE_LOOP and #TYPE_OSCILLATING: the counter will be finished only when the change occurs.
91
92 /// @brief Controls what happens to the frame when it reaches the target frame.
94};
95
96} // namespace Util
f32 m_startFrame
Lower bound of the frame interval.
void calc()
Updates the frame counter.
void setUpdateRate(f32 updateRate)
Sets the update rate.
FrameCounter_c()
Constructs a new frame counter.
void play(f32 updateRate, Type_e type, f32 startFrame, f32 endFrame)
Fully initializes into a valid state.
~FrameCounter_c()
Destroys the frame counter.
bool getFinished() const
Gets whether the counter is finished.
void init(f32 startFrame, f32 endFrame)
Initializes the frame interval.
f32 m_frame
The current frame in the interval [start, end].
f32 getFrame() const
Gets the current frame.
bool m_finished
Whether or not the counter is finished.
Type_e m_type
Controls what happens to the frame when it reaches the target frame.
f32 m_updateRate
Controls the direction and rate at which the frame updates.
f32 getUpdateRate() const
Gets the update rate.
f32 m_endFrame
Upper bound of the frame interval.
Type_e
The possible behaviors after the frame counter is finished.
@ TYPE_ONETIME
Locks the frame to the target frame.
@ TYPE_LOOP
Continues counting in the same direction.
@ TYPE_OSCILLATING
Continues counting in the opposite direction.
void setFrame(f32 frame)
Sets the current frame.