Open 3D Engine GameState Gem API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
GameState::GameStateRequests Class Referenceabstract

EBus interface used to submit requests related to game state management. More...

#include <GameStateRequestBus.h>

Inherits AZ::EBusTraits.

Public Member Functions

virtual void UpdateActiveGameState ()=0
 
virtual AZStd::shared_ptr< IGameStateGetActiveGameState ()=0
 
virtual bool PushGameState (AZStd::shared_ptr< IGameState > newGameState)=0
 
virtual bool PopActiveGameState ()=0
 
virtual void PopAllGameStates ()=0
 Pop all game states from the stack, leaving it empty.
 
virtual bool ReplaceActiveGameState (AZStd::shared_ptr< IGameState > newGameState)=0
 
virtual bool DoesStackContainGameStateOfTypeId (const AZ::TypeId &gameStateTypeId)=0
 
virtual bool AddGameStateFactoryOverrideForTypeId (const AZ::TypeId &gameStateTypeId, GameStateFactory factory)=0
 
virtual bool RemoveGameStateFactoryOverrideForTypeId (const AZ::TypeId &gameStateTypeId)=0
 
virtual GameStateFactory GetGameStateFactoryOverrideForTypeId (const AZ::TypeId &gameStateTypeId)=0
 

Static Public Member Functions

template<class GameStateType >
static AZStd::shared_ptr< IGameStateCreateNewOverridableGameStateOfType (bool checkForOverride=true)
 
template<class GameStateType >
static void CreateAndPushNewOverridableGameStateOfType (bool checkForOverride=true)
 
template<class GameStateType >
static bool PopActiveGameStateUntilOfType ()
 
template<class GameStateType >
static bool IsActiveGameStateOfType ()
 
template<class GameStateType >
static bool DoesStackContainGameStateOfType ()
 
template<class GameStateType >
static bool AddGameStateFactoryOverrideForType (GameStateFactory factory)
 
template<class GameStateType >
static bool RemoveGameStateFactoryOverrideForType ()
 
template<class GameStateType >
static GameStateFactory GetGameStateFactoryOverrideForType ()
 

Static Public Attributes

static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single
 
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single
 

Detailed Description

EBus interface used to submit requests related to game state management.

Member Function Documentation

◆ AddGameStateFactoryOverrideForType()

template<class GameStateType >
bool GameState::GameStateRequests::AddGameStateFactoryOverrideForType ( GameStateFactory  factory)
inlinestatic

Add a game state override so that a request to push a new game state of a certain type will result in pushing a new game state of a different type instead. This is useful for situations where we want to use a set of default game states but override some (or all) of them with custom versions which satisfy the requirements of a specific game project.

Template Parameters
GameStateTypeThe original game state type to be overridden
Parameters
[in]factoryThe factory function that will create the game state override
Returns
True if the game state override was successfully added, false otherwise

◆ AddGameStateFactoryOverrideForTypeId()

virtual bool GameState::GameStateRequests::AddGameStateFactoryOverrideForTypeId ( const AZ::TypeId &  gameStateTypeId,
GameStateFactory  factory 
)
pure virtual

Add a game state override so that a request to push a new game state of a certain type will result in pushing a new game state of a derived type instead. This is useful for situations where we want to use a set of default game states but override some (or all) of them with custom versions which satisfy the requirements of a specific game project.

Parameters
[in]gameStateTypeIdThe original game state type id to be overridden
[in]factoryThe factory function that will create the game state override
Returns
True if the game state override was successfully added, false otherwise

◆ CreateAndPushNewOverridableGameStateOfType()

template<class GameStateType >
void GameState::GameStateRequests::CreateAndPushNewOverridableGameStateOfType ( bool  checkForOverride = true)
inlinestatic

Create a new game state and push it onto the stack to make it the active game state. New game states are created and stored in the stack using a shared_ptr, so they will be destroyed automatically once they are popped off the stack (assuming that nothing else retains a reference, say via GameStateNotifications::OnActiveGameStateChanged).

Template Parameters
GameStateTypeThe game state type to create and activate
Parameters
[in]checkForOverridesTrue if we should check for an override, false otherwise

◆ CreateNewOverridableGameStateOfType()

template<class GameStateType >
AZStd::shared_ptr< IGameState > GameState::GameStateRequests::CreateNewOverridableGameStateOfType ( bool  checkForOverride = true)
inlinestatic

Create a new game state

Template Parameters
GameStateTypeThe game state type to create
Parameters
[in]checkForOverridesTrue if we should check for an override, false otherwise
Returns
A shared pointer to the new game state that was created

◆ DoesStackContainGameStateOfType()

template<class GameStateType >
bool GameState::GameStateRequests::DoesStackContainGameStateOfType
inlinestatic

Query whether the game state stack contains a game state of the specified type

Template Parameters
GameStateTypeThe game state type to check whether is in the stack
Returns
True if the stack contains a game state of the specified type, false otherwise

◆ DoesStackContainGameStateOfTypeId()

