ezEngine  Release 25.03
ezFallbackGameState Class Reference

ezFallbackGameState is an ezGameState that can handle existing worlds when no other game state is available. More...

#include <FallbackGameState.h>

Inheritance diagram for ezFallbackGameState:

Public Member Functions

virtual void ProcessInput () override
 The ezGameState doesn't implement any input logic, but it forwards to UpdateBackgroundSceneLoading().
 
virtual void OnActivation (ezWorld *pWorld, ezStringView sStartPosition, const ezTransform &startPositionOffset) override
 Called upon game startup. More...
 
virtual bool IsFallbackGameState () const override
 Reports true for ezFallbackGameState only, not for derived types.
 
- Public Member Functions inherited from ezGameState
ezWorldGetMainWorld ()
 Returns the ezWorld that is currently the active one.
 
ezCameraGetMainCamera ()
 Gives access to the game state's main camera object.
 
ezViewGetMainView ()
 Returns the ezView that is currently the one used for rendering the main output.
 
bool IsLoadingSceneInBackground (float *out_pProgress=nullptr) 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.
 
virtual void OnDeactivation () override
 Cleans up the main window before the game is shut down.
 
virtual void AddMainViewsToRender () override
 Makes sure m_hMainView gets rendered. Mainly needed by the editor.
 
virtual void RequestQuit () override
 Simply stores that the game should stop. More...
 
virtual bool WasQuitRequested () const override
 Whether WasQuitRequested() was called before.
 
void LoadScene (ezStringView sSceneFile, ezStringView sPreloadCollection, ezStringView sStartPosition, const ezTransform &startPositionOffset)
 Immediately switches to a loading screen and starts loading a level. More...
 
void SwitchToLoadingScreen (ezStringView sTargetSceneFile)
 Convenience function to switch to a loading screen. More...
 
void ChangeMainWorld (ezWorld *pNewMainWorld, ezStringView sStartPosition, const ezTransform &startPositionOffset)
 Sets m_pMainWorld and updates m_pMainView to use that new world for rendering. More...
 
void StartBackgroundSceneLoading (ezStringView sSceneFile, ezStringView sPreloadCollection)
 Starts loading a scene in the background. More...
 
void CancelBackgroundSceneLoading ()
 If a scene is currently being loaded in the background, cancel the loading. More...
 
- Public Member Functions inherited from ezGameStateBase
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.
 
- Public Member Functions inherited from ezReflectedClass
virtual const ezRTTIGetDynamicRTTI () const
 
bool IsInstanceOf (const ezRTTI *pType) const
 Returns whether the type of this instance is of the given type or derived from it.
 
template<typename T >
EZ_ALWAYS_INLINE bool IsInstanceOf () const
 Returns whether the type of this instance is of the given type or derived from it.
 

Protected Types

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

Protected Member Functions

virtual void ConfigureInputActions () override
 Called by SwitchToLoadingScreen() to setup a new world that acts as the loading screen while waiting for another scene to finish loading.
 
virtual ezResult SpawnPlayer (ezStringView sStartPosition, const ezTransform &startPositionOffset) override
 Overrideable function that may create a player object. More...
 
virtual const ezCameraComponentFindActiveCameraComponent ()
 
void FindAvailableScenes ()
 
bool DisplayMenu ()
 
virtual void OnBackgroundSceneLoadingFinished (ezUniquePtr< ezWorld > &&pWorld) override
 Called by UpdateBackgroundSceneLoading() when a scene is finished loading. More...
 
virtual void OnBackgroundSceneLoadingFailed (ezStringView sReason) override
 Called by UpdateBackgroundSceneLoading() when a scene failed to load.
 
virtual void ConfigureMainCamera () override
 Searches for a "Main View" ezCameraComponent in the world and uses that for the camera position, if available. More...
 
- Protected Member Functions inherited from ezGameState
 ezGameState ()
 This class cannot be instantiated directly.
 
virtual void CreateActors ()
 Creates an actor with a default window (ezGameStateWindow) adds it to the application. More...
 
ezUniquePtr< ezActorCreateXRActor ()
 Creates an XR Actor, if XR is configured and available for the project.
 
ezViewCreateMainView ()
 Creates a default main view.
 
virtual void OnChangedMainWorld (ezWorld *pPrevWorld, ezWorld *pNewWorld, ezStringView sStartPosition, const ezTransform &startPositionOffset)
 Executed when ChangeMainWorld() is used to switch to a new world. More...
 
virtual ezUniquePtr< ezWindowCreateMainWindow ()
 Override this to modify the default window creation behavior. Called by CreateActors().
 
