View Full Version : Multiplayer problem
10-21-2004, 02:37 PM
I have made a lot of Flash games and I have just started making a multiplayer game, using ElectroServer and Flash 2004
My problem is quite simple.
If I set my flash to 25 frames/s and trace out getTimer() interval in the onEnterFrame, the result is something like this :
40,40,40,50,41,41,40,40,40,49,43,44,40,40,39, that is not good
On the server I have a setInterval(function,40), the same trace reports
47,47,46,47,47,47,46,47,47,47,63,47,47,47, that is certainly not good
As you can see, this leads to inconsistency when I sync, client and server.
Is there a well known sollution to this problem ?
10-21-2004, 05:13 PM
I forgot to tell you that I am calculating the moving of objects both on the server and the client. The server sends a message to the client only when a change of state has occured ( from moving left to full stop ), and then the client sync the objetcs position with the server ( thats when the inconsitency occurs )
I made it this way to avoid a lot messages.
Maybe the server should contact each client with the position of the objects every 30ms ?
What is the best sollution ?
10-21-2004, 06:51 PM
You bring up some good points. I have a ton of experience in handline the that you are running into.
It helps to look at this in sort of a different way. Don't look at frames as chunks of time. If your frame frame is 25, don't expect each frame to be 40ms after the previous. Instead, treat frames like snapshots in time. What you render onto the screen would then be *always* be correct, but is dependent on what time it is.
This means that you make animations time based. I'd still recommend using enterFrame. On every enterFrame event do a getTimer() call. Based on either what time it is or how much time passed since the previous render, do stuff.
For instance, a ball rolling horizontally across the screen might have this equation of motion:
var x = xVel*time + x_initial
x_initial is the x position of the ball at time 0. The position can be precisely determined just by doing a getTimer() to figure out what time it is. Now, you can extend this frame-independent animation to all moving objects.
Where you might see issues:
Collision detection. If it is multiplayer then collision detection should most likely be done by the server anyway. But if you *had* to do collision detection on the client you need to do it in memory, hitTest won't cut it when time-based animations. One client's "snapshot" in time might be 52ms while someone elses is 45ms....hence rendering the ball out correctly, but in a different position. If you do the detection i memory, then it too is frame independent.
I understand that this is a big change in thinking, but I can assure you that is perfect and absolutely needed since you cannot gaurantee synchronization between the server and the client if they both use unreliable time intervals.
10-21-2004, 07:14 PM
Thanks for the tips
I will try this tomorrow
10-21-2004, 07:31 PM
One more question.
I can not use getTimer in the plugin, is getTime accurate ?
10-22-2004, 12:28 PM
I implemented the code just now and it is working perfectly :-)
No lag or displacement or anything ( Date.getTime on the server was accurate )
10-26-2004, 03:20 AM
Sorry for the delay in my response, yes Date.getTime should be accurate down to ~1-10 milliseconds depending on your JVM and platform.
Powered by vBulletin® Version 4.1.6 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.