| 1 | = Synchronisable = |
| 2 | The most important part of the Network API is the Synchronisable Class (see also [wiki:network/Synchronisable Synchronisable]): |
| 3 | * This class provides the functionality for objects to get synchronised over the network: |
| 4 | * REGISTERDATA/REGISTERSTRING: these functions register a variable (to the Network Engine) that needs synchronisation |
| 5 | * setObjectMode: this function sets the direction of synchronisation (server->client / server<->client / server<-client) |
| 6 | * Every class that needs synchronisation must fullfill some dependencies: |
| 7 | * It must (public) inherit from Synchronisable |
| 8 | * It must have a default constructor |
| 9 | * All steps in object creation that need data (from the levelfile or the network) must be in the create() function |
| 10 | * It must implement the following functions: |
| 11 | * registerAllVariables: register all variables (currently only basic types and strings), that need synchronisation, to the network engine by calling REGISTERDATA and/or REGISTERSTRING |
| 12 | * create: (as described above) |
| 13 | * set appropriate synchronisation direction (default: server->client) by calling setObjectMode |
| 14 | |
| 15 | |
| 16 | ''' Synchronisable functions:'''[[BR]] |
| 17 | ''REGISTERDATA(varname)''[[BR]] |
| 18 | Use this makro to synchronise a membervariable of a class (like position, velocity, ...). This makro sets the sync-direction of the variable to server->client |
| 19 | {{{ |
| 20 | int SomeClass::i; // membervariable i |
| 21 | REGISTERDATA(i); |
| 22 | }}} |
| 23 | ''REGISTERDATA_WITHMODE(varname, mode)''[[BR]] |
| 24 | Use this makro if you want to sync a variable using a different direction than the default. |
| 25 | {{{ |
| 26 | int SomeClass::i; //membervariable i |
| 27 | REGISTERDATA_WITHMODE(i, network::direction::toclient); //same as REGISTERDATA(i) |
| 28 | //or |
| 29 | REGISTERDATA_WITHMODE(i, network::direction::toserver); //sync i only to the server (be carefull when using this) |
| 30 | //or |
| 31 | REGISTERDATA_WITHMODE(i, network::direction::bidirectional); //sync i in both directions |
| 32 | }}} |
| 33 | |
| 34 | ''REGISTERSTRING(stringname)''[[BR]] |
| 35 | same as REGISTERDATA but for strings |
| 36 | |
| 37 | ''REGISTERSTRING_WITHMODE(stringname, mode)''[[BR]] |
| 38 | same as REGISTERDATA_WITHMODE but for strings |
| 39 | |
| 40 | ''setObjectMode''[[BR]] |
| 41 | this sets the sync direction of the whole object (default: server->client). |
| 42 | '''Note:''' if you don't call setObjectMode with a value other than network::direction::toclient then the variables will only be synchronised to the client (if at all) |