Hopefully Easy Question
I'm not new to programming, but I am new to game programming. I know Java, C, and C++. I've done simulation and analysis, application, and some other various random items, (ex: Web Crawler), but I have never had to deal with a user inputing commands while something is running save one instance and I used threads.
So, onto my question. Exactely how does one interupt all the updating and rendering etc that goes on in a main game loop with user commands. For example in tetris, with blocks moving down, and frames redrawing, etc. How do you take in the user's input without stopping the process? Do you have to use multiple threads or is there a simpler way I am unaware of?
Quote:Original post by TRYCORP
So, onto my question. Exactely how does one interupt all the updating and rendering etc that goes on in a main game loop with user commands. For example in tetris, with blocks moving down, and frames redrawing, etc. How do you take in the user's input without stopping the process? Do you have to use multiple threads or is there a simpler way I am unaware of?
It's called event driven programming.
basically loop like this
while(true)
{
handle events
do calculations
render
}
in the case of tetris
while(true)
{
check for button presses and deal with them accordingly
move pieces/check for rows/etc
show blocks
}
I have plenty of small examples on my site</incredibly shameless plug>
usualy you have some event driven framework (such as win32, or SDL) and your game loop "peeks" for messages. If no messages are available it loops "update" and "render".
If input message is there it handles input (either update then or flags some booleans for next loop "update"
note: both "update" and "render" use a timer (clock) to know how much time passed from previous loop to move things smoothly.
Iftah.
If input message is there it handles input (either update then or flags some booleans for next loop "update"
note: both "update" and "render" use a timer (clock) to know how much time passed from previous loop to move things smoothly.
Iftah.
Ah, ok, are thier any non-platform dependent event driven frameworks out thier? Something built in ANSI standard?
I should have visited your website before asking that question Lazy. Right there on the main page...
"SDL is used as the API because it is cross platform, and relatively easy to use."
Thanks guys.
"SDL is used as the API because it is cross platform, and relatively easy to use."
Thanks guys.
Quote:Original post by TRYCORP
Ah, ok, are thier any non-platform dependent event driven frameworks out thier?
I recommend SDL.
See sig.
See SDL website.
Also see Alternative libraries FAQ
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement