NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
s_StateMgr.hpp
1#pragma once
2#include <game/sLib/s_StateInterfaces.hpp>
3#include <game/sLib/s_StateIDChk.hpp>
4
5/// @brief The interface for state managers.
6/// @details A state manager handles execution of and transitioning between state IDs.
8public:
9 virtual ~sStateMgrIf_c() {}
10 virtual void initializeState() = 0; ///< Initializes the current state.
11 virtual void executeState() = 0; ///< Executes the current state.
12 virtual void finalizeState() = 0; ///< Prepares the current state for termination.
13 virtual void changeState(const sStateIDIf_c &newStateID) = 0; ///< Transitions to a new state ID.
14 virtual void refreshState() = 0; ///< Marks the current state to be executed again.
15 virtual sStateIf_c *getState() const = 0; ///< Gets the state holder.
16 virtual const sStateIDIf_c *getNewStateID() const = 0; ///< Gets the next state ID.
17 virtual const sStateIDIf_c *getStateID() const = 0; ///< Gets the current state ID.
18 virtual const sStateIDIf_c *getOldStateID() const = 0; ///< Gets the previous state ID.
19};
20
21/**
22 * @brief An implementation of sStateMgrIf_c.
23 *
24 * @tparam T The parent class for this state manager.
25 * @tparam Method The state method handler to use.
26 * @tparam Factory The state factory to use.
27 * @tparam Check The state ID checker to use.
28 * @ingroup state
29 */
30template <class T, class Method, template <class> class Factory, class Check>
31class sStateMgr_c : public sStateMgrIf_c {
32public:
33 sStateMgr_c(T &owner, const sStateIDIf_c &initialState) :
34 mFactory(owner),
35 mMethod(mCheck, mFactory, initialState) {}
36
37 virtual void initializeState() { mMethod.initializeStateMethod(); }
38 virtual void executeState() { mMethod.executeStateMethod(); }
39 virtual void finalizeState() { mMethod.finalizeStateMethod(); }
40
41 virtual void changeState(const sStateIDIf_c &newState) { mMethod.changeStateMethod(newState); }
42
43 virtual void refreshState() { mMethod.refreshStateMethod(); }
44
45 virtual sStateIf_c *getState() const { return mMethod.getState(); }
46 virtual const sStateIDIf_c *getNewStateID() const { return mMethod.getNewStateID(); }
47 virtual const sStateIDIf_c *getStateID() const { return mMethod.getStateID(); }
48 virtual const sStateIDIf_c *getOldStateID() const { return mMethod.getOldStateID(); }
49
50private:
51 Check mCheck;
52 Factory<T> mFactory;
53 Method mMethod;
54};
The interface for state IDs.
The interface for a state holder.
The interface for state managers.
Definition s_StateMgr.hpp:7
virtual const sStateIDIf_c * getStateID() const =0
Gets the current state ID.
virtual void executeState()=0
Executes the current state.
virtual sStateIf_c * getState() const =0
Gets the state holder.
virtual const sStateIDIf_c * getOldStateID() const =0
Gets the previous state ID.
virtual const sStateIDIf_c * getNewStateID() const =0
Gets the next state ID.
virtual void initializeState()=0
Initializes the current state.
virtual void refreshState()=0
Marks the current state to be executed again.
virtual void finalizeState()=0
Prepares the current state for termination.
virtual void changeState(const sStateIDIf_c &newStateID)=0
Transitions to a new state ID.
virtual void executeState()
Executes the current state.
virtual void refreshState()
Marks the current state to be executed again.
virtual const sStateIDIf_c * getOldStateID() const
Gets the previous state ID.
virtual void finalizeState()
Prepares the current state for termination.
virtual const sStateIDIf_c * getStateID() const
Gets the current state ID.
virtual const sStateIDIf_c * getNewStateID() const
Gets the next state ID.
virtual sStateIf_c * getState() const
Gets the state holder.
virtual void changeState(const sStateIDIf_c &newState)
Transitions to a new state ID.
virtual void initializeState()
Initializes the current state.