GameHost Class
Definition
Section titled “Definition”Represents the SadConsole game engine.
public abstract class GameHost : IDisposableInheritance object
Implements IDisposable
Remarks
Section titled “Remarks”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().
Constructors
Section titled “Constructors”GameHost()
Section titled “GameHost()”protected GameHost()Fields
Section titled “Fields”_renderers
Section titled “_renderers”Holds all of the IRenderer types.
protected Dictionary<string, Type> _renderers_rendererSteps
Section titled “_rendererSteps”Holds all of the IRenderStep types.
protected Dictionary<string, Type> _rendererSteps_gameStartedAt
Section titled “_gameStartedAt”The date and time the game was started.
protected DateTime _gameStartedAtProperties
Section titled “Properties”_splashScreens
Section titled “_splashScreens”The splash screens to show on game startup.
protected Queue<IScreenSurface>? _splashScreens { get; set; }Instance
Section titled “Instance”Instance of the game host.
public static GameHost Instance { get; protected set; }SerializerPathHint
Section titled “SerializerPathHint”Contains the path to a file being serialized or deserialized.
public static string SerializerPathHint { get; }DrawCalls
Section titled “DrawCalls”Draw calls registered for the next drawing frame.
public Queue<IDrawCall> DrawCalls { get; }ScreenCellsX
Section titled “ScreenCellsX”How many cells fit in the render area width used by SadConsole.
public int ScreenCellsX { get; }ScreenCellsY
Section titled “ScreenCellsY”How many cells fit in the render area width used by SadConsole.
public int ScreenCellsY { get; }FrameNumber
Section titled “FrameNumber”A frame number counter, incremented every game frame.
public int FrameNumber { get; set; }Collection of fonts. Used mainly by the deserialization system.
public Dictionary<string, IFont> Fonts { get; }EmbeddedFont
Section titled “EmbeddedFont”The font automatically loaded by SadConsole. Standard IBM style font.
public SadFont EmbeddedFont { get; }EmbeddedFontExtended
Section titled “EmbeddedFontExtended”The font automatically loaded by SadConsole. Standard IBM style font. Extended with extra SadConsole characters.
public SadFont EmbeddedFontExtended { get; }DefaultFont
Section titled “DefaultFont”The default font for any type that does not provide a font.
public IFont DefaultFont { get; set; }DefaultFontSize
Section titled “DefaultFontSize”The default font size to use with the DefaultFont.
public IFont.Sizes DefaultFontSize { get; set; }Keyboard
Section titled “Keyboard”Global keyboard object used by SadConsole during the update frame.
public Keyboard Keyboard { get; }Global mouse object used by SadConsole during the update frame.
public Mouse Mouse { get; }UpdateFrameDelta
Section titled “UpdateFrameDelta”The elapsed time between now and the last update call.
public TimeSpan UpdateFrameDelta { get; set; }DrawFrameDelta
Section titled “DrawFrameDelta”The elapsed time between now and the last draw call.
public TimeSpan DrawFrameDelta { get; set; }GameRunningTotalTime
Section titled “GameRunningTotalTime”The total time the game has been running.
public TimeSpan GameRunningTotalTime { get; }StartingConsole
Section titled “StartingConsole”The console created by the game and automatically assigned to Screen.
public Console? StartingConsole { get; protected set; }Screen
Section titled “Screen”The active screen processed by the game.
public IScreenObject? Screen { get; set; }RootComponents
Section titled “RootComponents”Update components that run before the Screen is processed.
public List<RootComponent> RootComponents { get; set; }FocusedScreenObjects
Section titled “FocusedScreenObjects”The stack of focused consoles used by the mouse and keyboard.
public FocusedScreenObjectStack FocusedScreenObjects { get; set; }Random
Section titled “Random”A global random number generator.
public Random Random { get; set; }Methods
Section titled “Methods”OnGameStarted()
Section titled “OnGameStarted()”Raises the Started event.
protected virtual void OnGameStarted()OnGameEnding()
Section titled “OnGameEnding()”Raises the Ending event.
protected virtual void OnGameEnding()OnFrameRender()
Section titled “OnFrameRender()”Raises the FrameRender event.
protected virtual void OnFrameRender()OnFrameUpdate()
Section titled “OnFrameUpdate()”Raises the FrameUpdate event.
protected virtual void OnFrameUpdate()Runs the game.
public abstract void Run()GetTexture(string)
Section titled “GetTexture(string)”Gets a texture from the implemented host.
public abstract ITexture GetTexture(string resourcePath)Parameters
Section titled “Parameters”resourcePath string
The path to the texture to load.
Returns
Section titled “Returns”ITexture
The texture from the game host.
GetTexture(Stream)
Section titled “GetTexture(Stream)”Gets a texture from the implemented host.
public abstract ITexture GetTexture(Stream textureStream)Parameters
Section titled “Parameters”textureStream Stream
A stream containing the texture.
Returns
Section titled “Returns”ITexture
The texture from the game host.
CreateTexture(int, int)
Section titled “CreateTexture(int, int)”Creates a texture.
public abstract ITexture CreateTexture(int width, int height)Parameters
Section titled “Parameters”width int
The width of the texture in pixels.
height int
The height of the texture in pixels.
Returns
Section titled “Returns”ITexture
The texture from the game host.
GetRenderer(string)
Section titled “GetRenderer(string)”Creates and returns an IRenderer by name.
public virtual IRenderer? GetRenderer(string name)Parameters
Section titled “Parameters”name string
The name of the renderer.
Returns
Section titled “Returns”IRenderer
A new renderer.
SetRenderer(string, Type)
Section titled “SetRenderer(string, Type)”Sets the default IRenderer for a type.
public void SetRenderer(string name, Type rendererType)Parameters
Section titled “Parameters”name string
The name to register the renderer as.
rendererType Type
The renderer type.
SetRendererStep(string, Type)
Section titled “SetRendererStep(string, Type)”Sets the default IRenderStep for a type.
public void SetRendererStep(string name, Type rendererStepType)Parameters
Section titled “Parameters”name string
The name to register the render step as.
rendererStepType Type
The render step type.
GetRendererStep(string)
Section titled “GetRendererStep(string)”Creates and returns a IRenderStep by name.
public virtual IRenderStep GetRendererStep(string name)Parameters
Section titled “Parameters”name string
The name of the renderer.
Returns
Section titled “Returns”IRenderStep
A new renderer.
GetKeyboardState()
Section titled “GetKeyboardState()”Gets the state of the keyboard from the implemented host.
public abstract IKeyboardState GetKeyboardState()Returns
Section titled “Returns”IKeyboardState
The state of the keyboard.
GetMouseState()
Section titled “GetMouseState()”Gets the state of the mouse from the implemented host.
public abstract IMouseState GetMouseState()Returns
Section titled “Returns”IMouseState
The state of the mouse.
GetDeviceScreenSize(out int, out int)
Section titled “GetDeviceScreenSize(out int, out int)”Gets the size of the current device’s screen in pixels.
public abstract void GetDeviceScreenSize(out int width, out int height)Parameters
Section titled “Parameters”width int
The width of the screen.
height int
The height of the screen.
SetSplashScreens(params IScreenSurface[])
Section titled “SetSplashScreens(params IScreenSurface[])”The splash screens the game should sequentially show on startup.
public void SetSplashScreens(params IScreenSurface[] surfaces)Parameters
Section titled “Parameters”surfaces IScreenSurface[]
The splash screens to show.
LoadFont(string)
Section titled “LoadFont(string)”Loads a font from a file and adds it to the Fonts collection.
public IFont LoadFont(string font)Parameters
Section titled “Parameters”font string
The font file to load.
Returns
Section titled “Returns”IFont
A master font that you can generate a usable font from.
DestroyDefaultStartingConsole()
Section titled “DestroyDefaultStartingConsole()”Destroys the StartingConsole instance.
public void DestroyDefaultStartingConsole()Remarks
Section titled “Remarks”Prior to calling this method, you must set Screen to an object other than StartingConsole.
OpenStream(string, FileMode, FileAccess)
Section titled “OpenStream(string, FileMode, FileAccess)”Opens a file stream with the specified mode and access.
public virtual Stream OpenStream(string file, FileMode mode = FileMode.Open, FileAccess access = FileAccess.Read)Parameters
Section titled “Parameters”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.
Returns
Section titled “Returns”Stream
The stream object.
FileExists(string)
Section titled “FileExists(string)”Checks if a file exists.
public virtual bool FileExists(string file)Parameters
Section titled “Parameters”file string
The file to check.
Returns
Section titled “Returns”bool
true if the file exists; otherwise false.
FileDelete(string)
Section titled “FileDelete(string)”Deletes a file.
public virtual bool FileDelete(string file)Parameters
Section titled “Parameters”file string
The file to delete.
Returns
Section titled “Returns”bool
true if the file was deleted; otherwise false.
LoadDefaultFonts(string?)
Section titled “LoadDefaultFonts(string?)”Loads the embedded IBM.font files. Sets the DefaultFont property.
protected void LoadDefaultFonts(string? defaultFont)Parameters
Section titled “Parameters”defaultFont string
An optional font to load and set as the default.
Remarks
Section titled “Remarks”If defaultFont is null, the EmbeddedFont or EmbeddedFontExtended font is set based on the value of UseDefaultExtendedFont.
LoadMappedColors()
Section titled “LoadMappedColors()”Uses reflection to examine the SadRogue.Primitives.Color type and add any predefined colors into ColorMappings.
protected static void LoadMappedColors()ResizeWindow(int, int, bool)
Section titled “ResizeWindow(int, int, bool)”Resizes the window to the specified dimensions.
public abstract void ResizeWindow(int width, int height, bool resizeOutputSurface = false)Parameters
Section titled “Parameters”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
ResizeWindow(int, int, Point, bool)
Section titled “ResizeWindow(int, int, Point, bool)”Resizes the window to the specified cell count along the X-axis and Y-axis.
public void ResizeWindow(int cellsX, int cellsY, Point cellSize, bool resizeOutputSurface = false)Parameters
Section titled “Parameters”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
SaveGlobalState()
Section titled “SaveGlobalState()”Saves the global state, mainly the FocusedScreenObjects and Screen objects.
public void SaveGlobalState()RestoreGlobalState()
Section titled “RestoreGlobalState()”Restores the global state that was saved with SaveGlobalState().
public void RestoreGlobalState()Dispose(bool)
Section titled “Dispose(bool)”protected virtual void Dispose(bool disposing)Parameters
Section titled “Parameters”disposing bool
~GameHost()
Section titled “~GameHost()”Disposes this object.
protected ~GameHost()Dispose()
Section titled “Dispose()”Disposes this object.
public void Dispose()Events
Section titled “Events”FrameRender
Section titled “FrameRender”Raised when the game draws a frame to the screen.
public event EventHandler<GameHost>? FrameRenderEvent Type
Section titled “Event Type”FrameUpdate
Section titled “FrameUpdate”Raised when the game updates prior to drawing a frame.
public event EventHandler<GameHost>? FrameUpdateEvent Type
Section titled “Event Type”Started
Section titled “Started”A callback to run before the Run() method is called;
public event EventHandler<GameHost>? StartedEvent Type
Section titled “Event Type”Ending
Section titled “Ending”A callback to run after the Run() method is called;
public event EventHandler<GameHost>? Ending