• Create Account

## In-Game Console

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

15 replies to this topic

154
Like
0Likes
Like

Posted 12 January 2013 - 11:41 AM

What are the consoles that we see in games made of? For example, Quake's console http://gregdolleysblog.files.wordpress.com/2008/01/image.png .

I've made one with AllocConsole, but that opens in a seperate window. I'm looking to make one that just takes up a portion of the screen when toggled on like we see in most games.

### #2Bacterius  Members

13102
Like
4Likes
Like

Posted 12 January 2013 - 11:43 AM

I would assume they render it themselves as if it were just another GUI element, and implement the command parser themselves (or using some existing tool).

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

154
Like
0Likes
Like

Posted 12 January 2013 - 11:55 AM

command parser

Well, that word helped loads. Searching "console" was not helpful at all with Google, but there are many more results for that. Thanks!

I think the way to do it would be to have 2 text boxes (CreateWindow), one read-only and one to type in. The read only would echo whatever goes into a log file and the write one would handle the commands.

Edited by Kurask, 12 January 2013 - 12:33 PM.

### #4FLeBlanc  Members

3133
Like
5Likes
Like

Posted 12 January 2013 - 12:03 PM

POPULAR

You might take a look at the GLConsole project. While it is OpenGL-specific, it should still be instrumental in understanding what goes into a console system.

### #5Karsten_  Members

2309
Like
3Likes
Like

Posted 12 January 2013 - 12:50 PM

For the console in a couple of my games, I simply display lines of a log (rather than using std::cout) so it can display on an Android device easily.

For writing commands, I simply send the message to all of my ingame objects in the hope that one of them intercepts the message and can react / respond to it.

But depending on what API / engine you are using, it really isn't too hard to implement bespoke rather than dragging in some other project and rigging it up.
http://tinyurl.com/shewonyay - Thanks so much for those who voted on my GF's Competition Cosplay Entry for Cosplayzine. She won! I owe you all beers

Mutiny - Open-source C++ Unity re-implementation.
Defile of Eden 2 - FreeBSD and OpenBSD binaries of our latest game.

154
Like
0Likes
Like

Posted 12 January 2013 - 01:16 PM

For the console in a couple of my games, I simply display lines of a log (rather than using std::cout) so it can display on an Android device easily.

For writing commands, I simply send the message to all of my ingame objects in the hope that one of them intercepts the message and can react / respond to it.

But depending on what API / engine you are using, it really isn't too hard to implement bespoke rather than dragging in some other project and rigging it up.

That's what I was thinking. I'd have my output go to some text file and have something constantly echo whatever is in that file onto the screen. I don't know the best way to do that though. My project is in C++ using DirectX for the  graphics. I was thinking I'd just make a textbox using CreateWindowEx that displayed all the output and I'd have another textbox slightly below that to handle the input. I'd have to figure out how to do that, but it sounds reasonable.

### #7Karsten_  Members

2309
Like
2Likes
Like

Posted 12 January 2013 - 01:38 PM

Rather than outputing to an intermediate file, why not add the messages to a std::vector?
Then just display the last 10 lines or so or delete the first one until the length is less than 10 messages.

Also, rather than using Windows GUI components to display the messages, perhaps just make the messages draw to the screen as basic bitmap fonts or something. Have a basic boolean to toggle when you press the '' key to specify if to draw the console or not every game loop.
http://tinyurl.com/shewonyay - Thanks so much for those who voted on my GF's Competition Cosplay Entry for Cosplayzine. She won! I owe you all beers

Mutiny - Open-source C++ Unity re-implementation.
Defile of Eden 2 - FreeBSD and OpenBSD binaries of our latest game.

### #8Llamaiyama  Members

133
Like
2Likes
Like

Posted 12 January 2013 - 01:39 PM

That's what I was thinking. I'd have my output go to some text file and have something constantly echo whatever is in that file onto the screen. I don't know the best way to do that though. My project is in C++ using DirectX for the  graphics. I was thinking I'd just make a textbox using CreateWindowEx that displayed all the output and I'd have another textbox slightly below that to handle the input. I'd have to figure out how to do that, but it sounds reasonable.

Using CreateWindowEx isn't going to make a console that's really usable in-game, unless you are running windowed mode. IIRC DirectX has some font rendering classes if you are using earlier versions. Check the SDK samples.

As for logging: echoing from a file is not the greatest idea. Buffers can take time to flush. You may not want to lock a file constantly while a program is running (and conversely lock it while reading).

There are a bunch of good logging frameworks out there (check this thread on stackoverflow) that let you have multiple backend emitters. I use Boost.Log (not officially part of boost) in my projects and it works great for that sort of thing.

### #9nife87  Members

520
Like
3Likes
Like

Posted 12 January 2013 - 01:45 PM

