Changeset 1521 for code/branches
- Timestamp:
- Jun 2, 2008, 11:08:46 PM (16 years ago)
- Location:
- code/branches/network/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/Synchronisable.cc
r1505 r1521 45 45 46 46 #include "core/CoreIncludes.h" 47 // #include "core/Identifier.h" 47 48 48 49 namespace network … … 66 67 67 68 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; 68 73 } 69 74 … … 87 92 * @param size size of the datatype the variable consists of 88 93 */ 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){ 90 95 // create temporary synch.Var struct 91 96 synchronisableVariable *temp = new synchronisableVariable; … … 94 99 temp->mode = mode; 95 100 temp->type = t; 101 temp->callback = cb; 96 102 COUT(5) << "Syncronisable::registering var with size: " << temp->size << " and type: " << temp->type << std::endl; 97 103 // increase datasize … … 218 224 } 219 225 COUT(5) << "Synchronisable: element size: " << (*i)->size << " type: " << (*i)->type << std::endl; 226 bool callback=false; 220 227 switch((*i)->type){ 221 228 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; 222 232 memcpy((void*)(*i)->var, data, (*i)->size); 223 233 data+=(*i)->size; … … 227 237 COUT(5) << "string size: " << (*i)->size << std::endl; 228 238 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; 229 242 *((std::string *)((*i)->var)) = std::string((const char*)data); 230 243 COUT(5) << "synchronisable: char: " << (const char*)data << " string: " << std::string((const char*)data) << std::endl; … … 232 245 break; 233 246 } 247 // call the callback function, if defined 248 if(callback) 249 (*i)->callback->call(); 234 250 } 235 251 return true; -
code/branches/network/src/network/Synchronisable.h
r1505 r1521 27 27 */ 28 28 29 //30 // C++ Interface: synchronisable31 //32 // Description:33 //34 //35 // Author: Oliver Scheuss, (C) 200736 //37 // Copyright: See COPYING file that comes with this distribution38 //39 //40 29 #ifndef _Synchronisable_H__ 41 30 #define _Synchronisable_H__ … … 45 34 #include <list> 46 35 #include "core/OrxonoxClass.h" 36 #include "NetworkCallback.h" 47 37 48 38 namespace network … … 65 55 void *var; 66 56 variableType type; 57 NetworkCallbackBase *callback; 67 58 }SYNCVAR; 68 59 … … 81 72 int classID; 82 73 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); 84 75 // syncData getData(); 85 76 syncData getData(unsigned char *mem, int mode=0x0); -
code/branches/network/src/orxonox/objects/SpaceShip.cc
r1516 r1521 69 69 SpaceShip* SpaceShip::instance_s; 70 70 71 71 72 SpaceShip *SpaceShip::getLocalShip(){ 72 73 Iterator<SpaceShip> it; … … 163 164 164 165 void SpaceShip::registerAllVariables(){ 165 registerVar( &camName_, camName_.length()+1, network::STRING, 0x1 );166 registerVar( &camName_, camName_.length()+1, network::STRING, 0x1 ); 166 167 registerVar( &maxSpeed_, sizeof(maxSpeed_), network::DATA, 0x1); 167 168 registerVar( &maxSideAndBackSpeed_, sizeof(maxSideAndBackSpeed_), network::DATA, 0x1); -
code/branches/network/src/orxonox/objects/SpaceShip.h
r1505 r1521 44 44 { 45 45 public: 46 46 47 47 48 static SpaceShip *getLocalShip();
Note: See TracChangeset
for help on using the changeset viewer.