I have a pretty straight forward server (using kryonet). The clients are only storing the current state of the car (x,y,angle etc) and are sending requests of acceleration and turning.
The server is receiving the requests and adding them to a ArrayBlockingQueue that the physics thread drains and reads and updates.
When adding another player, the speed of the game slows down by almost double. I have ruled out a lot of things (I have all updates and package sending throttled at 60Hz.)
I am suspecting that using a blocking queue is blocking so much that it is causing the slowdown.
How can I send the client requests to the physics thread without blocking issues?
I have found the bug. I needed to throttle the physics simulation in a different way (not with the world.step() function, but limit how often that is called). It is something like this.
while(true)
{
delta = System.nanoTime() - timer;
if(delta >= 16666666) // 60 Hz
{
world.step(1.0f, 6, 2);
processAndUpdateYourData();
timer = System.nanoTime();
}
}
Then I need to adjust all the physics numbers so they feel natural with this configuration.