Most, and hereby I mean practically any game I have every played in release, use the in-game GUI to display the console, not an external window API like Windows' own.<br />Thereby they can toggle all aspects of its appearance - but there is much more to it than just pretty graphics, although ones like Source Engine's is both very pretty and functional (listing all cvars related to the chars you have typed so far and easy help/description for any cvars, for instance) IMHO, though I miss an "in-game appearance" (you cannot type while playing - console must be accessed from the menu).<br />You also need a way to bind console input (like "help", "max_fps 100", "quit", etc.) to actual source in order to command the game to do something.<br />Quake, as you mentioned, uses a system of cvars (console variables and commands) - you can read all about both online and in their released source (the newest edition of id's cvar system in actual source, that I know of, lies accessible in their Half Life 2 SDK).<br />Games like FarCry exposes this functionality via a full fledged scripting system (Lua, in this case) and binds commands/variables and the necessary callbacks this way, since they use it for all other scripting purposes anyways.<br />

### #10ic0de  Members

955
Like
2Likes
Like

Posted 12 January 2013 - 02:17 PM

Rather than outputing to an intermediate file, why not add the messages to a std::vector?
Then just display the last 10 lines or so or delete the first one until the length is less than 10 messages.

Also, rather than using Windows GUI components to display the messages, perhaps just make the messages draw to the screen as basic bitmap fonts or something. Have a basic boolean to toggle when you press the '' key to specify if to draw the console or not every game loop.

In my engine I do something similar to this, I have a console class which stores its most recent lines internally in an std::vector and also writes that information to a file. When I use my console::outf() function the line is written to a log and added to an std::vector and the console is then drawn from the std::vector. As for drawing my console it is simply another GUI element.

you know you program too much when you start ending sentences with semicolons;

154
Like
0Likes
Like

Posted 12 January 2013 - 03:05 PM

That's what I was thinking. I'd have my output go to some text file and have something constantly echo whatever is in that file onto the screen. I don't know the best way to do that though. My project is in C++ using DirectX for the  graphics. I was thinking I'd just make a textbox using CreateWindowEx that displayed all the output and I'd have another textbox slightly below that to handle the input. I'd have to figure out how to do that, but it sounds reasonable.

Using CreateWindowEx isn't going to make a console that's really usable in-game, unless you are running windowed mode. IIRC DirectX has some font rendering classes if you are using earlier versions. Check the SDK samples.

As for logging: echoing from a file is not the greatest idea. Buffers can take time to flush. You may not want to lock a file constantly while a program is running (and conversely lock it while reading).

There are a bunch of good logging frameworks out there (check this thread on stackoverflow) that let you have multiple backend emitters. I use Boost.Log (not officially part of boost) in my projects and it works great for that sort of thing.

Yeah, I can render text to the screen, I just wasn't sure if it was efficient to do so.

I don't know how I'd get started on binding input to the source, or even getting input to appear on the screen instead of using it to control the camera, as nife87 said above.

### #12clashie  Members

632
Like
3Likes
Like

Posted 13 January 2013 - 01:34 AM

The actual logic behind a console system isn't too hard to put together, I have a simple Cvar class which uses template specializations for the argument types I support (float, int, string, and nothing) so when you create a Cvar object, it sets an internal flag accordingly for the type you tried to give it so it knows how to act on it later. It uses a FastDelegate internally for the function pointer stuff.

Then I just dump them into a map<string, Cvar> for the lookup. The Console class has an exec() function which just takes a string -- if there's 2 parts to it (like "test 500") then I split that into to name and argument, use the name for the lookup, and 500 is converted and handled accordingly. It's not really robust, but it's really tiny and simple, I think the whole thing is like around 150 lines.

### #13M6dEEp  Members

904
Like
1Likes
Like

Posted 13 January 2013 - 05:01 AM

I don't know how I'd get started on binding input to the source, or even getting input to appear on the screen instead of using it to control the camera, as nife87 said above.

I just added my console as one of the states in my game's state management system. That way it intercepts all of the inputs from the user while it's up, and when you're done you just pop it right off the state stack and go back to the game. You can use your game's internal logging system as a backing store for the console output also, which makes implementing it a bit easier because now your console window is a very watered down input parser/command execution host and log viewer.

### #14Ectara  Members

3097
Like
1Likes
Like

Posted 13 January 2013 - 10:19 AM

(the newest edition of id's cvar system in actual source, that I know of, lies accessible in their Half Life 2 SDK)

You could, alternatively, read the source code of one of id's games, like Quake.

Edited by Ectara, 13 January 2013 - 10:52 AM.

### #15Llamaiyama  Members

133
Like
1Likes
Like

Posted 13 January 2013 - 11:53 AM

That's what I was thinking. I'd have my output go to some text file and have something constantly echo whatever is in that file onto the screen. I don't know the best way to do that though. My project is in C++ using DirectX for the  graphics. I was thinking I'd just make a textbox using CreateWindowEx that displayed all the output and I'd have another textbox slightly below that to handle the input. I'd have to figure out how to do that, but it sounds reasonable.

Using CreateWindowEx isn't going to make a console that's really usable in-game, unless you are running windowed mode. IIRC DirectX has some font rendering classes if you are using earlier versions. Check the SDK samples.

As for logging: echoing from a file is not the greatest idea. Buffers can take time to flush. You may not want to lock a file constantly while a program is running (and conversely lock it while reading).

There are a bunch of good logging frameworks out there (check this thread on stackoverflow) that let you have multiple backend emitters. I use Boost.Log (not officially part of boost) in my projects and it works great for that sort of thing.

Yeah, I can render text to the screen, I just wasn't sure if it was efficient to do so.

I don't know how I'd get started on binding input to the source, or even getting input to appear on the screen instead of using it to control the camera, as nife87 said above.

This depends on how you're handling input. If you are directly testing for input in functions to move camera and such you'll need to check if the console is open or not when making those calculations.

Rendering text to the screen, like pretty much everything else in programming, can be efficient or not depending on how it's done. Earlier versions of D3D have ID3DXFont which may simplify this. Newer versions don't come with D3DX, so you'll either need to write your own font renderer, use someone else's, or use DirectWrite.

154
Like
0Likes
Like

Posted 14 January 2013 - 09:53 PM

Thanks for the suggestions; I ended up getting everything working. I was looking for functions that handled it altogether in case one existed. As stated earlier, the code to make one was pretty simple (I imagined it being a little more difficult than it turned out to be).

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.