Hi,[background=transparent] [/background]
[background=transparent]
[background=transparent]
[background=transparent]I'm coding a rhythm game and the game runs smoothly with uncapped fps. But when I try to cap it around 60 the game updates in little chunks, like hiccups, as if it was skipping frames or at a very low frame rate. The reason I need to cap frame rate is because in some computers I tested the fps varies a lot (from ~80 - ~250 fps) and those drops are noticeable and degrade response time. Since this is a rhythm game this is very important.[/background]
[background=transparent]This issue is driving me crazy. I've spent a a whole week already and still can't figure out the problem. I hope someone more experienced than me could shed some light on it. I'll try to put here all the hints I've tried along with the code for my game loop, so I apologize with this post gets too lengthy.[/background] [/background][/background]
[background=transparent]
[background=transparent][background=transparent]1st GameLoop:[/background]
[/background][/background]
[background=transparent][background=transparent]
const uint UPDATE_SKIP = 1000 / 60;
uint nextGameTick = SDL_GetTicks();[/background][/background]
while(isNotDone)
{
// only false when a QUIT event is generated!
if (processEvents())
{
if (SDL_GetTicks() > nextGameTick)
{
update(UPDATE_SKIP);
render();
nextGameTick += UPDATE_SKIP;
}
}
}
[/background][/background]
[background=transparent]
const uint UPDATE_SKIP = 1000 / 60;
uint nextGameTick = SDL_GetTicks();[/background][/background]
while(isNotDone)
{
// only false when a QUIT event is generated!
if (processEvents())
{
if (SDL_GetTicks() > nextGameTick)
{
update(UPDATE_SKIP);
render();
nextGameTick += UPDATE_SKIP;
}
}
}
[background=transparent]
[background=transparent]2nd Game Loop:[/background]
[color=black][background=transparent] [/background][/background][/background][background=transparent][background=transparent][color=black][background=transparent]
const uint UPDATE_SKIP = 1000 / 60;
while (isNotDone)
{
LARGE_INTEGER startTime;
QueryPerformanceCounter(&startTime);[/background][/background][/background]
// process events will return false in case of a QUIT event processed
if (processEvents())
{
update(frameTime);
render();
}
LARGE_INTEGER endTime;
do {
QueryPerformanceCounter(&endTime);
frameTime = static_cast<uint>((endTime.QuadPart - startTime.QuadPart) * 1000.0 / frequency.QuadPart);
} while (frameTime < UPDATE_SKIP);
}
[/background][/background][/background]
[background=transparent]
const uint UPDATE_SKIP = 1000 / 60;
while (isNotDone)
{
LARGE_INTEGER startTime;
QueryPerformanceCounter(&startTime);[/background][/background][/background]
// process events will return false in case of a QUIT event processed
if (processEvents())
{
update(frameTime);
render();
}
LARGE_INTEGER endTime;
do {
QueryPerformanceCounter(&endTime);
frameTime = static_cast<uint>((endTime.QuadPart - startTime.QuadPart) * 1000.0 / frequency.QuadPart);
} while (frameTime < UPDATE_SKIP);
}