persona-3-dual
A DS demake of Persona 3
Loading...
Searching...
No Matches
UIAnimation.hpp
Go to the documentation of this file.
1
6
7#pragma once
8
9#include <aegis/types.hpp>
10
20
25{
26 public:
27 virtual ~UIAnimation() = default;
28
29 UIAnimation(const UIAnimation&) = delete;
33
38 bool tick(ae::q20_12_t dt)
39 {
40 if (done || cancelled)
41 {
42 return true;
43 }
44 if (!paused)
45 {
46 done = onUpdate(dt);
47 if (done && applyRepeat())
48 {
49 done = false;
50 }
51 }
52 return done || cancelled;
53 }
54
55 virtual void reverse()
56 {
57 }
58
62 virtual void reset()
63 {
64 elapsed = ae::q20_12_t{0};
65 done = false;
66 cancelled = false;
67 paused = false;
68 }
69
70 void pause()
71 {
72 paused = true;
73 }
74
75 void resume()
76 {
77 paused = false;
78 }
79
80 void cancel()
81 {
82 cancelled = true;
83 }
84
85 bool isCancelled() const
86 {
87 return cancelled;
88 }
89
90 bool isPaused() const
91 {
92 return paused;
93 }
94
95 bool isDone() const
96 {
97 return done;
98 }
99
100 void setRepeat(UIRepeatMode mode, int count = -1)
101 {
102 repeatMode = mode;
103 remainingRepeats = count;
104 }
105
106 protected:
107 UIAnimation() = default;
108
113 virtual bool onUpdate(ae::q20_12_t dt) = 0;
114
120 {
122 {
123 return false;
124 }
125
126 if (remainingRepeats == 0)
127 {
128 return false;
129 }
130 if (remainingRepeats > 0)
131 {
133 }
134
136 {
137 reverse();
138 elapsed = ae::q20_12_t{0};
139 cancelled = false;
140 done = false;
141 return true;
142 }
143
144 // Loop
145 reset();
146 return true;
147 }
148
149 bool paused = false;
150 bool cancelled = false;
151 bool done = false;
152 ae::q20_12_t elapsed{0};
155};
UIRepeatMode
How an animation behaves after reaching its end.
@ Loop
Restart from the beginning.
@ PingPong
Reverse direction each cycle.
@ Once
Play once, then complete.
bool isCancelled() const
ae::q20_12_t elapsed
bool isPaused() const
UIAnimation()=default
int remainingRepeats
-1 = infinite when mode is not Once.
UIAnimation(UIAnimation &&)=delete
bool tick(ae::q20_12_t dt)
Advances the animation by dt seconds (Q20.12).
UIAnimation & operator=(UIAnimation &&)=delete
virtual ~UIAnimation()=default
virtual void reset()
Resets runtime state so the animation can play again (used by Loop).
void setRepeat(UIRepeatMode mode, int count=-1)
UIRepeatMode repeatMode
bool isDone() const
bool applyRepeat()
Applies repeat policy after a completed cycle.
UIAnimation(const UIAnimation &)=delete
virtual void reverse()
UIAnimation & operator=(const UIAnimation &)=delete
virtual bool onUpdate(ae::q20_12_t dt)=0
Per-frame update.