Jump to content
  • Advertisement
Sign in to follow this  

Running in 60 fps

This topic is 2896 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

Flickering how? items on the screen jerk around? the screen doesn't update nearly as fast? you are seeing it flash black and then display?

are you double buffer rendering?

Also I wouldn't couple movement processing and screen renders together like that. uncoupling them allows smoother rendering.

Also, consider that rendering takes time and movement takes time. I hope they are both tight enough to fit into your frame time maximum to achieve 60 fps. Edited by Infernal-rk

Share this post

Link to post
Share on other sites
Here is a sample of my game loop. You'll notice that I have two updateXXXXX() methods. The updateFixed steps through fixed time step operations, such as processing input, movement, etc. The updateVariable processes things like rendering. Eventually this loop will be more based on process/task delegation across several threads, but I haven't gotten to that point yet. This is all single threaded but I can maintain a decent frame rate on an older laptop, assuming I keep the size of the window at 1024x768 or smaller.

TTimer clock;
double fixedTimeStep = 1 / 60.0;
int maxSubSteps = 5;
int numSubSteps = 0;
double timeDifference = 0.0;
unsigned long startTime = clock.getMilliseconds();
unsigned long currentTime = startTime;
unsigned long endTime = 0;
double localTime = 0.0;

// main game loop iterates until a stop event
// has been detected from the event system.
while(!m_bShutdown) {
currentTime = clock.getMilliseconds();
timeDifference = (currentTime - startTime) / 1000.0;
startTime = currentTime;

numSubSteps = 0;
if(maxSubSteps != 0) {
localTime += timeDifference;
if(localTime >= fixedTimeStep) {
numSubSteps = (int) (localTime / fixedTimeStep);
localTime -= numSubSteps * fixedTimeStep;

if(numSubSteps != 0) {
int clampedSubSteps = (numSubSteps > maxSubSteps) ? maxSubSteps : numSubSteps;
for(int i = 0; i < clampedSubSteps; ++i)


if(1000 * fixedTimeStep - (clock.getMilliseconds() - startTime) > 1)

Share this post

Link to post
Share on other sites
your while loop there....is this being called by the win32 message loop or did you remove all that and just have your own while loop left. No concern for the windws messages that need to be processed?

Share this post

Link to post
Share on other sites
The event subsystem takes care of that for me when it gets polled in the updateFixed() method call. I guess I could have placed it in the main loop :).

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!