Generic C memory compression / packing

Started by
6 comments, last by Rasterman 11 years, 11 months ago
I'm working on a new networking project, a RTS game, and going with a server client model. To sync the clients I am planning to use delta comparisons on the server, only update client view units quickly, and use selective memory packing, meaning only sending bytes, words, or dwords that have changed. To do this I wrote some very simple packer/unpacker routines, and will have some custom ones for faster updates. I was just curious if anyone knows of any articles or other forum threads on this subject? The only thing I could find was an article here http://sirisian.com/blog/binary-packet/ but it is regarding packing bit by bit, which I am not going to do since I think it would be too CPU intensive for a mobile game.
Advertisement
Google's Protocol Buffers might be interesting, although I'm not sure how they measure up in terms of relative computational efficiency on a mobile device.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]


The only thing I could find was an article here http://sirisian.com/.../binary-packet/ but it is regarding packing bit by bit, which I am not going to do since I think it would be too CPU intensive for a mobile game.

CPU intensive for who? The client is basically just sending input that might only a be a few bytes. It depends on how twitchy your game is, but since you mentioned mobile I'll assume it's not a 400 apm RTS game. Then for getting the state I'm imagining a fixed update rate that's fairly low like 200 ms at the most? (5 updates per second). Assuming you're not updating hundreds of units at once and are doing sane delta updates I don't think you'd hit anything that would be that CPU intensive to deserialize coming from the server.

That said I wrote these two writers. C++ version. C# version. They are simple binary writers/readers which I wrote for someone that was developing between languages. Basically what's going to help you more than anything is sane delta compression. Not sending anything the client already knows about. Your server should be 100% aware of what the clients know and intelligent in building the per client packets. (I'd give you more information, but I removed my old articles online relating to this so I could rewrite them. Been meaning to get back to that).

// edit also I see my robots.txt isn't stopping people from finding my blog. Interesting.
Thanks for your input, both useful posts :) After reading your binary-packet article again, that is basically what I am doing, except for boolean values I'm simply using a byte rather than misaligning the data and packing it bit by bit, I'm packing it byte by byte. And I think it may be too CPU intensive for the server, since the server will also run on a mobile device, and be doing all of the game simulation, and overhead for calculating data deltas for all clients. If I have to limit the number of clients to 1 that is not a problem, and currently my game does support 1000 mobile units per players, up to 4 players, but if that needs to be limited for network play that is not a problem either.

I'm thinking using delta updates and only updating quickly for units in the clients currently active viewport will hopefully be enough to limit the bandwidth. I'm adding this to an already completed and mature game, so don't have the luxury of making a predictive system. My goal also isn't to make a 100% perfect sync, as long as its playable and pretty close I will be happy.
Spent the day testing delta bandwidth. Last test was 2 players with 200 offensive units total (400 including buildings), it averages about 400 kB/s with an estimated 25% of waste, this is for all 400 units every frame. If I backoff the static units and the units outside of the clients viewport to update less it drops down to 60-150 kB/s with 25% waste, so with simple optimization I could get that down to 50-100 kB/s, that seems pretty reasonable. This is at an update rate of 30 fps, so if the game can handle less updates automatically say 5 fps then that would drop to 10-20 kB/s.
150 kB/s is at least 20x too much for an RTS. If you use an input-synchronous model (a la Age of Empires, Starcraft, Warcraft, etc) then you only need to send commands, and re-calculate unit movements/actions on all clients.
enum Bool { True, False, FileNotFound };
I could get that down to 50-100 kB/s, that seems pretty reasonable.[/quote]

For a 30 minute session, that's ~180 megabytes. So 6 hours of gameplay will break 1GB/month limit that many devices come with. Some low-end plans only come with 100MB of data or so. These numbers start approaching video on demand.

At $0.1 per MB over that, it would be $36 per hour of gameplay. That is, simply put, insane. Unless you're running a 1-900- business. Honest advice, if planning on distributing such an app, it better come with a huge warning, or you may bankrupt people.

For a RTS, with dedicated protocol, think tens of bytes per second instead.


Even if costs weren't a problem, network reliability is. A small delay will mean corresponding pile-up of data, which isn't biggest problem, but considering the way naive serialization works it may cause bursts of multiple megabytes on spikes.
FYI my game is now working in multiplayer smile.png Took 50 days, now testing over LAN and with simulated lag. Turned out to work better than I had anticipated using state change notifications, which amounts to about 3KB/s of data with 50-100 units, and upwards of 15KB/s with 500 units. The client isn't perfect, units sometimes get out of position and are lerped to their correct locations. For adding networking to such a complicated game after the fact I am pretty happy with it. I also do a full update on one unit per timeslice, which I should probably increase if the connection is on broadband.

This topic is closed to new replies.

Advertisement