Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Version 7 and Version 8 of code/howto/Synchronisable


Ignore:
Timestamp:
Sep 29, 2008, 2:22:47 PM (16 years ago)
Author:
scheusso
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • code/howto/Synchronisable

    v7 v8  
    22This is a step-by-step guide to make a class XYZ synchronisable.
    33 * 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''').
    55 * 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]]
    66See also [wiki:network/Synchronisable Synchronisable reference] for more information.
     
    1919{{{
    2020void XYZ::registerAllVariables(){
    21 REGISTERDATA(somevariable);
    22 REGISTERSTRING(meshSrcName_);
     21  REGISTERDATA(somevariable);
     22  REGISTERSTRING(meshSrcName_);
    2323}
    2424}}}
     
    2626{{{
    2727XYZ::XYZ(){
    28 registerAllVariables();
     28  registerAllVariables();
    2929// do not work with synchronisable variables in your constructor (except initialisation)
    3030}
     
    3333{{{
    3434bool XYZ::create(){
    35 this->ogreMesh_.setMesh(meshSrcName_);
     35  this->ogreMesh_.setMesh(meshSrcName_);
    3636}
    3737}}}
     
    7373  //Memberfunctions
    7474  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 !!!
    7577    REGISTERDATA_WITHDIR(node_->getPosition().x, network::direction::bidirectional);
    7678    REGISTERDATA_WITHDIR(node_->getPosition().y, network::direction::bidirectional);
     
    99101
    100102== Example class that inherits indirectly from Synchronisable == #indirect
    101 These kind of classes only have to do some steps:
     103This kind of class only has to do some steps:
    102104{{{
    103105class ABC: public XYZ {