Hopefully Easy Question

Started by
6 comments, last by Lazy Foo 17 years, 11 months ago
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?
Lesson Number 4:"Blades don't need reloading."-- The Zombie Survival Guide
Advertisement
Its just a case of doing it all at once, in my experience.

User Input
Phyics
AI
Render

Dave
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>

Learn to make games with my SDL 2 Tutorials

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.
Ah, ok, are thier any non-platform dependent event driven frameworks out thier? Something built in ANSI standard?
Lesson Number 4:"Blades don't need reloading."-- The Zombie Survival Guide
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.
Lesson Number 4:"Blades don't need reloading."-- The Zombie Survival Guide
Yes, there is. Try GLUT.
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

Learn to make games with my SDL 2 Tutorials

This topic is closed to new replies.

Advertisement