Original Post
In my game I've got two threads, a server thread and a client thread. The server thread does all the logic and collision stuff, the client mostly renders. The trouble I'm having is getting the two threads to share the CPU. The client runs in the main thread and the server runs in a thread I create. I'm using SDL_Delay() in the server thread to make it give up the CPU sort of like this:
// calculate how long the delay should be to get the
// thread to run around 100 Hz
delay = 10 - (SDL_GetTicks() - timeAtBeginningOfFrame);
if (delay > 0) SDL_Delay(delay); Later in that thread I'm using fixed timesteps in ODE, like this: Step()
{
remainder += SecondsPerFrame();
while(true)
{
if (remainder >= 0.01) // 100 Hz
{
dWorldQuickStep(world, 0.01);
remainder -= 0.01;
}
else { break; }
}
} The problem is when the program first starts out it's running at 100% CPU usage, and it's slow. The client thread is running at about 50 FPS and the server at about 40 FPS. But the wierd thing is if I click and drag on the game's title bar, pausing the client thread, then release it, when it starts running again the client is running at around 100 FPS and the server at about 90 FPS. What is going on?