I strongly encourage anyone thinking of building a networked XNA game, or even a non-XNA game, to watch this presentation by Shawn Hargreaves at Microsoft's Gamefest '08. Critically, the talk covers latency, bandwidth, prediction and smoothing. It also discloses some alarming statistics regarding the reliability of the Internet as of last year, compiled by Bungie's Halo 3 BETA.
Microsoft's quality assurance dictates that, for commercial games, projects must on average use no more than 8k data a second. Which, given packet headers, voice data and framework wrappers, makes conformity to these standards less than straight forward.
Serious care must be taken when receiving packets to determine the relevance of positional data from real time objects. XNA's SendDataOptions helpers go to great lengths to automate this process but must be used sparingly, as they can add considerable weight to packets.
According to Hargreaves, games should cope well with anything up to a whopping 10% packet loss and 270ms latency. Ouch. The NetworkSession.SimulatedLatency and NetworkSession.SimulatedPacketLoss setters should assist in recreating these conditions, but undoubtedly there will be no substitute for the real thing and no doubt we'll see some 'interesting' behaviour during out iterative network code design process.
Hargreaves states "There's nothing quite as cheap as the packet you don't even send", and stresses the importance of being selective with data. The NetworkSession should NOT be flushed every game update - 10 to 20 times a second is common even for fast paced commercial games.
Also, it's common sense, but packet headers cost bandwidth, so sending bigger packets less often saves on the headers. The session can queue data in the buffer and flush it on the update, sending multiple groups of data in a single headed packet.
Hargreaves suggests casting complex data types down when possible. For example a Vector3 costs 12 bytes of data but casting each of the floats to a byte and shipping them off quarters that cost. Ok so it's not as accurate but if it's the position of a less than critical game component, who cares?
A Matrix is 16 floats so that's an unforgivable 64 bytes. If an object has just rotated, there's no need to send it's entire new transformation object. The scale and position is wasted. Strings are huge so it goes without saying, sending them across a network is bad and if a game is coded well it should never be needed other than as chat text which isn't really relevant to an XBOX game using voice communication.
Speaking of voice, that costs 500 bytes per second per player so communal chatter should be restricted to a pre-game lobby where no positional data is being sent. In game, I think we'll stick with our proximity based chat!
It's worth checking out the slides on hybrid topologies too. I won't bore you with the details, but the general idea is to have different clients taking care of different server data elements such as powerups or projectiles. On a peer-to-peer network game, this is theoretically the fastest way to distribute data as the upload is shared.
There's tonnes more information on prediction, smoothing and sending controller input along with positional data to assist with this. As I said, well worth a look.
Win2D / ANGLE team engineering process
11 years ago
No comments:
Post a Comment