Your wish, my command (console)

A couple of weeks ago, when I was working on a secret project of mine , the following situation occurred:

Each level in the game is composed of several sections. Some of them are interactive, requiring the player to do something (like traversing a path or killing enemies). Cut-scenes are played in-between those sections, triggered by some event happening in the game world (for example, when the player reaches a predefined point in the map).

As you might have guessed, it’s very frustrating to play entire sections of the level just to reach the last cut-scene and realizing that some actors were misplaced. Despite the fact that everything is based on Lua scripts and that reloading them is very fast, we still need to replay at least a couple of sections just to verify that our changes worked. It would be great to have a tool to trigger those animations and any other events as soon as the level loads, right?

Of course.

And what better tool for such a situation than an interactive console?… Actually, a scene editor would be much better. Maybe one embedding a script editor. Oh, oh! Visual scripting will be great too… and also… Ok, fine, it’s not the best solution, but bear with me.

Anyway, the interactive console is very simple to use. You press the tile (~) character in your keyboard and a prompt appears waiting for you to input commands. Yes, it’s pretty similar to UNIX terminals and it even has a command history and scrollable text, although there is no support for autocompletion at the moment.

Implementing new commands is as simple as registering a name and a callback that will be triggered whenever the user inputs such text into the prompt. For example:

Console::getInstance()->registerCommand( crimild::alloc< SimpleConsoleCommand>( "foo", []( Console *console, ConsoleCommand::ConsoleCommandArgs const &args ) {
   console->printLine( "Bar" );
}));

Here is the console in action:

Screen Shot 2017-05-10 at 1.09.08 AM

Probably the most useful command at the moment is the set one, which lets you change settings values while the game is running. For example, you can enable the profiler change the value of the profiler.enable variable like this:

set profiler.enabled=1

Screen Shot 2017-05-10 at 1.12.06 AM.png

The best part is that the console is already included into the Simulation framework and will be available as part of the next release (any time now). The only requirements is that you, the application developer, are responsible for providing a System Font to be used during the rendering phase. The same is true for the Profiler, btw.

See you next time!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s