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

plFallbackGameState is an plGameState that can handle existing worlds when no other game state is available. More...

#include <FallbackGameState.h>

Inheritance diagram for plFallbackGameState:

Public Member Functions

void EnableSceneSelectionMenu (bool bEnable)
 If disabled, pressing the Windows key won't show an onscreen menu to switch to a different scene.
 
void EnableFreeCameras (bool bEnable)
 If disabled, moving around a scene with a free camera won't be possible.
 
void EnableAutoSwitchToLoadedScene (bool bEnable)
 If disabled, the game state will not automatically switch to a scene that is being loaded in the background, once it is finished loading. Instead overriding code has to call SwitchToLoadedScene() itself.
 
virtual void ProcessInput () override
 Called once per game update. Should handle input updates here.
 
virtual void AfterWorldUpdate () override
 Called once each frame after the worlds have been updated.
 
virtual plGameStatePriority DeterminePriority (plWorld *pWorld) const override
 Returns plGameStatePriority::Fallback.
 
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 plString GetStartupSceneFile ()
 Returns the path to the scene file to load at startup. By default this is taken from the command line '-scene' option.
 
void SwitchToLoadingScreen ()
 Creates a new world that's used as a temporary loading screen while waiting for loading of another world to finish.
 
plResult StartSceneLoading (plStringView sSceneFile, plStringView sPreloadCollection)
 Starts loading a scene in the background.
 
void CancelSceneLoading ()
 If a scene is currently being loaded in the background, cancel the loading.
 
bool IsLoadingScene () const
 Whether a scene is currently being loaded.
 
bool IsInLoadingScreen () const
 Whether the game state currently displays a loading screen. This usually implies that a scene is being loaded as well.
 
void SwitchToLoadedScene ()
 Once scene loading has finished successfully, this can be called to switch to that scene.
 
plStringView GetActiveSceneName () const
 Returns the name of the plWorld that is currently active.
 
plStringView GetLoadingSceneName () const
 Returns the name of the plWorld that is currently being loaded.
 
- Public Member Functions inherited from plGameState
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 BeforeWorldUpdate ()
 Called once each frame before the worlds are updated.
 
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 Types

enum class  State {
  Ok , NoProject , BadProject , NoScene ,
  BadScene
}
 

Protected Member Functions

virtual plUniquePtr< plWorldCreateLoadingScreenWorld ()
 Called by SwitchToLoadingScreen() to setup a new world that acts as the loading screen while waiting for another scene to finish loading.
 
virtual void ConfigureInputActions () override
 Adds custom input actions, if necessary. Unless overridden OnActivation() will call this.
 
virtual plResult SpawnPlayer (const plTransform *pStartPosition) override
 Overridable function that may create a player object.
 
virtual const plCameraComponentFindActiveCameraComponent ()
 
void FindAvailableScenes ()
 
bool DisplayMenu ()
 
- Protected Member Functions inherited from plGameState
 plGameState ()
 This class cannot be instantiated directly.
 
virtual void CreateActors ()
 Creates an actor with a default window (plGameStateWindow) adds it to the application.
 
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

plInt32 m_iActiveCameraComponentIndex
 
plUniquePtr< plWorldm_pActiveWorld
 
plUniquePtr< plSceneLoadUtilitym_pSceneToLoad
 
State m_State = State::Ok
 
bool m_bShowMenu = false
 
bool m_bEnableSceneSelectionMenu = true
 
bool m_bEnableFreeCameras = true
 
bool m_bIsInLoadingScreen = false
 
bool m_bAutoSwitchToLoadedScene = true
 
bool m_bCheckedForScenes = false
 
plDynamicArray< plStringm_AvailableScenes
 
plUInt32 m_uiSelectedScene = 0
 
plString m_sTitleOfLoadingScene
 
plString m_sTitleOfActiveScene
 
- Protected Attributes inherited from plGameState
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

plFallbackGameState is an plGameState that can handle existing worlds when no other game state is available.

This game state returns a priority of 'Fallback' in DeterminePriority() and therefore only takes over when no other game state is available. It implements a simple first person camera to fly around a scene.

This game state cannot be used in stand-alone applications that require the game state to create a new world. It is mainly for plEditor and plPlayer which make sure that a world already exists.

Member Function Documentation

◆ AfterWorldUpdate()

void plFallbackGameState::AfterWorldUpdate ( )
overridevirtual

Called once each frame after the worlds have been updated.

Reimplemented from plGameStateBase.

◆ ConfigureInputActions()

void plFallbackGameState::ConfigureInputActions ( )
overrideprotectedvirtual

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

Reimplemented from plGameState.

◆ DeterminePriority()

plGameStatePriority plFallbackGameState::DeterminePriority ( plWorld * pWorld) const
overridevirtual

Returns plGameStatePriority::Fallback.

Implements plGameStateBase.

◆ EnableFreeCameras()

void plFallbackGameState::EnableFreeCameras ( bool bEnable)

If disabled, moving around a scene with a free camera won't be possible.

Also switching between scene cameras with Page Up/Down will be disabled.

◆ OnActivation()

void plFallbackGameState::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.

Reimplemented from plGameState.

◆ OnDeactivation()

void plFallbackGameState::OnDeactivation ( )
overridevirtual

Called when the game state is being shut down.

Reimplemented from plGameState.

◆ ProcessInput()

void plFallbackGameState::ProcessInput ( )
overridevirtual

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

Reimplemented from plGameStateBase.

◆ SpawnPlayer()

plResult plFallbackGameState::SpawnPlayer ( const plTransform * pStartPosition)
overrideprotectedvirtual

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 from plGameState.

◆ StartSceneLoading()

plResult plFallbackGameState::StartSceneLoading ( plStringView sSceneFile,
plStringView sPreloadCollection )

Starts loading a scene in the background.

If available, a collection can be provided. Resources referenced in the collection will be fully preloaded first and then the scene is loaded. This is the only way to get a proper estimation of loading progress and is necessary to get a smooth start, otherwise the engine will have to load resources on-demand, many of which will be needed during the first frame.

◆ SwitchToLoadingScreen()

void plFallbackGameState::SwitchToLoadingScreen ( )

Creates a new world that's used as a temporary loading screen while waiting for loading of another world to finish.

Usually this world would be set up in code and would be very quick to create. By default an entirely empty world is created.


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