Changes between Version 7 and Version 8 of code/howto/Synchronisable
- Timestamp:
- Sep 29, 2008, 2:22:47 PM (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
code/howto/Synchronisable
v7 v8 2 2 This is a step-by-step guide to make a class XYZ synchronisable. 3 3 * Synchronisable classes are registered to the network engine to be transfered/synched between client and server. 4 * If you want your class to get transfered, you have to ''register'' every important variable to the network (e.g. position, speed, health, ...). But only register variables that are absolutely neccessary (e.g. no local variables ).4 * If you want your class to get transfered, you have to ''register'' every important variable to the network (e.g. position, speed, health, ...). But only register variables that are absolutely neccessary (e.g. no local variables and '''no temporary copies/variables'''). 5 5 * The default transfer ''direction'' of variables (and objects) is from server to the clients only. If you want to change this for a certain variable (and object), call REGISTERDATA_WITHDIR(varname, direction) or REGISTERSTRING_WITHDIR(stringname, direction) instead of REGISTERDATA or REGISTERSTRING.[[br]] 6 6 See also [wiki:network/Synchronisable Synchronisable reference] for more information. … … 19 19 {{{ 20 20 void XYZ::registerAllVariables(){ 21 REGISTERDATA(somevariable);22 REGISTERSTRING(meshSrcName_);21 REGISTERDATA(somevariable); 22 REGISTERSTRING(meshSrcName_); 23 23 } 24 24 }}} … … 26 26 {{{ 27 27 XYZ::XYZ(){ 28 registerAllVariables();28 registerAllVariables(); 29 29 // do not work with synchronisable variables in your constructor (except initialisation) 30 30 } … … 33 33 {{{ 34 34 bool XYZ::create(){ 35 this->ogreMesh_.setMesh(meshSrcName_);35 this->ogreMesh_.setMesh(meshSrcName_); 36 36 } 37 37 }}} … … 73 73 //Memberfunctions 74 74 void registerAllVariables(){ 75 // !!! Note: this only works, because getPosition returns a reference and not a copy !!! 76 // !!! Never use REGISTERDATA/STRING with local/temporary copies !!! 75 77 REGISTERDATA_WITHDIR(node_->getPosition().x, network::direction::bidirectional); 76 78 REGISTERDATA_WITHDIR(node_->getPosition().y, network::direction::bidirectional); … … 99 101 100 102 == Example class that inherits indirectly from Synchronisable == #indirect 101 Th ese kind of classes only haveto do some steps:103 This kind of class only has to do some steps: 102 104 {{{ 103 105 class ABC: public XYZ {