Plasma Engine  2.0
Loading...
Searching...
No Matches
plGameState Class Reference

plGameState is the base class to build custom game logic upon. It works closely together with plGameApplication. More...

#include <GameState.h>

Inheritance diagram for plGameState:

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.
 
plCameraGetMainCamera ()
 Gives access to the game state's main camera object.
 
- Public Member Functions inherited from plGameStateBase
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.
 
- Public Member Functions inherited from plReflectedClass
virtual const plRTTIGetDynamicRTTI () 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< plActorCreateXRActor ()
 Creates an XR Actor if XR is configured and available for the project.
 
plViewCreateMainView ()
 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< plWindowCreateMainWindow ()
 Override this to modify the default window creation behavior. Called by CreateActors().
 
virtual plUniquePtr< plWindowOutputTargetGALCreateMainOutputTarget (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
 
plWorldm_pMainWorld = nullptr
 
plCamera m_MainCamera
 
bool m_bStateWantsToQuit = false
 
bool m_bXREnabled = false
 
bool m_bXRRemotingEnabled = false
 
plUniquePtr< plDummyXRm_pDummyXR
 
- Protected Attributes inherited from plGameStateBase
bool m_bStateWantsToQuit = false
 

Additional Inherited Members

- Static Public Member Functions inherited from plNoBase
static const plRTTIGetStaticRTTI ()
 

Detailed Description

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.

Note
Do not forget to reflect your derived class, otherwise plGameApplication may not find it.

Member Function Documentation

◆ ConfigureInputActions()

void plGameState::ConfigureInputActions ( )
protectedvirtual

Adds custom input actions, if necessary. Unless overridden OnActivation() will call this.

Reimplemented in plFallbackGameState.

◆ CreateActors()

void plGameState::CreateActors ( )
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.

◆ OnActivation()

void plGameState::OnActivation ( plWorld * pWorld,
const plTransform * pStartPosition )
overridevirtual

When a game state was chosen, it gets activated through this function.

Parameters
pWorldThe 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.
pStartPositionAn 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.

◆ OnDeactivation()

void plGameState::OnDeactivation ( )
overridevirtual

Called when the game state is being shut down.

Implements plGameStateBase.

Reimplemented in plFallbackGameState.

◆ ScheduleRendering()

void plGameState::ScheduleRendering ( )
overridevirtual

Has to call plRenderLoop::AddMainView for all views that need to be rendered.

Implements plGameStateBase.

◆ SpawnPlayer()

plResult plGameState::SpawnPlayer ( const plTransform * pStartPosition)
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.


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