Archived

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

Ancalagon the Black

I am probably really stupid, but...

Recommended Posts

If I have read the windows programming tutorials aright, you must call your message handling function every iteration of the main loop. Does this mean that it is impossible to pause for input while the program is running? Does this mean that if in my main loop I want the player to stop and enter some data, I couldn''t simply do a loop within the main loop until all data was entered? Is there a way to run two parallel loops, one for the windows stuff and the other being my main game loop? I am just beginning programming games in windows, and while that is no excuse for asking a stupid question, I really can''t find the answer for this one.

Share this post


Link to post
Share on other sites
You can pause at any time..if the pause is in your main loop, then your main loop will be suspended until the function returns..the windows message handler is just one stop along the way, it won''t automatically keep checking itself, you have to make the call to check the messages..

You can create multiple threads in windows, but it doesn''t sound like that''s what you''re looking for..

"Like all good things, it starts with a monkey.."

Share this post


Link to post
Share on other sites
Well, it''s kind of a matter of how Windows works, really.

You see, Windows interprets basically everything as a message that gets queued up until the appropriate app picks it up and interprets it. This includes every little pixel your mouse moves, every keystroke, things the apps are doing, timer events, refresh messages... all of that. It''s important to realize in this that your main loop is being looped through hundreds if not thousands of times each second. It''s really darn fast... or at least "fast enough".

So, when a user presses a key in a Win32 app, a WM_KEYDOWN message is tossed onto the queue. You didn''t pause for user input, it just got queued up for you to find and respond to later. Alternately, if you''re going the route where you check to see if certain keys are currently being held down, every loop you''re checking the virtual key state, and responding accordingly in your main loop, which, remember, is being looped through many times a second. You can''t really do a "cin" style input, but why would you want to? You''re picking up every key as the user hits it.

Now, if you''re familiar with MFC programming, it looks event-driven, but it really isn''t. You just didn''t have to write the loop that''s processing the message queue... they did it for you. You don''t have to use their loop if you don''t want to.

So basically, you can do everything, input, drawing, etc, in your own loop. It shouldn''t be necessary to do multiple loops... in fact you wouldn''t want to thread parallel loops for input and output, because it would make it harder for you. Properly communicating between threads can be a beast.

-fel

Share this post


Link to post
Share on other sites
While it is theoretically possible to stop event handling while the user types in something, you should not do this. The whole point about windows programming is, that the computer does not belong to one application and has to share processor time and memory.
If you catch user input via windows messages you can easily keep track of what the user types in.
You would have to switch in the message handling routine if you are in normal user interface mode or if he types in something special.
Hope you get the idea somehow! *g*

Share this post


Link to post
Share on other sites
Thanks for all you help guys. Let me see if I got this straight. You can pause within you main loop, but it will cause a huge backlog of messages. For example instead of doing this:

  
while(1) // main loop

{
for(i = 1,i<10,i++)
{
string[i] = getchar();
}

handle_msgs();

}


you should do this:

  
while(1) // main loop

{
string[i] = the last key pressed;
i++;

handle_msgs();

}


Do I have the basic idea? I know that code was very crude, but it gives you and idea of my thought processes.


Share this post


Link to post
Share on other sites