DWORD time_count = 25; // ms per frame, default if no performance counter
LONGLONG next_time = 0; // time to render next frame
LONGLONG cur_time = 0; // current time
LONGLONG perf_cnt = 0; // performance timer frequency
BOOL move_flag = TRUE; // flag noting if we have moved yet
if (move_flag)
{
// yes, move and clear flag
actualGame->update();
move_flag = FALSE;
}
cur_time = timeGetTime();
// is it time to render the frame?
if (cur_time > next_time)
{
// yes, render the frame
actualGame->draw();
// set time for next frame
next_time += time_count;
// If we get more than a frame ahead, allow us to drop one
// Otherwise, we will never catch up if we let the error
// accumulate, and message handling will suffer
if (next_time < cur_time)
{
next_time = cur_time + time_count;
}
// flag that we need to move objects again
move_flag = TRUE;
}
The problem still is, on SOME computers the game runs as expected and on SOME runs very fast.