Archived

This topic is now archived and is closed to further replies.

CyberSlag5k

How to prevent input from halting program

Recommended Posts

CyberSlag5k    514
I am thinking about starting a text based game project (a SUD, essentially) using C++ and in going through the general setup in my head, I realized I''m not entirely sure how to do the input. The game engine would essentially loop constantly, updating things such as creature positions, round times, and the like. However, the player needs to be able to input their actions at any given time. Obviously a cin statement would not work because doing so would effectively halt the entire program until the user entered some action. Such a reactive system would be, to be quite frank, boring (and in my oppinion a very poor game engine). So, the much anticipated question is...what is the standard convention for allowing input without halting the system (essentially an in-game console), using C++. Thanks, Mike (On a side note, if anyone who has worked on any similar project would like to share any tips or warn me of the common traps, I would appreciate your input) --Sometimes the hardest thing to do is nothing

Share this post


Link to post
Share on other sites
Chozo    176
The ways I know of are unbuffered input (google), which I''m not sure, but may make backspace/delete handling tough, and multi-threading (input is in its own thread). The biggest problem is going to be handling output without disrupting input, which I have no idea how to approach in an elegant manner.

Once you get the input, you just parse it out into tokens that correspond to nouns, verbs, etc.

Share this post


Link to post
Share on other sites
Kylotan    10008
Think about how graphical games do it: they check for pressed keys many times a second. This is what you should do, also. When you see a key being pressed, you add it to a buffer. When the key pressed is the Enter key, process your buffer as a command and clear it. Repeat ad infinitum.

[ MSVC Fixes | STL Docs | SDL | Game AI | Sockets | C++ Faq Lite | Boost
Asking Questions | Organising code files | My stuff | Tiny XML | STLPort]

Share this post


Link to post
Share on other sites
wizard341    144
Sounds like (if you dont already know about windows api programming) you should learn it. Getting keystrokes from windows will be trivial, and you can make your game work in a nice little window. Plus if you want to add basic shapes or sounds its as easy as PlaySound(...) or the drawrect functions where you must only specify 2 points to draw.

Share this post


Link to post
Share on other sites