开发者

Network message serialization for game

开发者 https://www.devze.com 2023-02-01 01:27 出处:网络
Exit-games make a network library product called photon, and they have and actively develop a limited mmo demo. Rather than shooting off json or XML, etc. saying \"MovePlayer\" (with associated params

Exit-games make a network library product called photon, and they have and actively develop a limited mmo demo. Rather than shooting off json or XML, etc. saying "MovePlayer" (with associated params), they nut that message down to a 2 digit int, via an enum - something l开发者_JAVA技巧ike Operations.MovePlayer. There's no denying that a 2 digit int is smaller than a longer string, however I really hate the idea of statically burning each and every message into an enum.

Would there be an alternative way to have a MessageID property assign itself a unique 2 digit int based on a lookup table or something? Has anyone dealt with this kind of thing before?


For games, this is not the "old-school" way of doing things - it's the norm.

This is because, unlike typical web-services where the server will send the client data in short, rare bursts, in games, the server and client are sending packets back and forth constantly. The number of packets needed to synchronize every client's state with every other's balloons exponentially with the number of players, so the more players your game will have, the more important it is to keep the packet-size small.

Also, going over the MTU size (usually about 1400 bytes) will cause packet-fragmentation, which can have a significant impact on performance.

Note also that Microsoft has an 8 kilobytes-per-second upload and download limit on games made for the XBox 360, so you pretty much can't create an MMO using XML for networking messages.


As for how to translate a byte into a message type: just use a switch statement, or store a Dictionary<byte, Type> or Dictionary<byte, Func<Message>> (assuming you have a bunch of message-classes which all derive from base-class Message)


That's a really old-school way of doing things and reminds me of the 80s.

My company is using Agatha (request broker) for messaging in our MMO:

http://davybrion.com/blog/2009/11/hello-world-with-agatha/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号