![]() |
Plasma Engine
2.0
|
plGameState is the base class to build custom game logic upon. It works closely together with plGameApplication. More...
#include <GameState.h>
Public Member Functions | |
virtual void | OnActivation (plWorld *pWorld, const plTransform *pStartPosition) override |
When a game state was chosen, it gets activated through this function. | |
virtual void | OnDeactivation () override |
Called when the game state is being shut down. | |
virtual void | ScheduleRendering () override |
Has to call plRenderLoop::AddMainView for all views that need to be rendered. | |
plCamera * | GetMainCamera () |
Gives access to the game state's main camera object. | |
![]() | |
virtual void | ProcessInput () |
Called once per game update. Should handle input updates here. | |
virtual void | BeforeWorldUpdate () |
Called once each frame before the worlds are updated. | |
virtual void | AfterWorldUpdate () |
Called once each frame after the worlds have been updated. | |
virtual plGameStatePriority | DeterminePriority (plWorld *pWorld) const =0 |
Called by plGameApplication to determine which game state is best suited to handle a situation. | |
virtual void | RequestQuit () |
Call this to signal that a game state requested the application to quit. | |
bool | WasQuitRequested () const |
Returns whether the game state wants to quit the application. | |
![]() | |
virtual const plRTTI * | GetDynamicRTTI () const |
bool | IsInstanceOf (const plRTTI *pType) const |
Returns whether the type of this instance is of the given type or derived from it. | |
template<typename T > | |
PL_ALWAYS_INLINE bool | IsInstanceOf () const |
Returns whether the type of this instance is of the given type or derived from it. | |
Protected Member Functions | |
plGameState () | |
This class cannot be instantiated directly. | |
virtual void | CreateActors () |
Creates an actor with a default window (plGameStateWindow) adds it to the application. | |
virtual void | ConfigureInputActions () |
Adds custom input actions, if necessary. Unless overridden OnActivation() will call this. | |
virtual plResult | SpawnPlayer (const plTransform *pStartPosition) |
Overridable function that may create a player object. | |
plUniquePtr< plActor > | CreateXRActor () |
Creates an XR Actor if XR is configured and available for the project. | |
plView * | CreateMainView () |
Creates a default main view. | |
void | ChangeMainWorld (plWorld *pNewMainWorld) |
Sets m_pMainWorld and updates m_pMainView to use that new world for rendering. | |
virtual void | ConfigureMainCamera () |
Sets up m_MainCamera for first use. | |
virtual plUniquePtr< plWindow > | CreateMainWindow () |
Override this to modify the default window creation behavior. Called by CreateActors(). | |
virtual plUniquePtr< plWindowOutputTargetGAL > | CreateMainOutputTarget (plWindow *pMainWindow) |
Override this to modify the default output target creation behavior. Called by CreateActors(). | |
virtual void | SetupMainView (plGALSwapChainHandle hSwapChain, plSizeU32 viewportSize) |
Creates a default render view. Unless overridden, OnActivation() will do this for the main window. | |
virtual void | ConfigureMainWindowInputDevices (plWindow *pWindow) |
Configures available input devices, e.g. sets mouse speed, cursor clipping, etc. Called by CreateActors() with the result of CreateMainWindow(). | |
Protected Attributes | |
plViewHandle | m_hMainView |
plWorld * | m_pMainWorld = nullptr |
plCamera | m_MainCamera |
bool | m_bStateWantsToQuit = false |
bool | m_bXREnabled = false |
bool | m_bXRRemotingEnabled = false |
plUniquePtr< plDummyXR > | m_pDummyXR |
![]() | |
bool | m_bStateWantsToQuit = false |
Additional Inherited Members | |
![]() | |
static const plRTTI * | GetStaticRTTI () |
plGameState is the base class to build custom game logic upon. It works closely together with plGameApplication.
In a typical game there is always exactly one instance of an plGameState derived class active. The game state handles custom game logic, which must be handled outside plWorld, custom components and scripts.
For example a custom implementation of plGameState may handle how to show a menu, when to switch to another level, how multi-player works, or which player information is transitioned from one level to the next. It's main purpose is to implement high-level game logic.
plGameApplication will loop through all available plGameState implementations and ask each available one whether it can handle a certain level. Each game state returns a 'score' how well it can handle the game.
In a typical game you only have one game state linked into the binary, so in that case there is no reason for such a system. However, in an editor you might have multiple game states available through plugins, but only one can take control. In such a case, each game state may inspect the given world and check whether it is e.g. a single-player or multi-player level, or whether it uses it's own game specific components, and then decide whether it is the best fit for that level.
|
protectedvirtual |
Adds custom input actions, if necessary. Unless overridden OnActivation() will call this.
Reimplemented in plFallbackGameState.
|
protectedvirtual |
Creates an actor with a default window (plGameStateWindow) adds it to the application.
The base implementation calls CreateMainWindow(), CreateMainOutputTarget() and SetupMainView() to configure the main window.
|
overridevirtual |
When a game state was chosen, it gets activated through this function.
pWorld | The game state is supposed to operate on the given world. In a stand-alone application pWorld will always be nullptr and the game state is expected to create worlds itself. When run inside the editor, pWorld will already exist and the game state is expected to work on it. |
pStartPosition | An optional transform for the 'player object' to start at. Usually nullptr, but may be set by the editor to relocate or create the player object at the given destination. |
Implements plGameStateBase.
Reimplemented in plFallbackGameState.
|
overridevirtual |
Called when the game state is being shut down.
Implements plGameStateBase.
Reimplemented in plFallbackGameState.
|
overridevirtual |
Has to call plRenderLoop::AddMainView for all views that need to be rendered.
Implements plGameStateBase.
|
protectedvirtual |
Overridable function that may create a player object.
By default called by OnActivation(). The default implementation will search the world for plPlayerStartComponent's and instantiate the given player prefab at one of those locations. If pStartPosition is not nullptr, it will be used as the spawn position for the player prefab, otherwise the location of the plPlayerStartComponent will be used.
Returns PL_SUCCESS if a prefab was spawned, PL_FAILURE if nothing was done.
Reimplemented in plFallbackGameState.