What data-structure/algorithm will allow me to send a list of key/value dictionaries using the least amount of bits?
Asked Answered
H

2

6

I have server objects that have corresponding client objects. The data to be kept in sync is inside the server object's key/value dictionary. To keep the client objects in sync with the sever objects, I want the server to send the key/value dictionary every frame for each object.

What data-structure/algorithm will allow me to send a list of key/value dictionaries using the least amount of bits?

Bonus constraint 1: For each type of object, the values of some keys change more often than others. Bonus constraint 2: Memory usage on the server side is relatively expensive.

Hysterogenic answered 22/10, 2012 at 11:9 Comment(1)
Would you please accept an answer? (Given that you still visit, of course.)Embryectomy
E
4

You don't need to send the whole dictionary. Instead, send just what's changed.

You don't need to send it each frame. Instead, send it on regular intervals that have nothing to do with the frame rate.

An important idea to keep in mind in the second point is that clients can predict changes in game state - the game can go on to be simulated in between receiving information from the server, and then only has to correct the mistakes after it receives authoritative information from the server again.

Embryectomy answered 22/10, 2012 at 11:17 Comment(0)
W
0

There are no special data structures or algorithms. Transferring delimited data is enough.

Example data (as a C string, note the "\\" which is actually a "\"): key1;value1;key2;value2;key3\\;with delimiter inside it;value3;\0

You can choose which keys you send, it's easy to read* and write**, takes little memory and can even be compressed (since it's just one stream of bytes).

*-Read:

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

**-Write:

foreach( key in keylist )
{
    write( replace( ';', '\\;', key ) );
    write( replace( ';', '\\;', dict[ key ] ) );
}
write( '\0' );
Weidar answered 22/10, 2012 at 11:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.