Forum Games Event syncs

Discussion relating to game development with Flash

Event syncs

Postby FulaFisken » March 12th, 2011, 5:34 pm

Hi there!

I have an issue that I need a solution or explanation for.
We have locked our steps on client and server to 33 ms.
We have a client clock that are completely synchronised with the server.

Game loop with lock step:
Code: Select all
   DateTime newTime = DateTime.Now;
            frameTime = (newTime - currentTime).TotalMilliseconds;
            currentTime = newTime;
           
            if (frameTime > 1000)
            {
                frameTime = 1000;
            }

            accumulator += frameTime;

            while (accumulator >= PERIOD)
            {     
                ForEachPlayer(delegate(Player player)
                {
                    player.ship.update();
                });
                tick++;
                accumulator -= PERIOD;

                syncManager.update(); //send command states
            }


An acceleration event is triggered on the client at 100 ms, next tick is nr 4.
The event reaches the server at 132 ms, next tick is nr 4. (32 ms latency)

A stop accelerate event is triggered on the client at 172 ms. next tick is nr 6.
The event reaches the server at 204 ms, next tick is nr 7.

The server has now accelerated 3 steps while the client only accelerated for 2 steps.

How do you make sure both client and server do the same amount of steps?
Fula Fisken
website blog twitter
Play Game
Astroflux
User avatar
FulaFisken
Paid Member
 
Posts: 139
Joined: March 2nd, 2011, 10:15 am

Re: Event syncs

Postby Benjaminsen » March 14th, 2011, 6:17 pm

Interesting problem, here is how I suggest you solve it. Basically the problem occurs as your code has no concept of when things happened. To properly fix it we need to change the code so thats no longer true. This does however require us to first synchronize the clocks between server and clients. Do this google search to figure out how.

Now that we have a synchronized clocks, we can pass a timestamp to the server which tells the server and the listening clients when something happened to an object. The client can then tick the object forward until the proper state for said object is achieved.

The clever reader will at this point be aware that
1: You will need separate timestamps for separate synchronized objects.
2: Just ticking additional times will not fix properties that are already out of syntonization. Thus you will need to send along all object properties with the timestamp.
3: You will need some good interpolation to ensure that the objects behave nicely.

The multiplayer asteroids example I have here implements all of the above except step 3 interpolation. (It does however need to get updated to the newest version of Player.IO to run)

Happy Hacking!
Chris
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Event syncs

Postby FulaFisken » March 15th, 2011, 12:00 pm

We have synhronized the client and servers with each other already. Lets assume the server has been accelerating for 300ms after recieving an acceleration message with timestamp from a client. Then a stop message with timestamp arrives at the server saying the that the client actually stopped accelerating 40 ms ago. Do you resimulate the acceleration phase or do you force the client to correct its position?

Right now we actually try to resimulate the server up to 99ms, by saving 3 previous states, after that we force the client to correct its position.
Fula Fisken
website blog twitter
Play Game
Astroflux
User avatar
FulaFisken
Paid Member
 
Posts: 139
Joined: March 2nd, 2011, 10:15 am


Return to Games