NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
s_FState.hpp
1#pragma once
2#include <game/sLib/s_StateInterfaces.hpp>
3#include <game/sLib/s_FStateID.hpp>
4
5/// @brief A state holder for a given class.
6/// @tparam T The class that this state belongs to.
7/// @ingroup state
8template<class T>
9class sFState_c : public sStateIf_c {
10public:
11 sFState_c(T &owner) : mpOwner(owner), mpID(nullptr) {}
12
13 enum STATE_ACTION_e {
14 INITIALIZE,
15 EXECUTE,
16 FINALIZE
17 };
18
19 /// @brief Performs a state action.
20 /// @details [Gets inlined, needed for function order to match].
21 /// @param action The action to perform.
22 void performAction(STATE_ACTION_e action) {
23 if (action == FINALIZE) {
24 mpID->finalizeState(mpOwner);
25 } else if (action == EXECUTE) {
26 mpID->executeState(mpOwner);
27 } else if (action == INITIALIZE) {
28 mpID->initializeState(mpOwner);
29 }
30 }
31
32 virtual void initialize() { performAction(INITIALIZE); }
33 virtual void execute() { performAction(EXECUTE); }
34 virtual void finalize() { performAction(FINALIZE); }
35
36 void setID(const sFStateID_c<T> *id) { mpID = id; }
37
38private:
39 T &mpOwner; ///< The owner of this state.
40 const sFStateID_c<T> *mpID; ///< The state ID that runs the state methods.
41};
An implementation of a state ID for a given class.
virtual void finalize()
Prepares the state for termination.
Definition s_FState.hpp:34
void performAction(STATE_ACTION_e action)
Performs a state action.
Definition s_FState.hpp:22
const sFStateID_c< T > * mpID
The state ID that runs the state methods.
Definition s_FState.hpp:40
virtual void execute()
Executes the state.
Definition s_FState.hpp:33
T & mpOwner
The owner of this state.
Definition s_FState.hpp:39
virtual void initialize()
Initializes the state.
Definition s_FState.hpp:32
The interface for a state holder.