+ Reply to Thread
Results 1 to 7 of 7

Thread: Multiplayer problem

  1. #1
    Junior Member
    Join Date
    Jul 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Multiplayer problem

    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 ?

    Stian Johansen

  2. #2
    Junior Member
    Join Date
    Jul 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 ?

  3. #3
    Electrotank jobem's Avatar
    Join Date
    Apr 2004
    Posts
    996
    Thanks
    0
    Thanked 24 Times in 17 Posts
    Hi beachbum,

    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:
    Code:
    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.
    ------
    Jobe Makar
    @jobemakar
    http://www.electrotank.com

    YouTube ElectroServer video tutorials
    http://www.youtube.com/user/ElectrotankInc

  4. #4
    Junior Member
    Join Date
    Jul 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the tips

    I will try this tomorrow

  5. #5
    Junior Member
    Join Date
    Jul 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    One more question.

    I can not use getTimer in the plugin, is getTime accurate ?

  6. #6
    Junior Member
    Join Date
    Jul 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I implemented the code just now and it is working perfectly :-)
    No lag or displacement or anything ( Date.getTime on the server was accurate )

    Thanks again

    Stian Johansen

  7. #7
    Electrotank
    Join Date
    Apr 2004
    Posts
    623
    Thanks
    0
    Thanked 5 Times in 5 Posts
    Sorry for the delay in my response, yes Date.getTime should be accurate down to ~1-10 milliseconds depending on your JVM and platform.

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts