What is the best way to synchronize my display? For now I am only using windows for learning so I don’t mind using windows specific code for now. This is what I though would work:
DWORD time;
public void display()
{
//renderscene
while (GetTickCount() - time < 20) ; //time is initialized in my setup function so it will work the first time
time = GetTickCount();
}
I did not want to use something like Sleep(30);. I think that would mean the time between each frame would be equal to (the time it takes to render the scene) + 30 miliseconds. This would mean a variable rate depending on how long it takes to render the scene. The above method makes sure that every 20 miliseconds we display one frame of animation (unless it takes longer than 20 miliseconds to render the scene). But I notice that the function call GetTickCount is really slowing my program down. If I change it to:
DWORD time;
public void display()
{
//renderscene
while (GetTickCount() - time < 0) ;
time = GetTickCount();
}
it is a lot slower than if I just comment out the whole thing.
I would also like to be able to do AI/collision detection/etc while the frames are synching. Any suggestions?