virtual bool GameState::GameStateRequests::DoesStackContainGameStateOfTypeId ( const AZ::TypeId &  gameStateTypeId)
pure virtual

Query whether the game state stack contains a game state of the specified type

Parameters
[in]gameStateTypeIdThe game state type to check whether is in the stack
Returns
True if the stack contains a game state of the specified type, false otherwise

◆ GetActiveGameState()

virtual AZStd::shared_ptr< IGameState > GameState::GameStateRequests::GetActiveGameState ( )
pure virtual

Request the active game state (if any)

Returns
A shared pointer to the active game state (will be empty if there is none)

◆ GetGameStateFactoryOverrideForType()

template<class GameStateType >
GameStateFactory GameState::GameStateRequests::GetGameStateFactoryOverrideForType
inlinestatic

Retrieve a game state override that was added using AddGameStateFactoryOverrideForType.

Template Parameters
GameStateTypeThe original game state type that was overridden
Returns
The factory function used to create the game state override, nullptr otherwise

◆ GetGameStateFactoryOverrideForTypeId()

virtual GameStateFactory GameState::GameStateRequests::GetGameStateFactoryOverrideForTypeId ( const AZ::TypeId &  gameStateTypeId)
pure virtual

Retrieve a game state override that was added using AddGameStateFactoryOverrideForTypeId.

Parameters
[in]gameStateTypeIdThe original game state type id that was overridden
Returns
The factory function used to create the game state override, nullptr otherwise

◆ IsActiveGameStateOfType()

template<class GameStateType >
bool GameState::GameStateRequests::IsActiveGameStateOfType
inlinestatic

Query whether the active game state is of the specified type

Template Parameters
GameStateTypeThe game state type to check whether is active
Returns
True if the active game state is of the specified type, false otherwise

◆ PopActiveGameState()

virtual bool GameState::GameStateRequests::PopActiveGameState ( )
pure virtual

Pop the active game state from the stack, which will result in it being deactivated and the game state below it in the stack (if any) becoming the active game state again.

Returns
True if the active game state was successfully popped, false otherwise

◆ PopActiveGameStateUntilOfType()

template<class GameStateType >
bool GameState::GameStateRequests::PopActiveGameStateUntilOfType
inlinestatic

Pop game states from the stack until the active game state is of the specified type. If no game state of the specified type exists in the game state stack it will be left empty.

Template Parameters
GameStateTypeThe game state type in the stack that we want to be active
Returns
True if the active game state is now of the specified type, false otherwise

◆ PushGameState()

virtual bool GameState::GameStateRequests::PushGameState ( AZStd::shared_ptr< IGameState newGameState)
pure virtual

Push a game state onto the stack, which will result in it becoming the active game state. If newGameState is already found in the stack this will fail and return false, however it is possible for multiple instances of the same game state type to occupy the stack.

Parameters
[in]newGameStateThe new game state to push onto the stack
Returns
True if the game state was successfully pushed onto the stack, false otherwise

◆ RemoveGameStateFactoryOverrideForType()

template<class GameStateType >
bool GameState::GameStateRequests::RemoveGameStateFactoryOverrideForType
inlinestatic

Remove a game state override that was added using AddGameStateFactoryOverrideForType.

Template Parameters
GameStateTypeThe original game state type that was overridden
Returns
True if the game state override was successfully removed, false otherwise

◆ RemoveGameStateFactoryOverrideForTypeId()

virtual bool GameState::GameStateRequests::RemoveGameStateFactoryOverrideForTypeId ( const AZ::TypeId &  gameStateTypeId)
pure virtual

Remove a game state override that was added using AddGameStateFactoryOverrideForTypeId.

Parameters
[in]gameStateTypeIdThe original game state type id that was overridden
Returns
True if the game state override was successfully removed, false otherwise

◆ ReplaceActiveGameState()

virtual bool GameState::GameStateRequests::ReplaceActiveGameState ( AZStd::shared_ptr< IGameState newGameState)
pure virtual

Replace the active game state with another game state that will become the active state. If the stack is currently empty, newGameState will be pushed to become the active state. If newGameState is already found in the stack this will fail and return false, however it is possible for multiple instances of the same game state type to occupy the stack. This differs from calling PopActiveGameState followed by PushGameState(newGameState), which would result in the state below the currently active state being activated then immediately deactivated when newGameState is pushed onto the stack; calling this will the state below the currently active state unchanged.

Parameters
[in]newGameStateThe new game state with which to replace the active game state
Returns
True if the active game state was successfully replaced, false otherwise

◆ UpdateActiveGameState()

virtual void GameState::GameStateRequests::UpdateActiveGameState ( )
pure virtual

Update the active game state. This is called during the AZ::ComponentTickBus::TICK_GAME priority update of the AZ::TickBus, but can be called independently any time if needed.

Member Data Documentation

◆ AddressPolicy

const AZ::EBusAddressPolicy GameState::GameStateRequests::AddressPolicy = AZ::EBusAddressPolicy::Single
static

EBus Trait: requests can only be sent to and addressed by a single instance (singleton)


The documentation for this class was generated from the following file: