Game

Namespace: Murder
Assembly: Murder.dll

public class Game : Game, IDisposable

Implements: Game, IDisposable

⭐ Constructors

public Game(IMurderGame game, GameDataManager dataManager)

Creates a new game, there should only be one game instance ever. If is not initialized, it will create the starting scene from GameProfile.

Parameters
game IMurderGame
dataManager GameDataManager

public Game(IMurderGame game)

Parameters
game IMurderGame

⭐ Properties

_disposePendingWorld

protected bool _disposePendingWorld;

Returns
bool

_gameData

protected readonly GameDataManager _gameData;

Returns
GameDataManager

_graphics

protected readonly GraphicsDeviceManager _graphics;

Returns
GraphicsDeviceManager

_logger

protected GameLogger _logger;

Single logger of the game.

Returns
GameLogger

_pendingExit

protected bool _pendingExit;

Returns
bool

_pendingWorld

protected MonoWorld _pendingWorld;

Returns
MonoWorld

_pendingWorldTransition

protected T? _pendingWorldTransition;

Returns
T?

_playerInput

protected readonly PlayerInput _playerInput;

Returns
PlayerInput

_sceneLoader

protected SceneLoader _sceneLoader;

Initialized in Game.LoadContent.

Returns
SceneLoader

ActiveScene

public Scene ActiveScene { get; }

Returns
Scene

AlwaysUpdateBeforeFixed

protected virtual bool AlwaysUpdateBeforeFixed { get; }

Always run update before fixed update. Override this for a different behavior.

Returns
bool

Components

public GameComponentCollection Components { get; }

Returns
GameComponentCollection

Content

public ContentManager Content { get; public set; }

Returns
ContentManager

Data

public static GameDataManager Data { get; }

Gets the GameDataManager instance.

Returns
GameDataManager

DeltaTime

public static float DeltaTime { get; }

De time difference between current and last update, scaled by pause and other time scaling. Value is reliable only during the Update().

Returns
float

DIAGNOSTICS_MODE

public static bool DIAGNOSTICS_MODE;

Use this to set whether diagnostics should be pulled.

Returns
bool

Downsample

public float Downsample;

Returns
float

FixedDeltaTime

public static float FixedDeltaTime { get; }

Gets the fixed delta time in seconds.

Returns
float

Fullscreen

public bool Fullscreen { get; public set; }

Gets or sets the fullscreen mode of the game. When set, it updates the game's window to reflect the new mode.

Returns
bool

GameScale

public Vector2 GameScale { get; }

Gets the scale of the game relative to the window size and game profile scale. Returns Vector2.One if the window has invalid dimensions.

Returns
Vector2

GraphicsDevice

public GraphicsDevice GraphicsDevice { get; }

Gets the current instance of the GraphicsDevice.

Returns
GraphicsDevice

GraphicsDeviceManager

public GraphicsDeviceManager GraphicsDeviceManager { get; }

Returns
GraphicsDeviceManager

GraphLogger

public virtual GraphLogger GraphLogger { get; }

Gets the current graph logger debugger.

Returns
GraphLogger

Grid

public static GridConfiguration Grid { get; }

Beautiful hardcoded grid so it's very easy to access in game!

Returns
GridConfiguration

HasCursor

protected virtual bool HasCursor { get; }

Returns
bool

Height

public static int Height { get; }

Gets the game height from the GameProfile. This is the intended size, not the actual size. For the current window size use RenderContext.Camera.

Returns
int

InactiveSleepTime

public TimeSpan InactiveSleepTime { get; public set; }

Returns
TimeSpan

InitialScene

protected virtual Scene InitialScene { get; }

Returns
Scene

Input

public static PlayerInput Input { get; }

Gets the PlayerInput instance.

Returns
PlayerInput

Instance

public static Game Instance { get; private set; }

Singleton instance of the game. wBe cautious when referencing this...

Returns
Game

IsActive

public bool IsActive { get; internal set; }

Returns
bool

IsDiagnosticEnabled

protected virtual bool IsDiagnosticEnabled { get; }

Returns
bool

IsFixedTimeStep

public bool IsFixedTimeStep { get; public set; }

Returns
bool

IsMouseVisible

public bool IsMouseVisible { get; public set; }

Returns
bool

IsPaused

public bool IsPaused { get; private set; }

Returns
bool

IsSkippingDeltaTimeOnUpdate

public bool IsSkippingDeltaTimeOnUpdate { get; }

Whether the player is currently skipping frames (due to cutscene) and ignore the time while calling update methods.

Returns
bool

LaunchParameters

public LaunchParameters LaunchParameters { get; }

Returns
LaunchParameters

LONGEST_TIME_RESET

