Sign in to follow this  
RobAU78

Game Loops and Synchronous Input

Recommended Posts

Hey everyone, So lately I've been looking into lower-level game programming (meaning the Win32 API, C/C++, etc.). Up to this point, I've done all of my game programming in either Java or C#. Anyways, I'm having a bit of trouble with gathering player input in the same thread as updating the game world and rendering it to the screen. Since I/O is rather asynchronous, some kind of timeout seems necessary (all other things being equal). On the other hand, maybe I/O is handled in (what amounts to) a separate thread even on the OS level, through interrupts and the like. Can any of you help me out here? I apologize if the above is confusing -- just looking for some clarification. Thanks!

Share this post


Link to post
Share on other sites
Assuming you're working in Win32 with C++ - the OS actually queues up input data for you. When you want to obtain user input, you pull a list of the input events that have occurred since the last time you read the input queue. You then respond to all of the input in the queue, and go about doing the game simulation update and graphics rendering.

Typically nowadays this is done via WM_INPUT which you can handle from your window's message procedure.

Share this post


Link to post
Share on other sites
Thanks for your reply! Sounds like my suspicion has been confirmed -- the OS does most of the heavy lifting. I can only imagine how it must have been when that was not true, and you had to write your own interrupt routines for capturing player input... :P

One question: is using WM_INPUT faster (or otherwise more advantageous) than using e.g. WM_KEYUP and WM_KEYDOWN?

Share this post


Link to post
Share on other sites
Using raw input (via WM_INPUT) is much more powerful and flexible than the alternatives. You'll get access to more devices than just the keyboard and mouse, and better information about what exactly is going on. (For example, WM_KEYUP doesn't work as you might expect if the player holds down the Alt key.)

Share this post


Link to post
Share on other sites
To be honest, I don't see myself making any games for a while that would not rely solely on the standard input devices -- i.e., keyboard and mouse. Do you think that reading WM_KEY* and WM_MOUSE* messages would be sufficient for what I want to do?

Share this post


Link to post
Share on other sites
Sufficient yes. A good idea, no. WM_INPUT was created to help make input processing simpler, and if you ignore that opportunity, you're in for a lot of really annoying bugs and "quirks" in your input code.

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