virtual ezUniquePtr< ezWindowOutputTargetGALCreateMainOutputTarget (ezWindow *pMainWindow)
 Override this to modify the default output target creation behavior. Called by CreateActors().
 
virtual void SetupMainView (ezGALSwapChainHandle hSwapChain, ezSizeU32 viewportSize)
 Creates a default render view. Unless overridden, OnActivation() will do this for the main window.
 
virtual void ConfigureMainWindowInputDevices (ezWindow *pWindow)
 Configures available input devices, e.g. sets mouse speed, cursor clipping, etc. Called by CreateActors() with the result of CreateMainWindow().
 
virtual ezString GetStartupSceneFile ()
 Returns the path to the scene file to load at startup. More...
 
virtual ezUniquePtr< ezWorldCreateLoadingScreenWorld (ezStringView sTargetSceneFile)
 Called by SwitchToLoadingScreen() to set up a new loading screen world. More...
 
void UpdateBackgroundSceneLoading ()
 If a scene is being loaded in the background, this advanced the loading. More...
 
virtual void OnBackgroundSceneLoadingCanceled ()
 Called by CancelBackgroundSceneLoading() when scene loading gets canceled.
 

Protected Attributes

ezInt32 m_iActiveCameraComponentIndex = -3
 
State m_State = State::Ok
 
bool m_bShowMenu = false
 
bool m_bCheckedForScenes = false
 
ezDynamicArray< ezStringm_AvailableScenes
 
ezUInt32 m_uiSelectedScene = 0
 
ezString m_sTitleOfScene
 
- Protected Attributes inherited from ezGameState
ezViewHandle m_hMainView
 
ezWorldm_pMainWorld = nullptr
 
ezCamera m_MainCamera
 
ezUniquePtr< ezDummyXRm_pDummyXR
 
bool m_bStateWantsToQuit = false
 
bool m_bXREnabled = false
 
bool m_bXRRemotingEnabled = false
 
bool m_bTransitionWhenReady = false
 
ezUniquePtr< ezSceneLoadUtilitym_pBackgroundSceneLoad
 
ezUniquePtr< ezWorldm_pLoadingScreenWorld
 
ezUniquePtr< ezWorldm_pLoadedWorld
 
ezString m_sTargetSceneSpawnPoint
 
ezTransform m_TargetSceneSpawnOffset = ezTransform::MakeIdentity()
 

Additional Inherited Members

- Static Public Member Functions inherited from ezGameState
static ezGameStateGetActiveGameState ()
 Returns the active ezGameState. Only one ezGameState is allowed to exist.
 
- Static Public Member Functions inherited from ezNoBase
static const ezRTTIGetStaticRTTI ()
 
- Static Protected Attributes inherited from ezGameState
static ezGameStates_pActiveGameState = nullptr
 

Detailed Description

ezFallbackGameState is an ezGameState 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 ezEditor and ezPlayer which make sure that a world already exists.

Member Function Documentation

◆ ConfigureMainCamera()

void ezFallbackGameState::ConfigureMainCamera ( )
overrideprotectedvirtual

Searches for a "Main View" ezCameraComponent in the world and uses that for the camera position, if available.

Override this for custom camera logic.

Reimplemented from ezGameState.

◆ OnActivation()

void ezFallbackGameState::OnActivation ( ezWorld pWorld,
ezStringView  sStartPosition,
const ezTransform startPositionOffset 
)
overridevirtual

Called upon game startup.

Calls CreateActors() to create the game's main window and setup input devices. Calls ConfigureInputActions() to setup input actions. Finally switches to pWorld (if available) or starts loading the scene that GetStartupSceneFile() returns.

Override any of the above functions to customize them.

Reimplemented from ezGameState.

◆ OnBackgroundSceneLoadingFinished()

void ezFallbackGameState::OnBackgroundSceneLoadingFinished ( ezUniquePtr< ezWorld > &&  pWorld)
overrideprotectedvirtual

Called by UpdateBackgroundSceneLoading() when a scene is finished loading.

May switch to the scene immediately or wait, for example for a user to confirm.

Reimplemented from ezGameState.

◆ SpawnPlayer()

ezResult ezFallbackGameState::SpawnPlayer ( ezStringView  sStartPosition,
const ezTransform startPositionOffset 
)
overrideprotectedvirtual

Overrideable function that may create a player object.

By default called by OnChangedMainWorld() when switching to a non-loading screen world. The default implementation will search the world for ezPlayerStartComponent'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 ezPlayerStartComponent will be used.

sStartPosition allows to spawn the player at another named location, but there is no default implementation for such logic.

Returns EZ_SUCCESS if a prefab was spawned, EZ_FAILURE if nothing was done.

Reimplemented from ezGameState.


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