Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1521 for code/branches


Ignore:
Timestamp:
Jun 2, 2008, 11:08:46 PM (16 years ago)
Author:
scheusso
Message:

we are now able to define callback actions, for each seperate variable of a synchronisable, that has changed

Location:
code/branches/network/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/network/Synchronisable.cc

    r1505 r1521  
    4545
    4646#include "core/CoreIncludes.h"
     47// #include "core/Identifier.h"
    4748
    4849namespace network
     
    6667
    6768  Synchronisable::~Synchronisable(){
     69    // delete callback function objects
     70    if(!orxonox::Identifier::isCreatingHierarchy())
     71      for(std::list<synchronisableVariable *>::iterator it = syncList->begin(); it!=syncList->end(); it++)
     72        delete (*it)->callback;
    6873  }
    6974 
     
    8792  * @param size size of the datatype the variable consists of
    8893  */
    89   void Synchronisable::registerVar(void *var, int size, variableType t, int mode){
     94  void Synchronisable::registerVar(void *var, int size, variableType t, int mode, NetworkCallbackBase *cb){
    9095    // create temporary synch.Var struct
    9196    synchronisableVariable *temp = new synchronisableVariable;
     
    9499    temp->mode = mode;
    95100    temp->type = t;
     101    temp->callback = cb;
    96102    COUT(5) << "Syncronisable::registering var with size: " << temp->size << " and type: " << temp->type << std::endl;
    97103    // increase datasize
     
    218224      }
    219225      COUT(5) << "Synchronisable: element size: " << (*i)->size << " type: " << (*i)->type << std::endl;
     226      bool callback=false;
    220227      switch((*i)->type){
    221228      case DATA:
     229        if((*i)->callback) // check whether this variable changed (but only if callback was set)
     230          if(strncmp((char *)(*i)->var, (char *)data, (*i)->size)!=0)
     231            callback=true;
    222232        memcpy((void*)(*i)->var, data, (*i)->size);
    223233        data+=(*i)->size;
     
    227237        COUT(5) << "string size: " << (*i)->size << std::endl;
    228238        data+=sizeof(int);
     239        if((*i)->callback) // check whether this string changed
     240          if( *(std::string *)((*i)->var) != std::string((char *)data) )
     241            callback=true;
    229242        *((std::string *)((*i)->var)) = std::string((const char*)data);
    230243        COUT(5) << "synchronisable: char: " << (const char*)data << " string: " << std::string((const char*)data) << std::endl;
     
    232245        break;
    233246      }
     247      // call the callback function, if defined
     248      if(callback)
     249        (*i)->callback->call();
    234250    }
    235251    return true;
  • code/branches/network/src/network/Synchronisable.h

    r1505 r1521  
    2727 */
    2828
    29 //
    30 // C++ Interface: synchronisable
    31 //
    32 // Description:
    33 //
    34 //
    35 // Author:  Oliver Scheuss, (C) 2007
    36 //
    37 // Copyright: See COPYING file that comes with this distribution
    38 //
    39 //
    4029#ifndef _Synchronisable_H__
    4130#define _Synchronisable_H__
     
    4534#include <list>
    4635#include "core/OrxonoxClass.h"
     36#include "NetworkCallback.h"
    4737
    4838namespace network
     
    6555    void *var;
    6656    variableType type;
     57    NetworkCallbackBase *callback;
    6758  }SYNCVAR;
    6859
     
    8172    int classID;
    8273
    83     void registerVar(void *var, int size, variableType t, int mode=1);
     74    void registerVar(void *var, int size, variableType t, int mode=1, NetworkCallbackBase *cb=0);
    8475    //  syncData getData();
    8576    syncData getData(unsigned char *mem, int mode=0x0);
  • code/branches/network/src/orxonox/objects/SpaceShip.cc

    r1516 r1521  
    6969    SpaceShip* SpaceShip::instance_s;
    7070
     71   
    7172    SpaceShip *SpaceShip::getLocalShip(){
    7273      Iterator<SpaceShip> it;
     
    163164
    164165    void SpaceShip::registerAllVariables(){
    165       registerVar( &camName_, camName_.length()+1, network::STRING, 0x1);
     166      registerVar( &camName_, camName_.length()+1, network::STRING, 0x1 );
    166167      registerVar( &maxSpeed_, sizeof(maxSpeed_), network::DATA, 0x1);
    167168      registerVar( &maxSideAndBackSpeed_, sizeof(maxSideAndBackSpeed_), network::DATA, 0x1);
  • code/branches/network/src/orxonox/objects/SpaceShip.h

    r1505 r1521  
    4444    {
    4545        public:
     46         
    4647
    4748            static SpaceShip *getLocalShip();
Note: See TracChangeset for help on using the changeset viewer.