I am working on a game engine that freely departs from Quake 2, adding some things, such as script effects (allowing the server to specify special effects for the client in detail, instead of having only a limited number of hard-coded effects that the client is capable of.) This is a compromise of efficiency Networks for flexibility.
I hit an interesting barrier. See, The maximum packet size is 2800 bytes, and only one can go to each client per frame.
Here is a script to make the effect of "sparks" (may be good for bullet sparks, electric shocks, etc.). http://pastebin.com/m7acdf519 (If you don’t understand this, don’t sweat, this is the special syntax I made and not related to the question I ask.)
I did my best to reduce the size of this script. I even reduced the variable names to separate letters. But the result is exactly 405 bytes. This means that you can place no more than 6 of them per frame. I also mean a few server-side changes that could shave it another 12 and change the protocol, which could save another 6. Although the savings will vary depending on which script you are working with.
However, out of these 387 bytes, I believe that only 41 will be unique between multiple applications of the effect. In other words, this is the main candidate for compression.
It so happened that R1Q2 (Quake 2 backward compatible engine with advanced network protocol) has a Zlib compression code. I could pick up this code, or at least keep a close eye on it.
But is Zlib necessarily the best choice here? I can imagine at least one alternative to LZMA, and it would be easier.
Requirements:
- It should be very fast (it should have very low performance when starting more than 100 times per second.)
- You need to copy as much data as possible in 2800 bytes.
- Small metadata size
- GPL compatible
Zlib looks good, but is there anything better? Keep in mind that none of these codes have yet been merged, so there are many opportunities for experimentation.
Thanks, -Max
EDIT: Thanks to those who suggested compiling the scripts into bytecode. I had to clearly understand this - yes, I do it. If you like, you can view the corresponding source code on my website, although it is still not a “lure”.
This is the server side code:
Lua: http://meliaserlow.dyndns.tv:8000/alienarena/lua_source/lua/scriptedfx.lua
C: http://meliaserlow.dyndns.tv:8000/alienarena/lua_source/game/g_scriptedfx.c
For a specific example of the script that I posted, it gets a source of 1172 bytes to 405 bytes - still not small enough. (Keep in mind that I want as many as possible in 2800 bytes!)
EDIT2: There is no guarantee that any given package will arrive. Each package should contain a "state of the world", without relying on the information transmitted in previous packages. Typically, these scripts will be used to transmit "eye candy." If there is no room for one, it drops out of the package and it does not really matter. But if too much falls out, things begin to look strange visually, and this is undesirable.