The Console Window System¶
What is it¶
The Console Window System is a system written for the Tempest Engine to allow the user to enter commands that can control the state of the game. It is implemented internally using the new Canvas System.
How it works¶
Rendering¶
As mentioned, the Console Window System uses the new Canvas System internally. It uses the Canvas System to render a floating window on top of the 3D game world. When the level loads, the Console Window System will create a custom Space where it stores the various game objects used for rendering the window itself.
The first game object created is the Console Window
object, which is the
master object used for positioning the window itself. It also acts as the
background of the console window, providing a backdrop for text to be rendered
against.
The second game object, the Console Window Buffer Field
, is created as a child
of the Console Window
object. This object is used to render all text of the
Console Window’s buffer, which includes the history of inputted commands as well
as output from both previous commands and the logging system of the engine.
The final game object that gets created, the Console Window Input Field
, is
also created as a child of the Console Window
object. Similarly to the
Console Window Buffer Field
object, this object is also just used to render
text. However, this object is used to render the current input buffer of the
Console Window rather than the the Console Window’s output history.
Input¶
Being a Console Window, input is expected while it is running so that commands can be given to the rest of the engine. The way this works is that every update tick the system checks if the console window is currently active and visible to the user. If it is, then all user input processing is disabled, and a function is registered to have all input passed to the Console Window System for processing. While there, any key that is not a backtick (`) or the escape key will modify the current user input in some way, one character at a time. A backspace character will delete the last character in the input, while any sort of enter or carriage return will attempt to execute whatever is currently in the input buffer as a command. Backtick and escape will close the console window, returning back to normal gameplay.
Commands¶
When a command is executed, the input buffer is split by spaces into a vector of
words. The first word is treated as the command to execute, and the rest are
treated as arguments to that command. What is interesting about the Console
Window System is that it doesn’t actually execute the commands itself. Instead,
the command name and these arguments are packaged up and fired as an event into
the Event System. What this means is that in order to define
an event, all one has to do is handle a CommandEvent
and process the command
and its arguments. This allows any system to be able to define new commands at
any point in the development process, without needing to ever touch or look at
the internals of the Console Window System.