![]() |
Plasma Engine
2.0
|
plGameState is the base class to build custom game logic upon. It works closely together with plGameApplication. More...
#include <GameStateBase.h>
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. | |
![]() | |
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 Attributes | |
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 '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.
|
virtual |
Called once each frame after the worlds have been updated.
Reimplemented in plFallbackGameState.
|
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.
|
pure virtual |
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. |
Implemented in plFallbackGameState, and plGameState.
|
pure virtual |
Called when the game state is being shut down.
Implemented in plFallbackGameState, and plGameState.
|
virtual |
Called once per game update. Should handle input updates here.
Reimplemented in plFallbackGameState.
|
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.
|
pure virtual |
Has to call plRenderLoop::AddMainView for all views that need to be rendered.
Implemented in plGameState.