GameBase Class
Namespace: Stride.GamesAssembly: Stride.Games.dll
The game.
public abstract class GameBase : ComponentBase, IDisposable, IComponent, IReferencable, ICollectorHolder, IGame
Name | Description | |
---|---|---|
Constructors | ||
GameBase() | Initializes a new instance of the GameBase class. |
|
Fields | ||
graphicsDeviceManager | ||
Log | ||
Properties | ||
Content | Gets the ContentManager. |
|
Context | Gets the game context. |
|
DrawInterpolationFactor | Is used when we draw without running an update beforehand, so when both IsFixedTimeStep
and IsDrawDesynchronized are set. |
|
DrawTime | The total and delta time to be used for logic running in the draw loop. |
|
DrawWhileMinimized | Should this instance still render/draw when the window is minimized. Updates are still going to run regardless of the value set. |
|
ForceOneUpdatePerDraw | Gets or sets a value indicating whether this instance should force exactly one update step per one draw step |
|
FullPlatformName | Gets the full name of the device this game is running if available |
|
GameSystems | Gets the game components registered by this game. |
|
GraphicsContext | ||
GraphicsDevice | Gets the graphics device. |
|
InactiveSleepTime | Gets or sets the time between each Tick() when IsActive is false. |
|
IsActive | Gets a value indicating whether this instance is active. |
|
IsDrawDesynchronized | When IsFixedTimeStep is set, is it allowed to render frames between two steps when we have time to do so. |
|
IsExiting | Gets a value indicating whether this instance is exiting. |
|
IsFixedTimeStep | Gets or sets a value indicating whether the elapsed time between each update should be constant, see TargetElapsedTime to configure the duration. |
|
IsMouseVisible | Gets or sets a value indicating whether the mouse should be visible. |
|
IsRunning | Gets a value indicating whether this instance is running. |
|
LaunchParameters | Gets the launch parameters. |
|
MinimizedMinimumUpdateRate | Access to the throttler used to set the minimum time allowed between each updates while the window is minimized and, depending on TreatNotFocusedLikeMinimized, while unfocused. |
|
Services | Gets the service container. |
|
TargetElapsedTime | Gets or sets the target elapsed time, this is the duration of each tick/update when IsFixedTimeStep is enabled. |
|
TreatNotFocusedLikeMinimized | Considers windows without user focus like a minimized window for MinimizedMinimumUpdateRate |
|
UpdateTime | The total and delta time to be used for logic running in the update loop. |
|
Window | Gets the abstract window. |
|
WindowMinimumUpdateRate | Access to the throttler used to set the minimum time allowed between each updates. |
|
Methods | ||
BeginDraw() | Starts the drawing of a frame. This method is followed by calls to Update(GameTime), Draw(GameTime) and EndDraw(Boolean). |
|
BeginRun() | Called after all components are initialized, before the game loop starts. |
|
ConfirmRenderingSettings(Boolean) | ||
Destroy() | ||
Draw(GameTime) | Reference page contains code sample. |
|
EndDraw(Boolean) | Ends the drawing of a frame. This method will always be preceeded by calls to BeginDraw() and perhaps Draw(GameTime) depending on if we had to do so. |
|
EndRun() | Called after the game loop has stopped running before exiting. |
|
Exit() | Exits the game. |
|
Initialize() | Called after the Game is created, but before GraphicsDevice is available and before LoadContent(). Reference page contains code sample. |
|
OnActivated(Object, EventArgs) | Raises the Activated event. Override this method to add code to handle when the game gains focus. |
|
OnDeactivated(Object, EventArgs) | Raises the Deactivated event. Override this method to add code to handle when the game loses focus. |
|
OnExiting(Object, EventArgs) | Raises an Exiting event. Override this method to add code to handle when the game is exiting. |
|
OnWindowCreated() | ||
PrepareContext() | Creates or updates Context before window and device are created. |
|
RawTick(TimeSpan, Int32, Single, Boolean) | Call this method within your overriden RawTickProducer() to update and draw the game yourself. |
|
RawTickProducer() | Calls RawTick(TimeSpan, Int32, Single, Boolean) automatically based on this game's setup, override it to implement your own system. |
|
ResetElapsedTime() | Resets the elapsed time counter. |
|
Run(GameContext) | Call this method to initialize the game, begin running the game loop, and start processing events for the game. |
|
ShowMissingRequirementMessage(Exception) | This is used to display an error message if there is no suitable graphics device or sound card. |
|
SuppressDraw() | Prevents calls to Draw until the next Update. |
|
Tick() | Updates the game's clock and calls Update and Draw. |
|
UnloadContent() | Called when graphics resources need to be unloaded. Override this method to unload any game-specific graphics resources. |
|
Update(GameTime) | Reference page contains links to related conceptual articles. |
|
Events | ||
Activated | Occurs when [activated]. |
|
Deactivated | Occurs when [deactivated]. |
|
Exiting | Occurs when [exiting]. |
|
UnhandledException | ||
WindowCreated | Occurs when [window created]. |
Constructors
GameBase()
Initializes a new instance of the GameBase class.
protected GameBase()
Fields
graphicsDeviceManager
protected IGraphicsDeviceManager graphicsDeviceManager
Field Value
Type | Description |
---|---|
IGraphicsDeviceManager |
Log
protected readonly ILogger Log
Field Value
Type | Description |
---|---|
ILogger |
Properties
Content
Gets the ContentManager.
public ContentManager Content { get; }
Property Value
Type | Description |
---|---|
ContentManager |
Context
Gets the game context.
public GameContext Context { get; }
Property Value
Type | Description |
---|---|
GameContext | The game context. |
DrawInterpolationFactor
Is used when we draw without running an update beforehand, so when both IsFixedTimeStep
and IsDrawDesynchronized are set.
It returns a number between 0 and 1 which represents the current position our DrawTime is in relation
to the previous and next step.
0.5 would mean that we are rendering at a time halfway between the previous and next fixed-step.
public float DrawInterpolationFactor { get; }
Property Value
Type | Description |
---|---|
System.Single | The draw interpolation factor. |
DrawTime
The total and delta time to be used for logic running in the draw loop.
public GameTime DrawTime { get; }
Property Value
Type | Description |
---|---|
GameTime |
DrawWhileMinimized
Should this instance still render/draw when the window is minimized. Updates are still going to run regardless of the value set.
public bool DrawWhileMinimized { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
ForceOneUpdatePerDraw
Gets or sets a value indicating whether this instance should force exactly one update step per one draw step
protected bool ForceOneUpdatePerDraw { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
FullPlatformName
Gets the full name of the device this game is running if available
public string FullPlatformName { get; }
Property Value
Type | Description |
---|---|
System.String |
GameSystems
Gets the game components registered by this game.
public GameSystemCollection GameSystems { get; }
Property Value
Type | Description |
---|---|
GameSystemCollection | The game components. |
GraphicsContext
public GraphicsContext GraphicsContext { get; }
Property Value
Type | Description |
---|---|
GraphicsContext |
GraphicsDevice
Gets the graphics device.
public GraphicsDevice GraphicsDevice { get; }
Property Value
Type | Description |
---|---|
GraphicsDevice | The graphics device. |
InactiveSleepTime
public TimeSpan InactiveSleepTime { get; set; }
Property Value
Type | Description |
---|---|
System.TimeSpan | The inactive sleep time. |
IsActive
Gets a value indicating whether this instance is active.
public bool IsActive { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
IsDrawDesynchronized
When IsFixedTimeStep is set, is it allowed to render frames between two steps when we have time to do so.
public bool IsDrawDesynchronized { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
IsExiting
Gets a value indicating whether this instance is exiting.
public bool IsExiting { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
IsFixedTimeStep
Gets or sets a value indicating whether the elapsed time between each update should be constant, see TargetElapsedTime to configure the duration.
public bool IsFixedTimeStep { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
IsMouseVisible
Gets or sets a value indicating whether the mouse should be visible.
public bool IsMouseVisible { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
IsRunning
Gets a value indicating whether this instance is running.
public bool IsRunning { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
LaunchParameters
Gets the launch parameters.
public LaunchParameters LaunchParameters { get; }
Property Value
Type | Description |
---|---|
LaunchParameters | The launch parameters. |
MinimizedMinimumUpdateRate
Access to the throttler used to set the minimum time allowed between each updates while the window is minimized and, depending on TreatNotFocusedLikeMinimized, while unfocused.
public ThreadThrottler MinimizedMinimumUpdateRate { get; }
Property Value
Type | Description |
---|---|
ThreadThrottler |
Services
Gets the service container.
public ServiceRegistry Services { get; }
Property Value
Type | Description |
---|---|
ServiceRegistry | The service container. |
TargetElapsedTime
Gets or sets the target elapsed time, this is the duration of each tick/update when IsFixedTimeStep is enabled.
public TimeSpan TargetElapsedTime { get; set; }
Property Value
Type | Description |
---|---|
System.TimeSpan | The target elapsed time. |
TreatNotFocusedLikeMinimized
Considers windows without user focus like a minimized window for MinimizedMinimumUpdateRate
public bool TreatNotFocusedLikeMinimized { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
UpdateTime
The total and delta time to be used for logic running in the update loop.
public GameTime UpdateTime { get; }
Property Value
Type | Description |
---|---|
GameTime |
Window
Gets the abstract window.
public GameWindow Window { get; }
Property Value
Type | Description |
---|---|
GameWindow | The window. |
WindowMinimumUpdateRate
Access to the throttler used to set the minimum time allowed between each updates.
public ThreadThrottler WindowMinimumUpdateRate { get; }
Property Value
Type | Description |
---|---|
ThreadThrottler |
Methods
BeginDraw()
Starts the drawing of a frame. This method is followed by calls to Update(GameTime), Draw(GameTime) and EndDraw(Boolean).
protected virtual bool BeginDraw()
Returns
Type | Description |
---|---|
System.Boolean |
|
BeginRun()
Called after all components are initialized, before the game loop starts.
protected virtual void BeginRun()
ConfirmRenderingSettings(Boolean)
public abstract void ConfirmRenderingSettings(bool gameCreation)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | gameCreation |
Destroy()
protected override void Destroy()
Overrides
Draw(GameTime)
Reference page contains code sample.
protected virtual void Draw(GameTime gameTime)
Parameters
Type | Name | Description |
---|---|---|
GameTime | gameTime | Time passed since the last call to Draw. |
EndDraw(Boolean)
Ends the drawing of a frame. This method will always be preceeded by calls to BeginDraw() and perhaps Draw(GameTime) depending on if we had to do so.
protected virtual void EndDraw(bool present)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | present |
EndRun()
Called after the game loop has stopped running before exiting.
protected virtual void EndRun()
Exit()
Exits the game.
public void Exit()
Initialize()
Called after the Game is created, but before GraphicsDevice is available and before LoadContent(). Reference page contains code sample.
protected virtual void Initialize()
OnActivated(Object, EventArgs)
Raises the Activated event. Override this method to add code to handle when the game gains focus.
protected virtual void OnActivated(object sender, EventArgs args)
Parameters
Type | Name | Description |
---|---|---|
System.Object | sender | The Game. |
System.EventArgs | args | Arguments for the Activated event. |
OnDeactivated(Object, EventArgs)
Raises the Deactivated event. Override this method to add code to handle when the game loses focus.
protected virtual void OnDeactivated(object sender, EventArgs args)
Parameters
Type | Name | Description |
---|---|---|
System.Object | sender | The Game. |
System.EventArgs | args | Arguments for the Deactivated event. |
OnExiting(Object, EventArgs)
Raises an Exiting event. Override this method to add code to handle when the game is exiting.
protected virtual void OnExiting(object sender, EventArgs args)
Parameters
Type | Name | Description |
---|---|---|
System.Object | sender | The Game. |
System.EventArgs | args | Arguments for the Exiting event. |
OnWindowCreated()
protected virtual void OnWindowCreated()
PrepareContext()
Creates or updates Context before window and device are created.
protected virtual void PrepareContext()
RawTick(TimeSpan, Int32, Single, Boolean)
Call this method within your overriden RawTickProducer() to update and draw the game yourself.
As this version is manual, there are a lot of functionality purposefully skipped:
clamping elapsed time to a maximum, skipping drawing when the window is minimized, ResetElapsedTime(), SuppressDraw(), IsFixedTimeStep,
IsDrawDesynchronized, MinimizedMinimumUpdateRate / WindowMinimumUpdateRate / TreatNotFocusedLikeMinimized.
protected void RawTick(TimeSpan elapsedTimePerUpdate, int updateCount = 1, float drawInterpolationFactor = 0F, bool drawFrame = true)
Parameters
Type | Name | Description |
---|---|---|
System.TimeSpan | elapsedTimePerUpdate | The amount of time passed between each update of the game's system,
the total time passed would be |
System.Int32 | updateCount | The amount of updates that will be executed on the game's systems. |
System.Single | drawInterpolationFactor | |
System.Boolean | drawFrame | Draw a frame. |
RawTickProducer()
Calls RawTick(TimeSpan, Int32, Single, Boolean) automatically based on this game's setup, override it to implement your own system.
protected virtual void RawTickProducer()
ResetElapsedTime()
Resets the elapsed time counter.
public void ResetElapsedTime()
Run(GameContext)
Call this method to initialize the game, begin running the game loop, and start processing events for the game.
public void Run(GameContext gameContext = null)
Parameters
Type | Name | Description |
---|---|---|
GameContext | gameContext | The window Context for this game. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Cannot run this instance while it is already running |
ShowMissingRequirementMessage(Exception)
This is used to display an error message if there is no suitable graphics device or sound card.
protected virtual bool ShowMissingRequirementMessage(Exception exception)
Parameters
Type | Name | Description |
---|---|---|
System.Exception | exception | The exception to display. |
Returns
Type | Description |
---|---|
System.Boolean | The System.Boolean. |
SuppressDraw()
Prevents calls to Draw until the next Update.
public void SuppressDraw()
Tick()
Updates the game's clock and calls Update and Draw.
public void Tick()
UnloadContent()
Called when graphics resources need to be unloaded. Override this method to unload any game-specific graphics resources.
protected virtual void UnloadContent()
Update(GameTime)
Reference page contains links to related conceptual articles.
protected virtual void Update(GameTime gameTime)
Parameters
Type | Name | Description |
---|---|---|
GameTime | gameTime | Time passed since the last call to Update. |
Events
Activated
Occurs when [activated].
public event EventHandler<EventArgs> Activated
Event Type
Type | Description |
---|---|
System.EventHandler<System.EventArgs> |
Deactivated
Occurs when [deactivated].
public event EventHandler<EventArgs> Deactivated
Event Type
Type | Description |
---|---|
System.EventHandler<System.EventArgs> |
Exiting
Occurs when [exiting].
public event EventHandler<EventArgs> Exiting
Event Type
Type | Description |
---|---|
System.EventHandler<System.EventArgs> |
UnhandledException
public event EventHandler<GameUnhandledExceptionEventArgs> UnhandledException
Event Type
Type | Description |
---|---|
System.EventHandler<GameUnhandledExceptionEventArgs> |
WindowCreated
Occurs when [window created].
public event EventHandler<EventArgs> WindowCreated
Event Type
Type | Description |
---|---|
System.EventHandler<System.EventArgs> |