Skip to content

GameHost Class

Represents the SadConsole game engine.

C#
public abstract class GameHost : IDisposable

Inheritance object

Implements IDisposable

When a new host is created, the host should do the following: - Run LoadDefaultFonts. - Run SetRenderer for window, controls, layered, and default renderers. - Run LoadMappedColors. - Configure the Screen to a new console with ScreenCellsX and ScreenCellsY. - Prior to running the game, run SplashScreens.SplashScreenManager.CheckRun().

C#
protected GameHost()

Holds all of the IRenderer types.

C#
protected Dictionary<string, Type> _renderers

Holds all of the IRenderStep types.

C#
protected Dictionary<string, Type> _rendererSteps

The date and time the game was started.

C#
protected DateTime _gameStartedAt

The splash screens to show on game startup.

C#
protected Queue<IScreenSurface>? _splashScreens { get; set; }

Instance of the game host.

C#
public static GameHost Instance { get; protected set; }

Contains the path to a file being serialized or deserialized.

C#
public static string SerializerPathHint { get; }

Draw calls registered for the next drawing frame.

C#
public Queue<IDrawCall> DrawCalls { get; }

How many cells fit in the render area width used by SadConsole.

C#
public int ScreenCellsX { get; }

How many cells fit in the render area width used by SadConsole.

C#
public int ScreenCellsY { get; }

A frame number counter, incremented every game frame.

C#
public int FrameNumber { get; set; }

Collection of fonts. Used mainly by the deserialization system.

C#
public Dictionary<string, IFont> Fonts { get; }

The font automatically loaded by SadConsole. Standard IBM style font.

C#
public SadFont EmbeddedFont { get; }

The font automatically loaded by SadConsole. Standard IBM style font. Extended with extra SadConsole characters.

C#
public SadFont EmbeddedFontExtended { get; }

The default font for any type that does not provide a font.

C#
public IFont DefaultFont { get; set; }

The default font size to use with the DefaultFont.

C#
public IFont.Sizes DefaultFontSize { get; set; }

Global keyboard object used by SadConsole during the update frame.

C#
public Keyboard Keyboard { get; }

Global mouse object used by SadConsole during the update frame.

C#
public Mouse Mouse { get; }

The elapsed time between now and the last update call.

C#
public TimeSpan UpdateFrameDelta { get; set; }

The elapsed time between now and the last draw call.

C#
public TimeSpan DrawFrameDelta { get; set; }

The total time the game has been running.

C#
public TimeSpan GameRunningTotalTime { get; }

The console created by the game and automatically assigned to Screen.

C#
public Console? StartingConsole { get; protected set; }

The active screen processed by the game.

C#
public IScreenObject? Screen { get; set; }

Update components that run before the Screen is processed.

C#
public List<RootComponent> RootComponents { get; set; }

The stack of focused consoles used by the mouse and keyboard.

C#
public FocusedScreenObjectStack FocusedScreenObjects { get; set; }

A global random number generator.

C#
public Random Random { get; set; }

Raises the Started event.

C#
protected virtual void OnGameStarted()

Raises the Ending event.

C#
protected virtual void OnGameEnding()

Raises the FrameRender event.

C#
protected virtual void OnFrameRender()

Raises the FrameUpdate event.

C#
protected virtual void OnFrameUpdate()

Runs the game.

C#
public abstract void Run()

Gets a texture from the implemented host.

C#
public abstract ITexture GetTexture(string resourcePath)

resourcePath string
The path to the texture to load.

ITexture
The texture from the game host.

Gets a texture from the implemented host.

C#
public abstract ITexture GetTexture(Stream textureStream)

textureStream Stream
A stream containing the texture.

ITexture
The texture from the game host.

Creates a texture.

C#
public abstract ITexture CreateTexture(int width, int height)

width int
The width of the texture in pixels.

height int
The height of the texture in pixels.

ITexture
The texture from the game host.

Creates and returns an IRenderer by name.

C#
public virtual IRenderer? GetRenderer(string name)

name string
The name of the renderer.

IRenderer
A new renderer.

Sets the default IRenderer for a type.

