Brunot
Loading...
Searching...
No Matches
Action.h
Go to the documentation of this file.
1
12// ____ __ __ __
13// /\__ _\/\ \ /\ \/\ \
14// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
15// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
16// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
17// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
18// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
19
20#pragma once
21
22#include "Utility/Math/Bezier.h"
23
24class Entity;
25
131{
132public:
133 Action() = default;
134 Action(const Action&) = default;
135 auto operator=(const Action&) -> Action& = default;
136 virtual ~Action() = default;
137 Action(Action&& other) noexcept = default;
138 auto operator=(Action&& other) noexcept -> Action& = default;
139 auto operator==(const Action& other) const -> bool;
140
141 Action(std::string name);
142 Action(std::string name, float duration);
143 Action(std::string name, float duration, const th::Bezier& bezierCurve, float initialDelay, float endingDelay);
144
149 auto update(float dt) -> void;
150
154 virtual auto init() -> void;
155
159 virtual auto execute() -> void;
160
164 virtual auto end() -> void;
165
169 virtual auto ActionShowMenu() -> void;
170
174 virtual auto render() const -> void;
175
176 auto shouldRemove() const -> bool;
177
178 auto getOwner() const -> Entity*;
179 auto setOwner(Entity* newObject) -> void;
180
184 auto getHasInitialized() const -> bool;
185
189
190 auto getHasExecuted() const -> bool;
194 auto getHasEnded() const -> bool;
195
196 auto isPaused() const -> bool;
197 auto setPaused(bool newState) -> void;
198
199 auto isBlocking() const -> bool;
200 auto setBlocking(bool newState) -> void;
201
202 auto setInitialDelay(float delay) -> void;
203 auto getInitialDelay() const -> float;
204
205 auto setDuration(float duration) -> void;
206 auto getDuration() const -> float;
207
208 auto setEndingDelay(float delay) -> void;
209 auto getEndingDelay() const -> float;
210
211 auto getTotalLifetime() const -> float;
212
217 auto getName() -> std::string;
218
223 auto getCompletionPercentage() const -> float;
224
229 auto getCurve() const -> th::Bezier;
230
234 auto setCurve(const th::Bezier& curve) -> void;
235
236 // These are protected so derived Actions can access them
237protected:
238
240 std::string actionName = "BaseAction";
241
243 bool blocking = false;
244
245 auto percentageComplete() const -> float;
246
247 template<typename T>
248 auto lerpBasedOnTime(const T& start, const T& end) -> T
249 {
250 return curve.value(normalizedTime, start, end);
251 }
252
253private:
254
255 float totalDuration = 0.1f;
256 float currentTime = 0.f;
257
259 float normalizedTime = 0.f;
260
262 float initialDelay = 0.f;
264 float endingDelay = 0.f;
265
266 bool hasInitialized = false;
267 bool hasExecuted = false;
268 bool hasEnded = false;
269
270 bool paused = false;
271
272
274};
Wrapper for cubic bezier curve class.
auto operator==(const Action &other) const -> bool
Definition Action.cpp:23
auto getEndingDelay() const -> float
Definition Action.cpp:195
auto getHasInitialized() const -> bool
Definition Action.cpp:135
auto setPaused(bool newState) -> void
Definition Action.cpp:155
auto getCompletionPercentage() const -> float
Function used to see how much the action has completed.
Definition Action.cpp:222
auto getTotalLifetime() const -> float
Definition Action.cpp:200
auto percentageComplete() const -> float
Definition Action.cpp:237
float normalizedTime
Age of the Action on a scale of 0-1. Note that this is after applying the curve.
Definition Action.h:259
th::Bezier curve
Definition Action.h:273
bool hasInitialized
Definition Action.h:266
auto getName() -> std::string
Function used for displaying info about what an Action does.
Definition Action.cpp:217
Entity * changingObject
Definition Action.h:239
float currentTime
Definition Action.h:256
Action(const Action &)=default
auto setOwner(Entity *newObject) -> void
Definition Action.cpp:130
auto update(float dt) -> void
Universal update function that handles calling init, update, and end at the right time.
Definition Action.cpp:49
auto getOwner() const -> Entity *
Definition Action.cpp:125
Action(Action &&other) noexcept=default
auto getInitialDelay() const -> float
Definition Action.cpp:175
bool paused
Definition Action.h:270
auto setEndingDelay(float delay) -> void
Definition Action.cpp:190
virtual auto execute() -> void
Virtual function that is called every frame to change a game object.
Definition Action.cpp:209
auto getHasEnded() const -> bool
Definition Action.cpp:145
auto getHasExecuted() const -> bool
Definition Action.cpp:140
auto setCurve(const th::Bezier &curve) -> void
set the curve of the function
Definition Action.cpp:232
std::string actionName
Definition Action.h:240
bool hasEnded
Definition Action.h:268
virtual auto ActionShowMenu() -> void
Displays a window in imgui.
Definition Action.cpp:116
float initialDelay
Delay that acts between the action being created and the action initializing.
Definition Action.h:262
auto setInitialDelay(float delay) -> void
Definition Action.cpp:170
auto getDuration() const -> float
Definition Action.cpp:185
auto setBlocking(bool newState) -> void
Definition Action.cpp:165
virtual auto render() const -> void
Function used to draw things to screen, useful for things such as debug drawing.
Definition Action.cpp:110
auto lerpBasedOnTime(const T &start, const T &end) -> T
Definition Action.h:248
auto setDuration(float duration) -> void
Definition Action.cpp:180
virtual ~Action()=default
virtual auto end() -> void
Virtual function that is called once, when an Action is finished executing.
Definition Action.cpp:213
auto operator=(const Action &) -> Action &=default
auto operator=(Action &&other) noexcept -> Action &=default
bool blocking
If an action is blocking, it stops all actions after it in an ActionList from updating.
Definition Action.h:243
float endingDelay
Delay that acts after the action has finished updating but before it has ended.
Definition Action.h:264
auto getCurve() const -> th::Bezier
Function used to see which type of curve an action has.
Definition Action.cpp:227
bool hasExecuted
Definition Action.h:267
Action()=default
auto isPaused() const -> bool
Definition Action.cpp:150
virtual auto init() -> void
Virtual function that is called once, when the Action is first starting up.
Definition Action.cpp:205
float totalDuration
Definition Action.h:255
auto isBlocking() const -> bool
Definition Action.cpp:160
auto shouldRemove() const -> bool
Definition Action.cpp:104
Definition Entity.h:41
Definition Factory.cpp:38
Definition Bezier.h:30