In-Game Console

Started by
6 comments, last by c_olin 14 years, 9 months ago
Hi! My game development has progressed to the point where I am going to try to implement an in-game console some time soon. If you have any pointers, references, hints or general advice on how to implement it as *smoothly* and as *quickly* (there's still so much to do...) as possible to share, I'd be grateful. Thanks, Alex
Advertisement
There was a thread in this forum recently on in-game consoles; it was more about what features should be included than about how to implement it, but you might look for it anyway (I don't remember for sure, but it might have had some code samples and/or links to references in it).

There was also a tutorial titled something like 'Creating an In-Game Console Using the STL' floating around the internet at one point - you might be able to find it as well (it might even be here on GDNet somewhere).

It's fairly common to implement a console in terms of a command-line parser, and some sort of dispatch mechanism for the individual commands that you want to support. I don't know what language you're using, but it's fairly common to use callbacks or delegates of some sort for the 'command dispatch' part.
For getting a console up and running quickly, I find it hard to beat using boost::python to embed Python and using a class derived from code.InteractiveConsole object to implement the actual REPL logic. In most cases you just need to override the write() method to get output dumped to the right place and then whatever method you use for input calls push() to send the individual lines to the interpreter. However, if you aren't familiar with Python and boost::python, this might take longer than it does for me. YMMV.
Flipcode.org has some articles about that, I used Console Variables And Commands once as a basis for my console but there are also other articles about it on the site.
You might be interested in these video tutorials:
http://www.marek-knows.com/downloadSection.php?Topic=GameDev&pg=6#GameDev102



Thanks,

I'll have an in-depth look at it next time around. :-)

Maybe I'll have to create my own console widget then - probably based on the DXUT widgets... btw... I may use those in my own non-commercial demos, right?

Alex
In my project, I have a developer console, it's not ingame yet (only thing missing is the gui drawing, which I'm working at already),
but it can be used from a win32 dialog and is capable of all the important stuff like autocompletion, etc.
it handles both variables and commands. you can check out the code in the svn if you like:
SVN ViewVC
(cmdsystem & cvarsystem contain the most code for it)
This is copy and pasted from my reply to this thread which may be useful to you. It is more along the lines of containing console variables, but it might be relevant.

I wrote a similar console-like system for containing game settings. It had a map of strings to boost::any's and could interpret commands such as:

// Settingsset int screen_width 1024set int screen_height 768set bool fullscreen false// etc...// Game settingsset float gravity 9.8set int difficulty 5// etc...


In the actual code the variables are fetch like:

void window::update_cvars() {    try {        int screen_width = console->get_cvar<int>("screen_width");        int screen_height = console->get_cvar<int>("screen_height");    } catch (cvar_error& e) {        throw fatal_error("failed to get critical cvar: "+e.what());    }}


The only real downside is that if a cvar is changed in realtime, the update_cvars() functions for all objects that access cvars must be called. To cope with this the console contains a list of cvar_accessors and if a cvar is changed since the last frame, then all cvar_accessors' function update_cvars is called.

The system is a little clunky, but I think it will evolve into something more elegant as my game is being developed.

This topic is closed to new replies.

Advertisement