Brunot
Loading...
Searching...
No Matches
Action Class Reference

#include <Action.h>

Inheritance diagram for Action:
[legend]
Collaboration diagram for Action:
[legend]

Public Member Functions

 Action ()=default
 Action (const Action &)=default
auto operator= (const Action &) -> Action &=default
virtual ~Action ()=default
 Action (Action &&other) noexcept=default
auto operator= (Action &&other) noexcept -> Action &=default
auto operator== (const Action &other) const -> bool
 Action (std::string name)
 Action (std::string name, float duration)
 Action (std::string name, float duration, const th::Bezier &bezierCurve, float initialDelay, float endingDelay)
auto update (float dt) -> void
 Universal update function that handles calling init, update, and end at the right time.
virtual auto init () -> void
 Virtual function that is called once, when the Action is first starting up.
virtual auto execute () -> void
 Virtual function that is called every frame to change a game object.
virtual auto end () -> void
 Virtual function that is called once, when an Action is finished executing.
virtual auto ActionShowMenu () -> void
 Displays a window in imgui.
virtual auto render () const -> void
 Function used to draw things to screen, useful for things such as debug drawing.
auto shouldRemove () const -> bool
auto getOwner () const -> Entity *
auto setOwner (Entity *newObject) -> void
auto getHasInitialized () const -> bool
auto getHasExecuted () const -> bool
auto getHasEnded () const -> bool
auto isPaused () const -> bool
auto setPaused (bool newState) -> void
auto isBlocking () const -> bool
auto setBlocking (bool newState) -> void
auto setInitialDelay (float delay) -> void
auto setEndingDelay (float delay) -> void
auto getName () -> std::string
 Function used for displaying info about what an Action does.
auto getCompletionPercentage () const -> float
 Function used to see how much the action has completed.

Protected Member Functions

auto percentageComplete () const -> float
template<typename T>
auto lerpBasedOnTime (const T &start, const T &end) -> T

Protected Attributes

EntitychangingObject = nullptr
std::string actionName = "BaseAction"

Private Attributes

float totalDuration = 0.1f
float currentTime = 0.f
float normalizedTime = 0.f
float initialDelay = 0.f
float endingDelay = 0.f
bool hasInitialized = false
bool hasExecuted = false
bool hasEnded = false
bool paused = false
bool blocking = false
th::Bezier curve

Detailed Description

At its core, an Action is simply something that changes a variable over a period of time. Actions can move an entity around, make things fade in or out, or even facilitate some gameplay. They are very versatile, but typically very specific. Actions almost always do just 1 thing. Actions are also very self-sufficient; All you need to do is create it and add it to an Entity, and it will handle the rest.

Actions Example

Making and using an Action is very simple. You just create the Action and pass it along to an Entity / ActionList.

For every Action, at minimum you will always need 1 thing: the end goal.

Let's say, for example, that we are a Component and want to apply a MoveToPointAction to our parent Entity. For this specific Action, our end goal will be a point (specifically a Point2D).

Point2D destination = {600,300,0,1};
MoveToPointAction action(destination);
Vector4D Point2D
Definition Transform.h:21
An action that moves an object to a specific point in the game world.
Definition MoveToPointAction.h:32

You can also pass in the variables directly instead of defining them beforehand.

MoveToPointAction otherAction(entity, {600,300,0,1});

Actions have a lot of extra parameters for fine-tuning (like total duration and initial delay, as examples). But you don't have to mess with those if you don't want to. Some of the more interesting ones will be explained in the "Advanced Actions" section.

To add these Actions to an entity, you have a few methods. The easiest option is to use the addAction function (slower but safe) or the << operator (faster but unsafe)

auto parent = getEntityParent();
parent.addAction(action);
parent << otherAction;

Alternatively, you can get the ActionList component itself and add directly to it

auto actionList = parent->getComponent<ActionList>(cActionList);
actionList->pushBack(action);
Component that stores all actions currently affecting the parent entity.
Definition ActionList.h:30
auto pushBack(const std::unique_ptr< Action > &newAction) -> void
Definition ActionList.cpp:159

All at once, adding an Action can look something like this:

parent << MoveToPointAction({600,300,0,1});

Creating New Actions

