Game loop ... or whatever it's called ...
Yes, I''m yet another person interested in game development. I have a few questions about the thing that Im going to call the main game loop.
Before I get into it, I should probably mention that I have finished my CS degree, so c++ or programming concepts probably wont be an issue here.
I''m wondering how a person is supposed to throttle a game. My first forray into the game development world was something simple ... another tetris clone. I soon realized that I can''t let the main game loop run full bore, or the block would hit the bottom of the screen before the user knew what was happening.
At first I tried the distance = (speed * time) approach ... this didnt work out since the time between each loop (or frame) was so small that the blocks never moved. Instead I decided to figure out how much time it should take for the block to fall one space, and only refresh the screen after this time is up.
A simple enough solution, but I doubt this strategy would work in a real game. I''m trying to figure out how the Quakes, Unreals and Diablo 2s of the world solve this problem. In games such as these the user ideally wants frame rates that are as high as possible ... refreshing the screen after a certain amout of time isn''t the way to achieve this, and for some reason (in my head) it doesn''t make sence to let the loop run free without any throttle.
is there enough happening in these game loops so that they essentially throttle themselves?
thanks in advance
God no, don''t throttle the game loop. Let it run as fast as possible.
Your thought to use distance = speed * time was the correct one. Each time through the loop, find the number of time units that have elapsed since the last screen refresh and use that time delta to update the position of your game entities. If you are running at 200 fps, that time delta would be around 1/200 of a second. If your blocks move at 2 unites per second, then they should move 1/100 of a unit every frame at 200 fps. If your blocks weren''t moving at all the first time you tried this, you must have been doing something wrong.
Even if the framerate becomes slower (or faster), using this method will provide a physically realistic motion in your game, while allowing smooth screen updates.
Your thought to use distance = speed * time was the correct one. Each time through the loop, find the number of time units that have elapsed since the last screen refresh and use that time delta to update the position of your game entities. If you are running at 200 fps, that time delta would be around 1/200 of a second. If your blocks move at 2 unites per second, then they should move 1/100 of a unit every frame at 200 fps. If your blocks weren''t moving at all the first time you tried this, you must have been doing something wrong.
Even if the framerate becomes slower (or faster), using this method will provide a physically realistic motion in your game, while allowing smooth screen updates.
quote:Original post by fizban75
God no, don''t throttle the game loop. Let it run as fast as possible.
If your blocks weren''t moving at all the first time you tried this, you must have been doing something wrong.
I think my problem was most likely that I was using INTs as the type for my x,y coordinates of the blocks. If I had used DOUBLEs I wouldnt have rounded down to a distance of zero pixles for each move.
quote:Original post by SpaceBoy2001
I think my problem was most likely that I was using INTs as the type for my x,y coordinates of the blocks. If I had used DOUBLEs I wouldnt have rounded down to a distance of zero pixles for each move.
That''s definitely the problem. All position information should be handled as floats or doubles.
Salutations.
I wrote a game with time-based motion. I used floats to store position on the map (in units of "tiles"), and timeGetTime() (it returns the current system time) to calculate the "time delta" per game loop, in milliseconds. All velocities were then worked into the game in units of tiles/milliseconds. You can find a copy of my game and source here if your interested in how I did it. Workspace & Project files for MSVC++ 6.0 pro included.
---email--- Tok ----surf----
~The Feature Creep of the Family~
I wrote a game with time-based motion. I used floats to store position on the map (in units of "tiles"), and timeGetTime() (it returns the current system time) to calculate the "time delta" per game loop, in milliseconds. All velocities were then worked into the game in units of tiles/milliseconds. You can find a copy of my game and source here if your interested in how I did it. Workspace & Project files for MSVC++ 6.0 pro included.
---email--- Tok ----surf----
~The Feature Creep of the Family~
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement