8Dromeda Twitter Disable Tracking

8Dromeda Blog

[All Posts] [<< >>] [2013-07-24]

Soilnar July Update Part 2: Network Optimization

Having dealt with scaling, I was poking around in the game and looked at a network monitor graph. The game was causing more traffic than I would've expected.

I fired up [tcpflow -p -c -i lo port 8081] and moved around.

Every movement step caused the transfer of a whole 20x20 tile chunk around the ship. Why? Well, because every time the ship moved, it added track traces to the tile underneath. This lead the network system to see that the 20x20 chunk was modified, and it happily proceeded to send it, every time.

Information flow in the Soilnar Entity-Component Framework is based on events. Systems emit events when something is modified, and other systems listen for events that they need to act on.

The network system simply listens for modification of anything, and when anything is modified, it determines who should hear about that modification, finally sending the modification to all the appropriate game clients.

First I thought something like "oh dog, this is going to go so spaghetti tier!", until the glorious truth hit me. The thing is actually fairly well designed! I needed to add an optional field to the value modification event that can contain a network-transferrable description of the change from the previous state to the current one, and make the tile chunk system always fill it in.

Before: struct ValuesModifiedEvent { vector<string> changes; }; After: struct ValuesModifiedEvent { struct ChangedValue { string name; MinorChange *minor_change; }; vector<ChangedValue> changes; };

All of the existing event listeners will work just like before, but the network system is extended to transfer the minor modification description instead when it is provided.

Before, when moving with a fast-moving ship, the network consumption was 50KB/s. Now it is 12KB/s, and if we leave out transferring newly visible tile chunks, it is 2KB/s.

To be continued...

As noted in the previous post, I have way too much stuff for a single post.

- A of 8Dromeda

All Posts