Simple game loop question
I'm new to game progaming and this is what I got, a game loop first checks for any button being pressed then updates some variable then updates the screen. So my question is while the loop is updating the screen (which takes a while) and I press some button how the heck is it everything gonna work out? I heard something about changing interupt. And what is a Keyboard buffer? Can a processor process more than one thing at once?
I forget the game is gonna be in Dos.
_______________
Tiso haio blamo
Edited by - Tiso on 8/8/00 4:45:56 PM
Updateing the Screen does not take that long. At a good 60fps, I dont think someone going to press a key for less than 1/60th of a second. And if they do, Like for typing, then you use Buffered input, which takes any key the user presses, saves it in a buffer, then when you check for input, it gives you all those keys. The OS is Multi-Tasking, the processor can not do more than one thing at a time.
I hope that made some sence later,
Edited by - Esap1 on August 8, 2000 5:52:53 PM
I hope that made some sence later,
Edited by - Esap1 on August 8, 2000 5:52:53 PM
Interrupts are an annoying relic of the DOS age. They''re still there, of course, and vital to device drivers and the OS, but generally something you don''t need to (and should never) touch under Windows. It''s amazingly easy to really f-up a computer when playing with interrupts, and except for creating a timer under DOS you don''t need to worry about them.
The computer buffers all input automatically, so you never have to worry about losing keystrokes during a screen refresh or game logic loop. Considering the fact that no human fingers can push a key for (1/30) of a second (assuming 30fps), you can safely assuming that you are receiving all keystrokes in your input function.
The processor can only process one instruction at a time. Under Windows, you know that you are always multi-tasking and so the processor is constantly switching between applications which each get a tiny slice of time to run. But even in DOS you never have the processor for 100% of the time, because of interrupts. (Interrupts are chunks of code that are executed when something happens, like the timer ticking or a key being pressed.) When an interrupt is triggered, your program stops running while the interrupt runs, and when the interrupt finished control is given back to your program.
-RWarden (roberte@maui.net)
The computer buffers all input automatically, so you never have to worry about losing keystrokes during a screen refresh or game logic loop. Considering the fact that no human fingers can push a key for (1/30) of a second (assuming 30fps), you can safely assuming that you are receiving all keystrokes in your input function.
The processor can only process one instruction at a time. Under Windows, you know that you are always multi-tasking and so the processor is constantly switching between applications which each get a tiny slice of time to run. But even in DOS you never have the processor for 100% of the time, because of interrupts. (Interrupts are chunks of code that are executed when something happens, like the timer ticking or a key being pressed.) When an interrupt is triggered, your program stops running while the interrupt runs, and when the interrupt finished control is given back to your program.
-RWarden (roberte@maui.net)
well like Esap was saying I real doubt that the user is going to be pressing keys that fast... chances are that there going to be pressing the key and its going to be down for lets say... 10 frames minume... so chances are your not going to lose the key...
I''m a summing your using c/c++
kbhit() might be _kbhit() depending on your compiler... kb hit checks to see if there is a key waiting....
if there is one grab it with getch()... for extened keys(like the arrow keys) it will return 0 so if it is 0 then do a getch again to get the scan code... else return the key....
Great Milenko
I''m a summing your using c/c++
if(kbhit()){ int key=getch(); if(key) return key; else return getch();}
kbhit() might be _kbhit() depending on your compiler... kb hit checks to see if there is a key waiting....
if there is one grab it with getch()... for extened keys(like the arrow keys) it will return 0 so if it is 0 then do a getch again to get the scan code... else return the key....
Great Milenko
Words Of Wisdom:
"Never Stick A Pretzel In Your Butt It Might Break Off In There."
http://www.crosswinds.net/~milenko
http://www.crosswinds.net/~pirotech
The Great Milenko"Don't stick a pretzel up your ass, it might get stuck in there.""Computer Programming is findding the right wrench to hammer in the correct screw."
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement