ss/include/s/s_FState.hpp

61 lines
1.5 KiB
C++
Raw Normal View History

2024-06-01 21:57:11 +00:00
#ifndef S_FSTATE_H
#define S_FSTATE_H
// clang-format off
#include "s/s_StateInterfaces.hpp"
#include "s/s_FStateID.hpp"
// clang-format on
2024-05-31 00:50:17 +00:00
2024-05-31 10:00:20 +00:00
// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib
// See include/s/README.txt for changes made
2024-05-31 00:50:17 +00:00
/// @brief A state holder for a given class.
/// @tparam T The class that this state belongs to.
/// @ingroup state
template <class T>
2024-05-31 00:50:17 +00:00
class sFState_c : public sStateIf_c {
public:
sFState_c(T &owner) : mpOwner(owner) {
mpID = nullptr;
}
2024-05-31 00:50:17 +00:00
enum STATE_ACTION_e {
INITIALIZE,
EXECUTE,
FINALIZE
};
/// @brief Performs a state action.
/// @details [Gets inlined, needed for function order to match].
/// @param action The action to perform.
void performAction(STATE_ACTION_e action) {
if (action == FINALIZE) {
mpID->finalizeState(mpOwner);
} else if (action == EXECUTE) {
mpID->executeState(mpOwner);
} else if (action == INITIALIZE) {
mpID->initializeState(mpOwner);
}
}
virtual const void initialize() {
performAction(INITIALIZE);
}
virtual const void execute() {
performAction(EXECUTE);
}
virtual const void finalize() {
performAction(FINALIZE);
}
2024-05-31 00:50:17 +00:00
void setID(const sFStateID_c<T> *id) {
mpID = id;
}
2024-05-31 00:50:17 +00:00
private:
T &mpOwner; ///< The owner of this state.
2024-05-31 00:50:17 +00:00
const sFStateID_c<T> *mpID; ///< The state ID that runs the state methods.
};
2024-06-01 21:57:11 +00:00
#endif