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 setEndingDelay(float delay) -> void;
204
209 auto getName() -> std::string;
210
215 auto getCompletionPercentage() const -> float;
216
217
218 // These are protected so derived Actions can access them
219protected:
220
222 std::string actionName = "BaseAction";
223
224 auto percentageComplete() const -> float;
225
226 template<typename T>
227 auto lerpBasedOnTime(const T& start, const T& end) -> T
228 {
229 return curve.value(normalizedTime, start, end);
230 }
231
232private:
233 float totalDuration = 0.1f;
234 float currentTime = 0.f;
235
236 // Age of the Action on a scale of 0-1. Note that this is after applying the curve
237 float normalizedTime = 0.f;
238
239 float initialDelay = 0.f;
240 float endingDelay = 0.f;
241
242 bool hasInitialized = false;
243 bool hasExecuted = false;
244 bool hasEnded = false;
245
246 bool paused = false;
247
248 bool blocking = false;
249
251};
Wrapper for cubic bezier curve class.
auto operator==(const Action &other) const -> bool
Definition Action.cpp:23
auto getHasInitialized() const -> bool
Definition Action.cpp:130
auto setPaused(bool newState) -> void
Definition Action.cpp:150
auto getCompletionPercentage() const -> float
Function used to see how much the action has completed.
Definition Action.cpp:192
auto percentageComplete() const -> float
Definition Action.cpp:197
float normalizedTime
Definition Action.h:237
th::Bezier curve
Definition Action.h:250
bool hasInitialized
Definition Action.h:242
auto getName() -> std::string
Function used for displaying info about what an Action does.
Definition Action.cpp:187
Entity * changingObject
Definition Action.h:221
float currentTime
Definition Action.h:234
Action(const Action &)=default
auto setOwner(Entity *newObject) -> void
Definition Action.cpp:125
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:120
Action(Action &&other) noexcept=default
bool paused
Definition Action.h:246
auto setEndingDelay(float delay) -> void
Definition Action.cpp:170
virtual auto execute() -> void
Virtual function that is called every frame to change a game object.
Definition Action.cpp:179
auto getHasEnded() const -> bool
Definition Action.cpp:140
auto getHasExecuted() const -> bool
Definition Action.cpp:135
std::string actionName
Definition Action.h:222
bool hasEnded
Definition Action.h:244
virtual auto ActionShowMenu() -> void
Displays a window in imgui.
Definition Action.cpp:115
float initialDelay
Definition Action.h:239
auto setInitialDelay(float delay) -> void
Definition Action.cpp:165
auto setBlocking(bool newState) -> void
Definition Action.cpp:160
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:227
virtual ~Action()=default
virtual auto end() -> void
Virtual function that is called once, when an Action is finished executing.
Definition Action.cpp:183
auto operator=(const Action &) -> Action &=default
auto operator=(Action &&other) noexcept -> Action &=default
bool blocking
Definition Action.h:248
float endingDelay
Definition Action.h:240
bool hasExecuted
Definition Action.h:243
Action()=default
auto isPaused() const -> bool
Definition Action.cpp:145
virtual auto init() -> void
Virtual function that is called once, when the Action is first starting up.
Definition Action.cpp:175
float totalDuration
Definition Action.h:233
auto isBlocking() const -> bool
Definition Action.cpp:155
auto shouldRemove() const -> bool
Definition Action.cpp:104
Definition Entity.h:39
Definition Bezier.h:30