C#
public void SetRenderer(string name, Type rendererType)

name string
The name to register the renderer as.

rendererType Type
The renderer type.

Sets the default IRenderStep for a type.

C#
public void SetRendererStep(string name, Type rendererStepType)

name string
The name to register the render step as.

rendererStepType Type
The render step type.

Creates and returns a IRenderStep by name.

C#
public virtual IRenderStep GetRendererStep(string name)

name string
The name of the renderer.

IRenderStep
A new renderer.

Gets the state of the keyboard from the implemented host.

C#
public abstract IKeyboardState GetKeyboardState()

IKeyboardState
The state of the keyboard.

Gets the state of the mouse from the implemented host.

C#
public abstract IMouseState GetMouseState()

IMouseState
The state of the mouse.

Gets the size of the current device’s screen in pixels.

C#
public abstract void GetDeviceScreenSize(out int width, out int height)

width int
The width of the screen.

height int
The height of the screen.

The splash screens the game should sequentially show on startup.

C#
public void SetSplashScreens(params IScreenSurface[] surfaces)

surfaces IScreenSurface[]
The splash screens to show.

Loads a font from a file and adds it to the Fonts collection.

C#
public IFont LoadFont(string font)

font string
The font file to load.

IFont
A master font that you can generate a usable font from.

Destroys the StartingConsole instance.

C#
public void DestroyDefaultStartingConsole()

Prior to calling this method, you must set Screen to an object other than StartingConsole.

Opens a file stream with the specified mode and access.

C#
public virtual Stream OpenStream(string file, FileMode mode = FileMode.Open, FileAccess access = FileAccess.Read)

file string
The file to open.

mode FileMode
The mode for opening. Defaults to Open.

access FileAccess
The type of access for the stream. Defaults to Read.

Stream
The stream object.

Checks if a file exists.

C#
public virtual bool FileExists(string file)

file string
The file to check.

bool
true if the file exists; otherwise false.

Deletes a file.

C#
public virtual bool FileDelete(string file)

file string
The file to delete.

bool
true if the file was deleted; otherwise false.

Loads the embedded IBM.font files. Sets the DefaultFont property.

C#
protected void LoadDefaultFonts(string? defaultFont)

defaultFont string
An optional font to load and set as the default.

If defaultFont is null, the EmbeddedFont or EmbeddedFontExtended font is set based on the value of UseDefaultExtendedFont.

Uses reflection to examine the SadRogue.Primitives.Color type and add any predefined colors into ColorMappings.

C#
protected static void LoadMappedColors()

Resizes the window to the specified dimensions.

C#
public abstract void ResizeWindow(int width, int height, bool resizeOutputSurface = false)

width int
The width of the window in pixels.

height int
The height of the window in pixels.

resizeOutputSurface bool
When true resizes the screen output surface along with the window. Defaults to false

Resizes the window to the specified cell count along the X-axis and Y-axis.

C#
public void ResizeWindow(int cellsX, int cellsY, Point cellSize, bool resizeOutputSurface = false)

cellsX int
The number of cells to fit horizontally.

cellsY int
The number of cells to fit vertically.

cellSize SadRogue.Primitives.Point
The size of the cells in pixels.

resizeOutputSurface bool
When true resizes the screen output surface along with the window. Defaults to false

Saves the global state, mainly the FocusedScreenObjects and Screen objects.

C#
public void SaveGlobalState()

Restores the global state that was saved with SaveGlobalState().

C#
public void RestoreGlobalState()
C#
protected virtual void Dispose(bool disposing)

disposing bool

Disposes this object.

C#
protected ~GameHost()

Disposes this object.

C#
public void Dispose()

Raised when the game draws a frame to the screen.

C#
public event EventHandler<GameHost>? FrameRender

EventHandler<GameHost>

Raised when the game updates prior to drawing a frame.

C#
public event EventHandler<GameHost>? FrameUpdate

EventHandler<GameHost>

A callback to run before the Run() method is called;

C#
public event EventHandler<GameHost>? Started

EventHandler<GameHost>

A callback to run after the Run() method is called;

C#
public event EventHandler<GameHost>? Ending

EventHandler<GameHost>