Sign in to follow this  
TRYCORP

Hopefully Easy Question

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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>

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Ah, ok, are thier any non-platform dependent event driven frameworks out thier? Something built in ANSI standard?

Share this post


Link to post
Share on other sites
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.

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