|
VR-Engage
2.2
|
DtPlayerStationStateManager provides a robust state management system for VR-Engage. It maintains a stack of states and handles transitions between them in a controlled manner. State operations are queued and processed during the tick cycle to ensure proper ordering and prevent state inconsistencies.
#include <playerStationStateManager.h>
Public Types | |
| enum | DtStackOp { NO_OP , OP_PUSH , OP_TRANSITION , OP_POP , OP_POP_UNTIL } |
| using | DtStateList = std::list<DtPlayerStationState*> |
| using | DtRegisteredStates = std::map<std::string, DtPlayerStationState*> |
| using | DtQueuedOp = std::tuple<DtStackOp, std::string, std::shared_ptr<DtPlayerStationStateArgs>> |
| using | DtStackOpQueue = std::deque<DtQueuedOp> |
Public Member Functions | |
| DtPlayerStationStateManager (const DtPlayerStationStateManager &)=delete | |
| DtPlayerStationStateManager & | operator= (const DtPlayerStationStateManager &)=delete |
| virtual void | registerState (DtPlayerStationState *state) |
| virtual void | tick (double dt) |
| virtual void | push (const std::string &state, DtPlayerStationStateArgs *args=NULL) |
| virtual void | transition (const std::string &state, DtPlayerStationStateArgs *args=NULL) |
| virtual void | pop () |
| virtual void | popUntil (const std::string &state, DtPlayerStationStateArgs *args=NULL) |
| DtPlayerStationState * | getState (const std::string &state) |
| virtual DtPlayerStationState * | currentState () |
| virtual bool | containsStateType (const std::string &state) |
| int | findStackPos (const std::string &state) |
| const void | debugDumpDeque () |
| virtual void | debugCallback () |
Protected Member Functions | |
| DtPlayerStationStateManager (DtPlayerStationApp &app) | |
| virtual | ~DtPlayerStationStateManager () |
| void | doTransition (const std::string &toState, const DtPlayerStationStateArgs *args) |
| void | doPop (const DtPlayerStationStateArgs *args=NULL) |
| void | doPush (const std::string &newState, const DtPlayerStationStateArgs *args) |
| void | doPopUntil (const std::string &exposeState, const DtPlayerStationStateArgs *args) |
| bool | isRegistered (const std::string &state) |
Protected Attributes | |
| DtStateList | myStateStack |
| DtRegisteredStates | myRegisteredStates |
| DtPlayerStationApp & | myApp |
| DtStackOpQueue | myStackOpQueue |
Friends | |
| class | DtPlayerStationApp |
| class | DtVreDebugManager |
| using makVre::DtPlayerStationStateManager::DtStateList = std::list<DtPlayerStationState*> |
Type definition for the state stack.
| using makVre::DtPlayerStationStateManager::DtRegisteredStates = std::map<std::string, DtPlayerStationState*> |
Type definition for the map of registered states.
| using makVre::DtPlayerStationStateManager::DtQueuedOp = std::tuple<DtStackOp, std::string, std::shared_ptr<DtPlayerStationStateArgs>> |
Type definition for a queued state operation Contains operation type, state name, and arguments.
| using makVre::DtPlayerStationStateManager::DtStackOpQueue = std::deque<DtQueuedOp> |
Type definition for the queue of state operations.
|
delete |
Deleted copy constructor.
Prevents copying of the state manager instance
References DtPlayerStationStateManager().
Referenced by DtPlayerStationStateManager(), and operator=().
|
protected |
Constructor.
| app | Reference to the player station application |
Initializes the state manager with a reference to the app. Constructor is protected to ensure only DtPlayerStationApp can create instances.
References DtPlayerStationApp.
|
protectedvirtual |
Virtual destructor.
Cleans up any remaining states and resources
|
delete |
Deleted assignment operator.
Prevents assignment of the state manager instance
References DtPlayerStationStateManager().
|
virtual |
Registers a new state with the manager.
| state | Pointer to the state to register |
Adds a state to the internal map of registered states, making it available for transitions. The state name is used as the key.
|
virtual |
Main tick function called from the player station tick.
| dt | Delta time since the last tick in seconds |
Processes any queued state operations and calls the tick method of the current active state. State operations are processed in the order they were queued.
|
virtual |
Queues a state to push onto the stack.
| state | Name of the state to push |
| args | Optional arguments to pass to the state |
The pushed state becomes the new active state, but the previous state remains on the stack. When the new state is later popped, the previous state will become active again.
|
virtual |
Queues a state to transition from the current active state.
| state | Name of the state to transition to |
| args | Optional arguments to pass to the new state |
Replaces the current active state with the new state. The previous state is removed from the stack and its exit method is called.
|
virtual |
Queues an operation to pop the active state off the stack.
Removes the current active state from the stack and makes the state below it the new active state. If there is no state below, the stack will be empty after this operation.
|
virtual |
Queues an operation to pop states until a specific state is exposed.
| state | Name of the state to expose |
| args | Optional arguments to pass to the exposed state |
Pops states from the stack until the specified state becomes the active state. If the state is not in the stack, this will result in an empty stack.
| DtPlayerStationState * makVre::DtPlayerStationStateManager::getState | ( | const std::string & | state | ) |
Gets a state by its name.
| state | Name of the state to retrieve |
Looks up a registered state by its name and returns a pointer to it. Returns NULL if the state is not registered.
|
virtual |
Gets the currently active state.
Returns the state at the top of the stack, which is the currently active state. Returns NULL if the stack is empty.
|
virtual |
Checks if a specific state type is in the stack.
| state | Name of the state to check for |
Searches the state stack for a state with the specified name. Returns true if found, false otherwise.
| int makVre::DtPlayerStationStateManager::findStackPos | ( | const std::string & | state | ) |
Finds the position of a state in the stack.
| state | Name of the state to find |
Searches for a state in the stack and returns its position. Position 0 is the bottom of the stack, with higher indices moving toward the top. Returns -1 if the state is not in the stack.
| const void makVre::DtPlayerStationStateManager::debugDumpDeque | ( | ) |
Dumps the contents of the operation queue for debugging.
Outputs the current contents of the operation queue to the debug log, showing each pending operation and its associated state and arguments.
|
virtual |
Debug callback function.
Called during debugging to allow inspection of the state manager
|
protected |
Performs a state transition operation.
| toState | Name of the state to transition to |
| args | Pointer to arguments for the new state |
Internal implementation for transitioning from the current state to a new state. Calls exit on the old state and enter on the new state.
|
protected |
Performs a pop operation on the state stack.
| args | Optional arguments to pass to the newly exposed state |
Internal implementation for popping the top state off the stack. Calls exit on the popped state and resume on the newly exposed state.
|
protected |
Performs a push operation on the state stack.
| newState | Name of the state to push |
| args | Pointer to arguments for the new state |
Internal implementation for pushing a new state onto the stack. Calls pause on the current state and enter on the new state.
|
protected |
Performs a popUntil operation on the state stack.
| exposeState | Name of the state to expose |
| args | Pointer to arguments for the exposed state |
Internal implementation for popping states until a specific state is exposed. Calls exit on all popped states and resume on the newly exposed state.
|
protected |
Checks if a state is registered.
| state | Name of the state to check |
Internal function that verifies if a state with the given name is registered in the state manager.
|
friend |
References DtPlayerStationApp.
Referenced by DtPlayerStationApp, and DtPlayerStationStateManager().
|
friend |
References DtVreDebugManager.
Referenced by DtVreDebugManager.
|
protected |
The state stack.
Contains the currently active states with the most recent at the front
|
protected |
Map of all registered states.
Maps state names to their corresponding state objects
|
protected |
Reference to the player station application.
Provides access to the application for states that need it
|
protected |
Queue of pending state operations.
Contains operations to be processed during the next tick, each with an operation type, state name, and arguments