However, there will be times where the Action you want hasn't been made yet, in which case you will have to create it yourself. Don't worry though, the NewActionStub is mostly filled out for you already. You will just need to update a few things.

I would recommend having your file open to the side of these instructions to make following along easier

  1. Member variables
    • "startingValue" and "endingValue": You will want to update these two to be of the type that you want to change. E.g. if you are changing a color, then you want to make them colors, if you are changing a position then you want to make them points.
    • "component": You should also update the "component" pointer to be the type of whatever component stores the variable you want to change. This is primarily so you don't need to get the component every execute frame.
  2. Constructors
    • You'll want to update the constructors to interact with your ending value and have the right Action name
    • The three constructors that are already provided are the ones that I think are most useful, but you can implement more or less if you want.
  3. Execution Code
  • note: init and execute have some code inside of them provided for you. Across both of them, you have the bare minimum required for an Action to work properly.
    • init: This function is called before the execute loop. It's useful for initiating variables and setting stuff up.
    • execute: This function is called across multiple frames and handles the actual changing of the Entity.
    • exit: This function is called after execute, right before the Action is fully finished and marked for deletion. This function is a bit more specific, so you'll only need to put code in here if necessary.

Advanced Actions

This section is about the extra variables inside of Actions.

Delays

These just delay the activation of certain function calls by some time.

  • initialDelay: This delays when "init" is called.
  • endingDelay: This delays when "end" is called, after the Action has finished executing.

Paused

This one is pretty simple. If an Action is paused, then it simply doesn't update. Once it is unpaused, it will continue updating as normal.

Blocking

If an Action is blocking, then it stops the activation of all Actions after it in the ActionList. I've included an example as to better explain it.

Let's say this is our ActionList

Order: 0 1 2
An action that changes the color (and alpha) of a sprite.
Definition ChangeColorAction.h:27

Normally, when ActionList updates, it will update all of these in order. However, if ChangeColorAction is blocking, then once it is updated, then ActionList stops updating. That means RotateAction (and any other potential Actions after it) WILL NOT UPDATE until ChangeColorAction is done.

Curve

Curves are currently WIP and not very user-friendly right now. Don't worry about it for now, just know that it handles easing. Examples of easing can be found at https://easings.net/

Constructor & Destructor Documentation

◆ Action() [1/6]

Action::Action ( )
default
Here is the caller graph for this function:

◆ Action() [2/6]

Action::Action ( const Action & )
default
Here is the call graph for this function:

◆ ~Action()

virtual Action::~Action ( )
virtualdefault

◆ Action() [3/6]

Action::Action ( Action && other)
defaultnoexcept
Here is the call graph for this function:

◆ Action() [4/6]

Action::Action ( std::string name)

◆ Action() [5/6]

Action::Action ( std::string name,
float duration )

◆ Action() [6/6]

Action::Action ( std::string name,
float duration,
const th::Bezier & bezierCurve,
float initialDelay,
float endingDelay )

Member Function Documentation

◆ ActionShowMenu()

auto Action::ActionShowMenu ( ) ->void
virtual

Displays a window in imgui.

Reimplemented in BroadcastMessageAction, ChangeColorAction, ChangeOpacityAction, LoadSceneAction, MoveEntityAction, MoveToPointAction, MoveVerticalAction, NewActionStub, and SetMessageEnabledAction.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ end()

auto Action::end ( ) ->void
virtual

Virtual function that is called once, when an Action is finished executing.

Reimplemented in BroadcastMessageAction, ChangeColorAction, ChangeOpacityAction, LoadSceneAction, MoveEntityAction, MoveToPointAction, MoveVerticalAction, NewActionStub, and SetMessageEnabledAction.

Here is the caller graph for this function:

◆ execute()

auto Action::execute ( ) ->void
virtual

Virtual function that is called every frame to change a game object.

Reimplemented in BroadcastMessageAction, ChangeColorAction, ChangeOpacityAction, LoadSceneAction, MoveEntityAction, MoveToPointAction, MoveVerticalAction, NewActionStub, and SetMessageEnabledAction.

Here is the caller graph for this function:

◆ getCompletionPercentage()

auto Action::getCompletionPercentage ( ) const->float

Function used to see how much the action has completed.

Returns
A number from 0-1 that indicates how far into completion the action is
Here is the caller graph for this function:

