Jump to content
  • Advertisement
Sign in to follow this  
TRYCORP

Hopefully Easy Question

This topic is 4462 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
Its just a case of doing it all at once, in my experience.

User Input
Phyics
AI
Render

Dave

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!