Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 499
likeaneel Avatar asked Oct 22 '12 11:10

likeaneel


People also ask

Which data structure can you use as keys for your dictionary?

Dictionaries are often implemented as hash tables. Each element stored in a dictionary is identified by a key of type K. Dictionary represents a mapping from keys to values. Dictionaries have numerous applications.

Which data structure is commonly used to store a dictionary?

Different languages enforce different type restrictions on keys and values in a dictionary. Dictionaries are often implemented as hash tables.

Which data structure would you use to store a dynamically ordered collection of values so you can insert and traverse them the most efficiently?

A dynamic array is a good choice if the accesses are random and insertion/deletion is at the end.

Which data type is used for dictionary?

Python's dictionaries are kind of hash table type. They work like associative arrays or hashes found in Perl and consist of key-value pairs. A dictionary key can be almost any Python type, but are usually numbers or strings. Values, on the other hand, can be any arbitrary Python object.


1 Answers

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.

like image 109
corazza Avatar answered Sep 22 '22 15:09

corazza