Forum Games Client runs faster than server

Discussion relating to game development with Flash

Client runs faster than server

Postby tef » January 18th, 2011, 10:31 am

Hi.

I am new to multiplayer games but I have read the guide on this forum and I have also read a other guides on the subject.

So far I have a super simple asteroids clone. I have a game loop on the server that handles all the movement and recieves input from the clients. The server sends state updates at regular intervals and the clients use interpolation to create a smooth movement and this works nice.

But when I try to add prediction into the clients loop algorithm I notice that it runs faster than the servers physics update 30 fps, even though my flash is running with 60 fps, but physics are locked fps at 30. Thus the server falls behind very fast even though its supposed to run with the same period. Now, I didn't expect them to run perfectly synchronized, but the client runs 1.5 times faster than the server.

What is the proper method to solve this issue?

/thanks
tef
 
Posts: 10
Joined: January 7th, 2011, 3:38 pm

Re: Client runs faster than server

Postby Benjaminsen » January 18th, 2011, 12:08 pm

I highly suggest that you switch to a frame rate independent mode. Ie, instead of using frames you calculate the offset since the last tick and calculate the world changes based on the difference.

The subject is a bit complex to get into at first, but it's really worth it in the long run as it also fixes issues such as different computers running your game at slightly different speeds. If enough people are asking for it, I will write some tutorials on the subject!
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Client runs faster than server

Postby tef » January 18th, 2011, 1:12 pm

The game is not dependet on flash frame rate. The physical update has a fixed frame rate, so even though flash doesn't manage to keep its frame rate the physical frame rate will always be forced to 30 fps, ie. 33 ms per period. But flash will draw as many times as possible during that period.

Maybe I need to do something similar on the server side, or use offset time as you suggested. Now my server game loop is just a timer. I guess the fram rate can't be trusted on the server side either?

AddTimer(delegate {
ForEachPlayer(updatePhysics);
}, PERIOD);
tef
 
Posts: 10
Joined: January 7th, 2011, 3:38 pm

Re: Client runs faster than server

Postby Benjaminsen » January 18th, 2011, 1:13 pm

tef wrote:The game is not dependet on flash frame rate. The physical update has a fixed frame rate, so even though flash doesn't manage to keep its frame rate the physical frame rate will always be forced to 30 fps, ie. 33 ms per period. But flash will draw as many times as possible during that period.

Maybe I need to do something similar on the server side, or use offset time as you suggested. Now my server game loop is just a timer. I guess the fram rate can't be trusted on the server side either?

AddTimer(delegate {
ForEachPlayer(updatePhysics);
}, PERIOD);


Nope there is no guaranteed processes speed on the server.
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Client runs faster than server

Postby tef » January 18th, 2011, 1:30 pm

Thanks for the reply.

I was naive enough to think that this was already taken care off, ie. that addTimer was a fixed loop. I just did an offset calculation and viola! The numbers are not screwed up.
tef
 
Posts: 10
Joined: January 7th, 2011, 3:38 pm


Return to Games



cron