Plasma Engine  2.0
Loading...
Searching...
No Matches
plGameStateBase Class Referenceabstract

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

#include <GameStateBase.h>

Inheritance diagram for plGameStateBase:

Public Member Functions

virtual void OnActivation (plWorld *pWorld, const plTransform *pStartPosition)=0
 When a game state was chosen, it gets activated through this function.
 
virtual void OnDeactivation ()=0
 Called when the game state is being shut down.
 
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 ScheduleRendering ()=0
 Has to call plRenderLoop::AddMainView for all views that need to be rendered.
 
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 Attributes

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 'priority' 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

◆ AfterWorldUpdate()

void plGameStateBase::AfterWorldUpdate ( )
virtual

Called once each frame after the worlds have been updated.

Reimplemented in plFallbackGameState.

◆ DeterminePriority()

virtual plGameStatePriority plGameStateBase::DeterminePriority ( plWorld * pWorld) const
pure virtual

Called by plGameApplication to determine which game state is best suited to handle a situation.

If the application already has a world that should be shown, the game state can inspect it. If the game state is expected to create a new world, pWorld will be nullptr.

Implemented in plFallbackGameState.

◆ OnActivation()

virtual void plGameStateBase::OnActivation ( plWorld * pWorld,
const plTransform * pStartPosition )
pure virtual

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.

Implemented in plFallbackGameState, and plGameState.

◆ OnDeactivation()

virtual void plGameStateBase::OnDeactivation ( )
pure virtual

Called when the game state is being shut down.

Implemented in plFallbackGameState, and plGameState.

◆ ProcessInput()

void plGameStateBase::ProcessInput ( )
virtual

Called once per game update. Should handle input updates here.

Reimplemented in plFallbackGameState.

◆ RequestQuit()

void plGameStateBase::RequestQuit ( )
virtual

Call this to signal that a game state requested the application to quit.

plGameApplication will shut down when this happens. plEditor will stop play-the-game mode when it is running.

◆ ScheduleRendering()

virtual void plGameStateBase::ScheduleRendering ( )
pure virtual

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

Implemented in plGameState.


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