Indie Game Development - "Having fun, making fun"

Tuesday, July 24, 2012

Dev Log - Bandwidth and Latency

I really enjoyed implementing the compression techniques for multiplayer, and have had great success with it.  I was able to reduce the server's bandwidth from 50,000 bytes to a peak of 7000 bytes.  Microsoft requires games going through their certification process to be below 8000.  While indie games do not have to meet this standard, I wanted to ensure my players had a good experience.

I was able to accomplish this using a variety of techniques that Shawn described in his blog.  First, I removed any data that was not really necessary at that moment.  For example, player stats are only needed after a match so I didn't need to update them during game play.  I also discovered that I didn't need to send a matrix for each character.  A matrix is a what the computer uses to store a 3D objects position, facing and scale.  Since my characters never change scale I didn't need the scale portion.  Since my characters never leave the ground, I was able to replace the 3D position and facing data with a smaller 2D vector data.  To top it off, I was able to further reduce the size using a compression technique called packed vertors.

The part that made me feel clever was when I was able to replace five interger values with a single half interger.  I realized that most of the numerical values I needed to send only had a range of 0-9.  Therefore, I saved a value in the one's place, another in the ten's place, another in the hundred's place and so on.

The last thing I did was offload some of the server's work to one or more clients.  In deathmatch for example, one of the clients is selected to manage any computer players, while the sever manages the balls.  In a sense therefore, there are kind of two servers.

All these techniques enabled me to meet my bandwidth goals while still sending data every frame - so I haven't had to trade bandwidth for latency.  My next step is to solve the latency problem.  After banging my head against a wall for a couple days, I've finally got a prediction system working for basic movement.  When I get back from vacation, I'll complete that work and let you know how it went.

No comments:

Post a Comment