SadConsole game host overview
A SadConsole host is the graphics engine that draws to the screen, processes input, and handles the game logic-loop. SadConsole doesn’t draw or handle input natively. It’s a generic library that relies on a “host” to provide the rendering engine and input processing.
SadConsole supports three game hosts: MonoGame, SFML, and FNA.
MonoGame
Section titled “MonoGame”The MonoGame host is NuGet package SadConsole.Host.MonoGame.
MonoGame is a community-driven game engine that supports 2D and 3D. The main SadConsole library only describes objects rendered in 2D; however, you can still use MonoGame’s 3D capabilities. MonoGame has the following features:
- 3D and 2D rendering capabilities.
- Cross-platform support for other operating systems.
- Built for .NET.
- Large community of users.
The SFML host is NuGet package SadConsole.Host.SFML.
SFML is a C engine built for 2D games. SFML has bindings for multiple languages, including .NET languages. SFML does work cross-platform, but requires significant effort to configure for other operating systems. SadConsole with SFML is currently built for Windows.
The host interface
Section titled “The host interface”SadConsole is designed to be unaware of the host rendering engine. The SadConsole.GameHost base class defines common functionality for all host renderers. A host might provide specific capabilities and types, but you generally don’t need them unless you want to do something specific with the host renderer, like using MonoGame’s 3D capabilities.
After starting a game, access the host through the GameHost.Instance property.
Input processing
Section titled “Input processing”SadConsole performs many operations during the update frame, including input processing. The input processor handles keyboard and mouse state. Mouse-related input events are continually processed on the object under the mouse cursor, but keyboard input works differently. Only the currently focused object receives keyboard input. The GameHost.FocusedScreenObjects property designates the focused object.
Mouse input scans the GameHost.Screen object hierarchy and determines which object is under the mouse. That object’s ProcessMouse(MouseScreenObjectState) method is called. This method checks the UseMouse property, and if it’s true, the object handles the mouse. When the object processes the mouse, it raises the following input events:
Keyboard
Section titled “Keyboard”Keyboard input is always sent to the “focused” object. An object is considered focused when its IsFocused property is set to true and it’s the top-most object in the GameHost.FocusedScreenObjects collection. When focused, SadConsole calls the object’s ProcessKeyboard(Keyboard) method every update frame. If the object’s UseKeyboard property is true, the keyboard input is processed.