NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
fanm.cpp
1#include <game/mLib/m_3d.hpp>
2
8
10
12 float frame = mpObj->GetFrame();
13 float updateRate = mpObj->GetUpdateRate();
14
15 bool updateRateNegative = updateRate < 0.0f;
16 if (updateRateNegative) {
17 updateRate *= -1.0f;
18 }
19
20 mCurrFrame = frame;
21
22 if (updateRateNegative || (mPlayMode & MASK_FORWARD) != 0) {
23 // Reverse animation
24 if (frame >= updateRate) {
25 frame -= updateRate;
26 } else {
27 if ((mPlayMode & MASK_LOOP) == 0) {
28 frame += mFrameMax - updateRate;
29 } else {
30 frame = mFrameStart;
31 }
32 }
33 } else {
34 // Forward animation
35 frame += updateRate;
36 if ((mPlayMode & MASK_LOOP) == 0) {
37 if (frame >= mFrameMax) {
38 frame -= mFrameMax;
39 }
40 } else {
41 float endFrame = mFrameMax - 1.0f;
42 if (frame >= endFrame) {
43 frame = endFrame;
44 }
45 }
46 }
47
48 mpObj->SetFrame(frame);
49}
50
51void m3d::fanm_c::set(float duration, m3d::playMode_e playMode, float updateRate, float startFrame) {
52 float frame = startFrame;
53 if (startFrame < 0.0f) {
54 if (playMode == FORWARD_ONCE) {
55 frame = 0.0f;
56 } else {
57 frame = duration - 1.0f;
58 }
59 }
60
61 mFrameMax = duration;
62 mFrameStart = 0.0f;
63
64 mpObj->SetFrame(frame);
65 mpObj->SetUpdateRate(updateRate);
66
67 mPlayMode = playMode;
68 mCurrFrame = frame;
69}
70
71void m3d::fanm_c::setFrame(float f) {
72 banm_c::setFrameOnly(f);
73 mCurrFrame = f;
74}
75
76bool m3d::fanm_c::isStop() const {
77 float frame = mpObj->GetFrame();
78 float updateRate = mpObj->GetUpdateRate();
79
80 // Only the "once" modes should ever be able to stop
81 if (updateRate < 0.0f || mPlayMode == REVERSE_ONCE) {
82 return frame <= mFrameStart;
83 } else if (mPlayMode == FORWARD_ONCE) {
84 return frame >= mFrameMax - 1.0f;
85 }
86
87 return false;
88}
89
90bool m3d::fanm_c::checkFrame(float f) const {
91 float objFrame = mpObj->GetFrame();
92 if (mCurrFrame == objFrame) {
93 return objFrame == f;
94 }
95
96 float updateRate = mpObj->GetUpdateRate();
97
98 if (updateRate < 0.0f || (mPlayMode & MASK_FORWARD) != 0) {
99 // Reverse animation
100 if (mCurrFrame > objFrame) {
101 if (mCurrFrame > f && objFrame <= f) {
102 return true;
103 }
104 } else {
105 // mCurrFrame < objFrame
106 if (f < mCurrFrame || f >= objFrame) {
107 return true;
108 }
109 }
110 } else {
111 // Forward animation
112 if (mCurrFrame < objFrame) {
113 if (mCurrFrame < f && objFrame >= f) {
114 return true;
115 }
116 } else {
117 // mCurrFrame > objFrame
118 if (f > mCurrFrame || f <= objFrame) {
119 return true;
120 }
121 }
122 }
123
124 return false;
125}
virtual void play()
Updates the animation. Call this function every frame to update the animation.
Definition fanm.cpp:11
float mCurrFrame
The frame the animation is currently on.
Definition fanm.hpp:39
bool isStop() const
Checks whether the animation is stopped.
Definition fanm.cpp:76
void setFrame(float frame)
Jumps to the specified frame in the animation.
Definition fanm.cpp:71
virtual ~fanm_c()
Destroys the animation object.
Definition fanm.cpp:9
fanm_c()
Constructs an animation object.
Definition fanm.cpp:3
bool checkFrame(float frame) const
Checks whether the animation has reached the specified frame.
Definition fanm.cpp:90
float mFrameMax
The last frame number of the animation.
Definition fanm.hpp:37
u8 mPlayMode
The play mode of the animation.
Definition fanm.hpp:40
float mFrameStart
The first frame number of the animation.
Definition fanm.hpp:38
void set(float duration, m3d::playMode_e playMode, float updateRate, float startFrame)
Starts the animation with the given parameters.
Definition fanm.cpp:51
playMode_e
Definition banm.hpp:7
@ MASK_FORWARD
Mask for forward play mode.
Definition banm.hpp:15
@ FORWARD_ONCE
Play the animation forward once.
Definition banm.hpp:9
@ FORWARD_LOOP
Play the animation forward in a loop.
Definition banm.hpp:8
@ REVERSE_ONCE
Play the animation in reverse once.
Definition banm.hpp:11
@ MASK_LOOP
Mask for loop play mode.
Definition banm.hpp:14