Class Game
Represents the main game class responsible for managing game loops, scenes, rendering, and updates.
Inherited Members
Namespace: Genesis.Core
Assembly: Genesis.dll
Syntax
public class Game
Constructors
Game(IRenderDevice, Viewport)
Creates a new instance of the Game class.
Declaration
public Game(IRenderDevice renderDevice, Viewport viewport)
Parameters
| Type | Name | Description |
|---|---|---|
| IRenderDevice | renderDevice | The rendering device to use. |
| Viewport | viewport | The viewport configuration. |
Properties
AssetManager
Gets or sets the asset manager for handling game assets.
Declaration
public AssetManager AssetManager { get; set; }
Property Value
| Type | Description |
|---|---|
| AssetManager |
DeltaTime
Gets or sets the time elapsed since the last frame in milliseconds.
Declaration
public double DeltaTime { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
FPS
Gets or sets the current frames per second achieved by the game loop.
Declaration
public double FPS { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
GameThread
Declaration
public Thread GameThread { get; set; }
Property Value
| Type | Description |
|---|---|
| Thread |
LastFrame
Gets or sets the timestamp of the last frame.
Declaration
public long LastFrame { get; set; }
Property Value
| Type | Description |
|---|---|
| long |
RenderDevice
Gets or sets the rendering device used by the game.
Declaration
public IRenderDevice RenderDevice { get; set; }
Property Value
| Type | Description |
|---|---|
| IRenderDevice |
Run
Gets or sets a value indicating whether the game loop is running.
Declaration
public bool Run { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Scenes
Gets or sets the list of scenes in the game.
Declaration
public List<Scene> Scenes { get; set; }
Property Value
| Type | Description |
|---|---|
| List<Scene> |
SelectedScene
Gets or sets the currently selected scene.
Declaration
public Scene SelectedScene { get; set; }
Property Value
| Type | Description |
|---|---|
| Scene |
Storage
Gets or sets the storage object for managing game data.
Declaration
public Storage Storage { get; set; }
Property Value
| Type | Description |
|---|---|
| Storage |
TargetFPS
Gets or sets the target frames per second for the game loop.
Declaration
public int TargetFPS { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
Viewport
Gets or sets the viewport configuration for rendering.
Declaration
public Viewport Viewport { get; set; }
Property Value
| Type | Description |
|---|---|
| Viewport |
Methods
AddScene(Scene)
Adds a scene to the list of scenes.
Declaration
public Scene AddScene(Scene scene)
Parameters
| Type | Name | Description |
|---|---|---|
| Scene | scene | The Scene object to be added. |
Returns
| Type | Description |
|---|---|
| Scene | The added Scene object. |
EndFrame(long)
Ends the current frame by processing storage and updating timing information.
Declaration
public void EndFrame(long currentFrame)
Parameters
| Type | Name | Description |
|---|---|---|
| long | currentFrame | The current time in milliseconds. |
FindScene(string)
Search for the scene with the given name
Declaration
public Scene FindScene(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name for the scene |
Returns
| Type | Description |
|---|---|
| Scene |
GetElementCenterScreenLocation2D(GameElement)
Returns the screen location of the given element with a center anchor.
Declaration
public Vec3 GetElementCenterScreenLocation2D(GameElement element)
Parameters
| Type | Name | Description |
|---|---|---|
| GameElement | element | The GameElement to get the centered screen coordinates for. |
Returns
| Type | Description |
|---|---|
| Vec3 | A Vec3 representing the centered screen coordinates of the element. |
GetElementScreenLocation2D(GameElement)
Get the screen coordinates of the given element.
Declaration
public Vec3 GetElementScreenLocation2D(GameElement element)
Parameters
| Type | Name | Description |
|---|---|---|
| GameElement | element | The GameElement to get the screen coordinates for. |
Returns
| Type | Description |
|---|---|
| Vec3 | A Vec3 representing the screen coordinates of the element. |
GetSceneCord(Vec3)
Transforms a display vector to a vector inside the scene.
Declaration
public Vec3 GetSceneCord(Vec3 location)
Parameters
| Type | Name | Description |
|---|---|---|
| Vec3 | location | The display vector to transform. |
Returns
| Type | Description |
|---|---|
| Vec3 | A Vec3 representing the transformed vector inside the scene. |
GetScene<T>()
Declaration
public T GetScene<T>() where T : Scene
Returns
| Type | Description |
|---|---|
| T |
Type Parameters
| Name | Description |
|---|---|
| T |
InitGame()
Initialize the game
Declaration
public void InitGame()
InitGameElement(GameElement)
Initializes a GameElement within the game environment.
Declaration
public void InitGameElement(GameElement element)
Parameters
| Type | Name | Description |
|---|---|---|
| GameElement | element | The GameElement to be initialized. |
LoadScene(Scene)
Loads a scene
Declaration
public void LoadScene(Scene scene)
Parameters
| Type | Name | Description |
|---|---|---|
| Scene | scene | The scene to be loaded. |
LoadScene(string)
Loads a scene with the given name.
Declaration
public void LoadScene(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name of the scene to be loaded. |
Loop()
Main game loop. Handles updates and rendering.
Declaration
public void Loop()
NextFrame(long)
Determines if it's time to proceed to the next frame based on the target FPS.
Declaration
public bool NextFrame(long currentFrame)
Parameters
| Type | Name | Description |
|---|---|---|
| long | currentFrame | The current time in milliseconds. |
Returns
| Type | Description |
|---|---|
| bool | True if enough time has passed to proceed to the next frame, otherwise false. |
RenderFrame(long)
Renders the current frame.
Declaration
public void RenderFrame(long currentFrame)
Parameters
| Type | Name | Description |
|---|---|---|
| long | currentFrame | The current time in milliseconds. |
Start()
Starts the main game loop.
Declaration
public void Start()
Stop()
Stops the main game loop.
Declaration
public void Stop()
StopGame()
Stops the game and cleans up resources.
Declaration
public void StopGame()
UpdateFrame(long)
Updates the game state for the current frame.
Declaration
public void UpdateFrame(long currentFrame)
Parameters
| Type | Name | Description |
|---|---|---|
| long | currentFrame | The current time in milliseconds. |
Events
AfterRender
Event triggered after rendering.
Declaration
public event GameEventHandler AfterRender
Event Type
| Type | Description |
|---|---|
| GameEventHandler |
AfterUpdate
Event triggered after the game update.
Declaration
public event GameEventHandler AfterUpdate
Event Type
| Type | Description |
|---|---|
| GameEventHandler |
BeforeRender
Event triggered before rendering.
Declaration
public event GameEventHandler BeforeRender
Event Type
| Type | Description |
|---|---|
| GameEventHandler |
BeforeUpdate
Event triggered before the game update.
Declaration
public event GameEventHandler BeforeUpdate
Event Type
| Type | Description |
|---|---|
| GameEventHandler |
OnDispose
Event triggered when the game is disposed.
Declaration
public event GameEventHandler OnDispose
Event Type
| Type | Description |
|---|---|
| GameEventHandler |
OnInit
Event triggered when the game initializes.
Declaration
public event GameEventHandler OnInit
Event Type
| Type | Description |
|---|---|
| GameEventHandler |
OnRenderBeginn
Event triggered at the beginning of rendering.
Declaration
public event GameEventHandler OnRenderBeginn
Event Type
| Type | Description |
|---|---|
| GameEventHandler |
OnRenderEnd
Event triggered at the end of rendering.
Declaration
public event GameEventHandler OnRenderEnd
Event Type
| Type | Description |
|---|---|
| GameEventHandler |
OnUpdate
Event triggered during the game update.
Declaration
public event GameEventHandler OnUpdate
Event Type
| Type | Description |
|---|---|
| GameEventHandler |