I'm trying to build a small networked game using WebGL and NodeJS. I have a basic client and server setup and I'm at the point where I'm trying to implement dead reckoning to simulate what happens on the client.
I have a odd problem which I'm not really sure how to fix, the game loops for my client and server don't seem to match up and the client one always seems to be faster. I'm hosting my server on the same system as my client right now and I'm logging every frame for the two. If I log it for longer than 5seconds the server starts to get behind by 10-20 frames and the gap just gets bigger and bigger over time. There isn't really anymore processing that is happening on the server than on the client at the moment because I'm working with a really basic example right now.
My loop for both right now look something like this:
var loopDelay = 16.666666666666666666666666666667;
function loop()
{
setTimeout(function() {
update();
loop();
}, loopDelay);
}
On the client I did have something like this:
function loop()
{
setTimeout(function() {
update();
requestAnimationFrame(loop);
draw();
}, loopDelay);
}
But I removed it and copied the server one temporarily when I started running into this problem to make sure it wasn't that.
What can I do to make the two sync up perfectly?
Thanks
No comments:
Post a Comment