What data structure / algorithm will allow me to send a list of keywords / values ​​using the least number of bits?

I have server objects having corresponding client objects. The data to be stored in synchronization is located inside the key / value dictionary of the server object. In order for client objects to synchronize with common objects, I want the server to send the dictionary key / value for each frame for each object.

What data structure / algorithm will allow me to list the key / value dictionaries using the fewest bits?

Bonus Limit 1: for each type of object, the values ​​of some keys change more often than others. Bonus Limit 2: Server-side memory usage is relatively expensive.

+6
source share
2 answers

You do not need to send the entire dictionary. Instead, send only what has changed.

You do not need to send it in every frame. . Instead, send it at regular intervals, which have nothing to do with frame rate.

An important idea that should be taken into account in the second paragraph is that clients can predict changes in the state of the game - the game can continue to simulate between receiving information from the server, and then only correct errors after it again receives reliable information from the server.

+4
source

There are no special data structures or algorithms. Limited data transfer is sufficient.

Example data (in the form of a string C, pay attention to "\\", which is actually "\"): key1;value1;key2;value2;key3\\;with delimiter inside it;value3;\0

You can choose which keys you send, it is easy to read * and write **, it takes up a bit of memory and can even be compressed (since this is just one stream of bytes).

* - Reading:

 while( peekbyte() != 0 ) { key = readuntil( ';' ); // checks if previous byte isn't "\" while looking for char. value = readuntil( ';' ); add( key, value ); } 

** - Record:

 foreach( key in keylist ) { write( replace( ';', '\\;', key ) ); write( replace( ';', '\\;', dict[ key ] ) ); } write( '\0' ); 
0
source

All Articles