A Flash Developer Resource Site

Page 1 of 3 123 LastLast
Results 1 to 20 of 45

Thread: Real-time multiplayer game: source code

  1. #1
    Senior Member
    Join Date
    Jun 2000
    Posts
    896

    Real-time multiplayer game: source code

    Hi guys,

    I presented a session last week at Flashforward 2004 SF on Real-time Multiplayer Games in Flash. For the presentation I created a real-time multiplayer game and made it available for play online and download. If you are interested in reviewing the session notes, the game, or the game source you can find all of this here:

    http://www.electrotank.com/Presentations/FF/SF2004/

    Eventually I intend to release several articles discussing the various sub-topics that I presented during the session. Also, I intend to eventually write an article discussing Pixel Cannon in greater detail.

    I hope that some of you find this useful!

  2. #2
    Ihoss
    Guest
    cool, although a little slow. there was a bit of lag when i played (against saphua, i won YAY )

  3. #3
    SaphuA SaphuA's Avatar
    Join Date
    Oct 2002
    Location
    The Netherlands
    Posts
    2,182
    Originally posted by Ihoss
    cool, although a little slow. there was a bit of lag when i played (against saphua, i won YAY )
    Yah d0h! I had to kill someone else first... so my health was low

    You did a great job there Jobem!
    Thnx for sharing this...

    SaphuA

  4. #4
    Senior Member
    Join Date
    Jun 2000
    Posts
    896
    Hi Ihoss,

    Yes, lag can occur. But that is 100% network related, has nothing to do with Flash or the game.

    In my presentation I discussed this and how you can work with it. That will be one of my next articles.

    All multiplayer games, like Quake and Everquest, have this exact problem. And like them, we can employ visual trickery to hide the problem. This game does not hide the problem.

  5. #5

  6. #6
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Thanks, Jobe

    If I may ask, where exactly is PixelCannonPlugin.as run? Is it server stuff only?

  7. #7
    Senior Member
    Join Date
    Jan 2004
    Posts
    366
    Hi Jobe,

    I have one of your books, its dymistified version for flash mx. Does that book go into real time multiplayer or do I need to look at this source code instead? I am still on one of the early chapters, so dont really know it all yet.

  8. #8
    Ihoss
    Guest
    arrow, theres an index part to your book

    there is a thread here where you can find a lot of stuff on it, and at the electroserver website theres also some articles.

  9. #9
    Senior Member
    Join Date
    Jan 2004
    Posts
    366
    Originally posted by Ihoss
    arrow, theres an index part to your book

    there is a thread here where you can find a lot of stuff on it, and at the electroserver website theres also some articles.
    i bought used, its missing a few first pages.

  10. #10
    Senior Member
    Join Date
    Oct 2001
    Location
    Belgium
    Posts
    467
    Thx m8y

    I'll run it on my server in a few minutes..

  11. #11
    Senior Member
    Join Date
    Jun 2000
    Posts
    896
    Hi tonypa,

    PixelCannon.as is a server-side plug-in. ElectroServer 3 pulls it in to use it for the game. If someone is trying to run this on their own computer then I can explain in more detail how to get it up and running for local testing.

  12. #12
    Senior Member
    Join Date
    Jun 2000
    Posts
    896
    ArrowFlash,

    No, there is nothing in that book about this. Only turn-based multiplayer games.

    Unfortunately there is also nothing about it in my latest game book which will be out this month. I was pretty upset about being rushed into publishing the book without being able to add some great stuff like this.

    As far as I know, this source file is the only open source real-time multiplayer Flash game out there. And there is no written documentation in any Flash related book on the subject. So for information on it at this point you need to do one or more of the following:

    -Ask me questions
    -Wait for some articles to be published by me on the subject
    -Figure some of it out for yourself reading through gamasutra.com and non-Flash related multiplayer books

    But information *will* come. The release of this file is just the first step of many.

  13. #13
    Yes we can tomsamson's Avatar
    Join Date
    Sep 2001
    Location
    Team Titan Secret Lair
    Posts
    4,666
    arrowflash you make me wonder almost each time i read a comment by you..
    anyho,Jobe,i gave it a try,too,first of all generous move to give it away,thanks =)
    then,just as the others said,i experienced some lagging,too,i´m interested in turning some of our games multiplayer,so i wonder,is it possible to create a realtime multiplayer version of a fast paced (nonstop action) game like a sidescrolling shoot´em´up?(without too much lagging?)
    which parts affect lagging so much? (specifically in your electroserver)?
    i have dsl,therefore i can play most commercial games without much lagging over the net,so where´s the major bottleneck when doing multiplayer in flash?
    i can imagine things like sending too much/oversized chunks of data or sending the data in form of xml but as you say:
    "All multiplayer games, like Quake and Everquest, have this exact problem. And like them, we can employ visual trickery to hide the problem. This game does not hide the problem."
    how can you hide the problem in games with constant action?

  14. #14
    Senior Member
    Join Date
    Jun 2000
    Posts
    896
    Hi tomsamson,

    That is a great question. Before answering, there are a few things to note about a real-time multiplayer game (RTMG) like Pixel Cannon (PC).

    - The entire game state is controlled by PixelCannon.as on the server in the server-side plug-in

    - All clients are completely synchronized with the server. Due to latency they don't get updates instantaneously. But when the update arrives, the client (Flash) updates the game state to look exactly like it should. If you click through some of the slides in my presentation notes, you'll see some good figures. Its actually under the synchronization heading.

    Now, you can imagine that if you have a larger latency that it will take a little more time for a message to arrive for you. Since this game does not attempt to hide that fact you can see it if your latency (seen in the upper right hand corner of the game) is above around 200ms.

    Here are two ways that games try to hide latency in a RTMG. One is simple, one is not (Keep in mind that these are not used in PC):

    - Scheduled the events. For example: a client sends a shot request to the server. Instead of the server creating it immediately, it can go ahead and send out a message to all clients telling them to create it in like 100ms. BAM, you just reduced the "feel" of the latency by 100ms.

    - Advanced smoothing/prediction algorithms. This is often referred to as dead-reckoning. This is used by most major fast-paced games like Quake. They may show incorrect information. They keep moving a person along what "seems" to be the correct path until they are told otherwise. If they get new information then they just use that to correct the path without snapping the character into the new position. If the new information is over a certain % off of the predicted path, then snapping (blippage) also may occur. Which is why people with horrible latencies might see people blipping all over the place. But people with mediocre or good latencies see the visual trickery with no blipping. But they still are not necessarily seeing correct information, its just "pretty close".

    There are some other little things that you can do as well. If the game doesn't need precision, then people might not care. If there is a muzzel flare on the tank barrel for instance, you might hide the fact that hte projectile is further ahead.

    One more thing and I'll shut up
    At the beginning of PC people might be experiencing a bit higher latency than later in the game. This is because right at the beginning, for like 1-2 seconds, the server is doing some initial things like parsing XML for the map. So there, only for a moment, is a slight delay. Every 2 seconds or 5 seconds the PC attempts to determine the latency. It keeps a running average of the last 10 values. I hope to update this with something better soon. I just read about an algorithm that is better than just taking the average. Its a way to logically throw out high latencies that don't belong in the averagle.

    Hope this helps with some understanding of the game. I am happy to explain more.

  15. #15
    Senior Member
    Join Date
    Jan 2004
    Posts
    366
    Originally posted by tomsamson
    arrowflash you make me wonder almost each time i read a comment by you..
    how can you hide the problem in games with constant action?
    Here is some basic idea.

    if (newdata == false)
    {
    move = getlastmove();
    fire = getlastfire();
    }

    Since I answered your question, please answer mine. You said that when I post it makes you wonder... what is it that you wonder?

  16. #16
    Senior Member
    Join Date
    Jun 2000
    Posts
    896
    Just some general information for everyone:

    -Pixel Cannon is completely controlled by the server

    -All clients are pretty dumb. They do no collision detection. And have almost no game-related logic. Most of the logic is used to interpret what the server tells it to do, and for animating things in a time-based way.

    -The server creates projectiles, moves tanks, and animates them in memory. When it determines a client needs to know something, it informs the appropriate clients. For instance, when a projectile collides with something or leaves the map, all clients are informed.

    -The custom server logic was written using ActionScript 1.0 and is used with ElectroServer 3 as what we call are calling plug-ins.

    -Each level is an XML file. When a level is chosen both the server and the client load this same XML file. The client uses it to display the map. The server uses it to represent the game in memory.

  17. #17
    2KHeroes / Sylvaniah designer luxregina's Avatar
    Join Date
    Jul 2001
    Location
    Somewhere between Kirlundin and Anskaven
    Posts
    1,273
    I was going to PM this, and i finally found no real reason to not say it out loud :



    Not only your book has been helpfull to a lot of us by making complicated concepts much clearer ( a* for me ! ) but you are also a valuable member of this community, always eager to give explanations ... and openening new perspectives for a lot of members : thanks for that new open source !

  18. #18
    Senior Member
    Join Date
    Jun 2000
    Posts
    896
    I'm glad to be of help!

    FYI: My newest gamebook out later this month has way better A*. Full mult-terrain support!

  19. #19
    Yes we can tomsamson's Avatar
    Join Date
    Sep 2001
    Location
    Team Titan Secret Lair
    Posts
    4,666
    Originally posted by ArrowFlash

    Since I answered your question, please answer mine. You said that when I post it makes you wonder... what is it that you wonder?
    thanks for the basic idea,
    i wondered as you got a book with missing pages,no big deal =)

    Jobe,thanks for explaining some ways of "cheating" around obvious lags =) ,especially the "Advanced smoothing/prediction algorithms"
    made me curious.
    i know i died although my enemy didn´t shoot anymore (but the lag avoidance calculated on that he may be) in my early quake days (with my 33.6 modem back then),but i still think its the best option =)
    also thanks for sharing the other valuable info,i´m fully with lux on what he said =)
    i´m building flash apps (the nowadays called RIAs..) at the office and we use xml for frontend/backend communication a lot but i stopped using it for games as i need the fastest possible input/output combo for those,so i´m still wondering why you´re using xml at all (or did i get that part wrong and you´re only using xml for the map and not for the communication (exchange)?

  20. #20
    Senior Member
    Join Date
    Jun 2000
    Posts
    896
    Hi tomsamson,

    One of the last slides in my presentation notes is on alternate protocols. ElectroServer 3, by defautl, uses XML. XML is extremely useful and easy to use, but at the same time its fat and in a RTMG can cause excessive bandwidth usage.

    We *just* introduced a way to define an alternate protocol through plug-ins. The plug-in can send raw data that is not XML. In Pixel Cannon the average packet size is 225 bytes. Using an alternate string protocol with a delimieter (like 393939|dkfjdkd|3939|289) we can reduce the average byte size to 20-40 bytes.

    Pixel Cannon still uses just plain old XML. Over the next few months you'll see us making much progress in this arena. Smoothing/prediction and scheduled events takes care of much of the latency problem, and defining an alternate protocol can help solve the bandwidth problem

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center