Sign in to follow this  
ak-73

In-Game Console

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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:


// Settings
set int screen_width 1024
set int screen_height 768
set bool fullscreen false
// etc...

// Game settings
set float gravity 9.8
set 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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this