public static const float LONGEST_TIME_RESET;

Returns
float

LongestRenderTime

public float LongestRenderTime { get; private set; }

Gets the longest render time ever recorded.

Returns
float

LongestUpdateTime

public float LongestUpdateTime { get; private set; }

Returns
float

Now

public static float Now { get; }

Gets the current scaled elapsed time.

Returns
float

NowAbsolute

public static float NowAbsolute { get; }

Gets the absolute time since the game started. This is not affected by pause, freeze frames or time scaling.

Returns
float

NowUnscaled

public static float NowUnscaled { get; }

Gets the current unscaled elapsed time.

Returns
float

Preferences

public static GamePreferences Preferences { get; }

Gets the GamePreferences asset instance.

Returns
GamePreferences

PreviousElapsedTime

public float PreviousElapsedTime { get; }

Elapsed time in seconds from the previous update frame since the game started

Returns
float

PreviousNow

public static float PreviousNow { get; }

Gets the scaled elapsed time from the previous fixed update.

Returns
float

PreviousNowUnscaled

public static float PreviousNowUnscaled { get; }

Time from previous fixed update.

Returns
float

Profile

public static GameProfile Profile { get; }

Gets the GameProfile asset instance.

Returns
GameProfile

Random

public static Random Random;

Provides a static Random instance.

Returns
Random

RenderTime

public float RenderTime { get; private set; }

Time in seconds that the Draw() method took to finish

Returns
float

Save

public static SaveData Save { get; }

Gets the active SaveData asset instance.

Returns
SaveData

Services

public GameServiceContainer Services { get; }

Returns
GameServiceContainer

Sound

public static ISoundPlayer Sound { get; }

Gets the ISoundPlayer instance.

Returns
ISoundPlayer

SoundPlayer

public readonly ISoundPlayer SoundPlayer;

Returns
ISoundPlayer

StartedSkippingCutscene

public bool StartedSkippingCutscene;

Whether the player started skipping.

Returns
bool

TargetElapsedTime

public TimeSpan TargetElapsedTime { get; public set; }

Returns
TimeSpan

TimeScale

public float TimeScale;

Returns
float

TimeTrackerDiagnoostics

public static UpdateTimeTracker TimeTrackerDiagnoostics;

Only updated if Game.DIAGNOSTICS_MODE is set.

Returns
UpdateTimeTracker

UnscaledDeltaTime

public static float UnscaledDeltaTime { get; }

De time difference between current and last update. Value is reliable only during the Update().

Returns
float

UpdateTime

public float UpdateTime { get; private set; }

Returns
float

Width

public static int Width { get; }

Gets the game width from the GameProfile. This is the intended size, not the actual size. For the current window size use RenderContext.Camera.

Returns
int

Window

public GameWindow Window { get; }

Returns
GameWindow

⭐ Events

Activated

public event EventHandler<TEventArgs> Activated;

Returns
EventHandler<TEventArgs>

Deactivated

public event EventHandler<TEventArgs> Deactivated;

Returns
EventHandler<TEventArgs>

Disposed

public event EventHandler<TEventArgs> Disposed;

Returns
EventHandler<TEventArgs>

Exiting

public event EventHandler<TEventArgs> Exiting;

Returns
EventHandler<TEventArgs>

⭐ Methods

BeginDraw()

protected virtual bool BeginDraw()

Returns
bool

ShowMissingRequirementMessage(Exception)

protected virtual bool ShowMissingRequirementMessage(Exception exception)

Parameters
exception Exception

Returns
bool

LoadSceneAsync(bool)

protected virtual Task LoadSceneAsync(bool waitForAllContent)

Asynchronously loads the game's content.

Parameters
waitForAllContent bool

Returns
Task

ApplyGameSettingsImpl()

protected virtual void ApplyGameSettingsImpl()

Virtual method for extended game settings application in derived classes.

BeginRun()

protected virtual void BeginRun()

Dispose(bool)

protected virtual void Dispose(bool isDisposing)

Parameters
isDisposing bool

Draw(GameTime)

protected virtual void Draw(GameTime gameTime)

Renders the current frame, handling loading draw and ImGui rendering, and tracks rendering time.

Parameters
gameTime GameTime

DrawImGui(GameTime)

protected virtual void DrawImGui(GameTime gameTime)

Placeholder for extending the ImGui drawing functionality in game editor.

Parameters
gameTime GameTime

EndDraw()

protected virtual void EndDraw()

EndRun()

protected virtual void EndRun()

ExitGame()

protected virtual void ExitGame()

Exit the game. This is used to wrap any custom behavior depending on the game implementation.

Finalize()

protected virtual void Finalize()

Initialize()

protected virtual void Initialize()