◆ getHasEnded()

auto Action::getHasEnded ( ) const->bool
Returns
If the action has completed
Here is the caller graph for this function:

◆ getHasExecuted()

auto Action::getHasExecuted ( ) const->bool
Returns
If the action is executing/is happening
Here is the caller graph for this function:

◆ getHasInitialized()

auto Action::getHasInitialized ( ) const->bool
Returns
If the action has started
Here is the caller graph for this function:

◆ getName()

auto Action::getName ( ) ->std::string

Function used for displaying info about what an Action does.

Returns
A string that represents the Action
Here is the caller graph for this function:

◆ getOwner()

auto Action::getOwner ( ) const->Entity *
Here is the caller graph for this function:

◆ init()

auto Action::init ( ) ->void
virtual

Virtual function that is called once, when the Action is first starting up.

Reimplemented in BroadcastMessageAction, ChangeColorAction, ChangeOpacityAction, LoadSceneAction, MoveEntityAction, MoveToPointAction, MoveVerticalAction, NewActionStub, and SetMessageEnabledAction.

Here is the caller graph for this function:

◆ isBlocking()

auto Action::isBlocking ( ) const->bool
Here is the caller graph for this function:

◆ isPaused()

auto Action::isPaused ( ) const->bool
Here is the caller graph for this function:

◆ lerpBasedOnTime()

template<typename T>
auto Action::lerpBasedOnTime ( const T & start,
const T & end )->T
inlineprotected
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=() [1/2]

auto Action::operator= ( Action && other) ->Action &=default
defaultnoexcept
Here is the call graph for this function:

◆ operator=() [2/2]

auto Action::operator= ( const Action & ) ->Action &=default
default
Here is the call graph for this function:

◆ operator==()

auto Action::operator== ( const Action & other) const->bool
Here is the call graph for this function:

◆ percentageComplete()

auto Action::percentageComplete ( ) const->float
protected
Here is the caller graph for this function:

◆ render()

auto Action::render ( ) const->void
virtual

Function used to draw things to screen, useful for things such as debug drawing.

Reimplemented in BroadcastMessageAction, ChangeColorAction, ChangeOpacityAction, LoadSceneAction, MoveEntityAction, MoveToPointAction, MoveVerticalAction, NewActionStub, and SetMessageEnabledAction.

Here is the caller graph for this function:

◆ setBlocking()

auto Action::setBlocking ( bool newState) ->void
Here is the caller graph for this function:

◆ setEndingDelay()

auto Action::setEndingDelay ( float delay) ->void
Here is the caller graph for this function:

◆ setInitialDelay()

auto Action::setInitialDelay ( float delay) ->void
Here is the caller graph for this function:

◆ setOwner()

auto Action::setOwner ( Entity * newObject) ->void
Here is the caller graph for this function:

◆ setPaused()

auto Action::setPaused ( bool newState) ->void
Here is the caller graph for this function:

◆ shouldRemove()

auto Action::shouldRemove ( ) const->bool
Here is the caller graph for this function:

◆ update()

auto Action::update ( float dt) ->void

Universal update function that handles calling init, update, and end at the right time.

Parameters
dtThe time in seconds that has elapsed
Here is the call graph for this function:

Member Data Documentation

◆ actionName

std::string Action::actionName = "BaseAction"
protected

◆ blocking

bool Action::blocking = false
private

◆ changingObject

Entity* Action::changingObject = nullptr
protected

◆ currentTime

float Action::currentTime = 0.f
private

◆ curve

th::Bezier Action::curve
private

◆ endingDelay

float Action::endingDelay = 0.f
private

◆ hasEnded

bool Action::hasEnded = false
private

◆ hasExecuted

bool Action::hasExecuted = false
private

◆ hasInitialized

bool Action::hasInitialized = false
private

◆ initialDelay

float Action::initialDelay = 0.f
private

◆ normalizedTime

float Action::normalizedTime = 0.f
private

◆ paused

bool Action::paused = false
private

◆ totalDuration

float Action::totalDuration = 0.1f
private

The documentation for this class was generated from the following files:
  • /home/egrazil/sites/Brunot/The House/source/Actions/Action.h
  • /home/egrazil/sites/Brunot/The House/source/Actions/Action.cpp