Initializes the game by setting up input bindings and configuring initial settings. Typically overridden by the game implementation.

LoadContent()

protected virtual void LoadContent()

Loads game content and initializes it. This includes initializing the sound player, game data, settings, shaders, and initial scene. Also asynchronously loads the initial scene.

LoadContentImpl()

protected virtual void LoadContentImpl()

Virtual method for extended content loading implementation in derived classes.

OnActivated(Object, EventArgs)

protected virtual void OnActivated(Object sender, EventArgs args)

Parameters
sender Object
args EventArgs

OnDeactivated(Object, EventArgs)

protected virtual void OnDeactivated(Object sender, EventArgs args)

Parameters
sender Object
args EventArgs

OnExiting(Object, EventArgs)

protected virtual void OnExiting(Object sender, EventArgs args)

Parameters
sender Object
args EventArgs

OnLoadingDraw(RenderContext)

protected virtual void OnLoadingDraw(RenderContext render)

Display drawing for the load animation.

Parameters
render RenderContext

SetWindowSize(Point)

protected virtual void SetWindowSize(Point screenSize)

Sets the window size for the game based on the specified screen size and full screen settings.

Parameters
screenSize Point

UnloadContent()

protected virtual void UnloadContent()

Update(GameTime)

protected virtual void Update(GameTime gameTime)

Performs game frame updates, handling logic for paused states, fixed updates, and unscaled time.

Parameters
gameTime GameTime

ApplyGameSettings()

protected void ApplyGameSettings()

Applies game settings based on the current Murder.Game._gameData. Configures grid and rendering settings, and calls an implementation-specific settings application method.

DoPendingExitGame()

protected void DoPendingExitGame()

DoPendingWorldTransition()

protected void DoPendingWorldTransition()

UpdateImpl(GameTime)

protected void UpdateImpl(GameTime gameTime)

Implements core update logic, including frame freezing, world transitions, input handling, and time scaling.

Parameters
gameTime GameTime

CanResumeAfterSaveComplete()

public bool CanResumeAfterSaveComplete()

Determines if the game can resume after a save operation is complete. Returns true if there's no active save data or the save operation has finished.

Returns
bool

QueueReplaceWorldOnCurrentScene(MonoWorld, bool)

public bool QueueReplaceWorldOnCurrentScene(MonoWorld world, bool disposeWorld)

This is called when replacing the world for a current scene. Happened when transition from two different scenes (already loaded) as a world.

Parameters
world MonoWorld
disposeWorld bool

Returns
bool

QueueWorldTransition(Guid)

public bool QueueWorldTransition(Guid world)

Parameters
world Guid

Returns
bool

ResumeDeltaTimeOnUpdate()

public bool ResumeDeltaTimeOnUpdate()

Resume game to normal game time.

Returns
bool

CreateRenderContext(GraphicsDevice, Camera2D, RenderContextFlags)

public RenderContext CreateRenderContext(GraphicsDevice graphicsDevice, Camera2D camera, RenderContextFlags settings)

Creates a RenderContext using the specified graphics device, camera, and settings. Returns a new RenderContext if the game instance is null. Optionally implement this interface for using your custom RenderContext.

Parameters
graphicsDevice GraphicsDevice

camera Camera2D

settings RenderContextFlags

Returns
RenderContext

BeginImGuiTheme()

public virtual void BeginImGuiTheme()

Placeholder for setting up a custom ImGui theme, to be extended in game editor.

Dispose()

public virtual void Dispose()

EndImGuiTheme()

public virtual void EndImGuiTheme()

Placeholder for finalizing a custom ImGui theme, to be extended in game editor.

RefreshWindow()

public virtual void RefreshWindow()

Refreshes the game window settings based on the current profile.

Exit()

public void Exit()

FreezeFrames(int)

public void FreezeFrames(int amount)

This will pause the game for of frames.

Parameters
amount int

Pause()

public void Pause()

This will pause the game.

QueueExitGame()

public void QueueExitGame()

This queues such that the game exit at the end of the update. We wait until the end of the update to avoid any access to a world that has been disposed on cleanup.

ResetElapsedTime()

public void ResetElapsedTime()

Resume()

public void Resume()

This will resume the game.

Run()

public void Run()

RunOneFrame()

public void RunOneFrame()

SetWaitForSaveComplete()

public void SetWaitForSaveComplete()

Sets the flag to indicate that the game should wait for the save operation to complete.

SkipDeltaTimeOnUpdate()

public void SkipDeltaTimeOnUpdate()

This will skip update times and immediately run the update calls from the game until Game.ResumeDeltaTimeOnUpdate is called.

SuppressDraw()

public void SuppressDraw()

Tick()

public void Tick()