Changeset 565 for code/branches/FICN/src/network
- Timestamp:
- Dec 17, 2007, 10:39:12 AM (17 years ago)
- Location:
- code/branches/FICN/src/network
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/FICN/src/network/Client.cc
r514 r565 127 127 if(!isConnected) 128 128 return false; 129 if(client_connection.addPacket(pck_gen.chatMessage( message.c_str() ))) ;129 if(client_connection.addPacket(pck_gen.chatMessage( message.c_str() ))) 130 130 return client_connection.sendPackets(); 131 131 // send packets -
code/branches/FICN/src/network/Synchronisable.cc
r531 r565 26 26 datasize=0; 27 27 objectID=idCounter++; 28 //registerAllVariables();28 // registerAllVariables(); 29 29 } 30 30 … … 41 41 * @param size size of the datatype the variable consists of 42 42 */ 43 void Synchronisable::registerVar(const void *var, int size ){43 void Synchronisable::registerVar(const void *var, int size, variableType t){ 44 44 // create temporary synch.Var struct 45 synchronisableVariable temp={size, var };45 synchronisableVariable temp={size, var, t}; 46 46 // increase datasize 47 47 datasize+=sizeof(int)+size; … … 65 65 for(i=syncList.begin(); i!=syncList.end(); i++){ 66 66 // increase size (size of variable and size of size of variable ;) 67 totalsize+=sizeof(int)+i->size; 67 if(i->type == STRING) 68 totalsize+=sizeof(int)+((std::string *)i->var)->length()+1; 69 else 70 totalsize+=sizeof(int)+i->size; 68 71 } 69 72 syncData retVal; … … 77 80 int n=0; 78 81 for(i=syncList.begin(); n<totalsize && i!=syncList.end(); i++){ 79 //CHANGED: i->size TO (const void*)(&(i->size)) memcpy WANTS A CONST VOID* SO CONVERT INT TO CONST VOID*80 82 std::memcpy(retVal.data+n, (const void*)(i->size), sizeof(int)); 81 83 n+=sizeof(int); 82 //CHANGED: i->var TO (const void*)(&(i->var)) SINCE var IS A POINTER, NO & BEFORE i 83 std::memcpy(retVal.data+n, (const void*)(i->var), i->size); 84 n+=i->size; 84 switch(i->type){ 85 case STRING: 86 std::memcpy(retVal.data+n, (const void *)(((std::string *)i->var)->c_str()), ((std::string *)i->var)->length()+1); 87 n+=((std::string *)i->var)->length()+1; 88 break; 89 case DATA: 90 std::memcpy(retVal.data+n, ((const void*)i->var), i->size); 91 n+=i->size; 92 break; 93 } 85 94 } 86 95 return retVal; … … 107 116 int n=0; 108 117 for(i=syncList.begin(); n<datasize && i!=syncList.end(); i++){ 109 //CHANGED: i->size TO (const void*)(&(i->size)) memcpy WANTS A CONST VOID* SO CONVERT INT TO CONST VOID*110 118 std::memcpy(retVal.data+n, (const void*)(i->size), sizeof(int)); 111 119 n+=sizeof(int); 112 //CHANGED: i->var TO (const void*)(&(i->var)) SINCE var IS A POINTER, NO & BEFORE i 113 std::memcpy(retVal.data+n, (const void*)(i->var), i->size); 114 n+=i->size; 120 switch(i->type){ 121 case DATA: 122 std::memcpy(retVal.data+n, (const void*)(i->var), i->size); 123 n+=i->size; 124 break; 125 case STRING: 126 std::memcpy(retVal.data+n, (const void*)(((std::string *)i->var)->c_str()), ((std::string *)i->var)->length()+1); 127 n+=((std::string *) i->var)->length()+1; 128 break; 129 } 115 130 } 116 131 return retVal; … … 126 141 std::list<synchronisableVariable>::iterator i; 127 142 for(i=syncList.begin(); i!=syncList.end(); i++){ 128 if((int)*data==i->size){ 129 data+=sizeof(int); 130 //CHANGED: THIS FROM i->var TO (void*)i->var SINCE var IS A CONST VOID* AND memcpy NEEDS A VOID* AS FIRST ARGUMENT 131 memcpy((void*)i->var, data, i->size); 132 data+=i->size; 143 if((int)*data==i->size || i->type==STRING){ 144 switch(i->type){ 145 case DATA: 146 data+=sizeof(int); 147 memcpy((void*)i->var, data, i->size); 148 data+=i->size; 149 break; 150 case STRING: 151 i->size = (int)*data; 152 data+=sizeof(int); 153 *((std::string *)i->var) = std::string((const char*)data); 154 data += i->size; 155 break; 156 } 133 157 } else 134 158 return false; //there was some problem with registerVar … … 142 166 */ 143 167 int Synchronisable::getSize(){ 144 return datasize; 168 int tsize=0; 169 std::list<synchronisableVariable>::iterator i; 170 for(i=syncList.begin(); i!=syncList.end(); i++){ 171 switch(i->type){ 172 case DATA: 173 tsize+=i->size; 174 break; 175 case STRING: 176 tsize+=((std::string *)i->var)->length()+1; 177 break; 178 } 179 } 180 return tsize; 145 181 } 146 182 -
code/branches/FICN/src/network/Synchronisable.h
r496 r565 15 15 #include <list> 16 16 #include <iostream> 17 #include <string> 17 18 18 19 #include "orxonox/core/CoreIncludes.h" … … 21 22 namespace network { 22 23 24 enum variableType{ 25 DATA, 26 STRING, 27 }; 23 28 24 29 struct syncData{ … … 32 37 int size; 33 38 const void *var; 39 variableType type; 34 40 }SYNCVAR; 35 41 … … 40 46 * @author Oliver Scheuss 41 47 */ 42 class Synchronisable : public orxonox::OrxonoxClass{48 class Synchronisable : virtual public orxonox::OrxonoxClass{ 43 49 public: 44 Synchronisable();45 50 46 51 virtual ~Synchronisable(); … … 48 53 int classID; 49 54 50 void registerVar(const void *var, int size );55 void registerVar(const void *var, int size, variableType t); 51 56 syncData getData(); 52 57 syncData getData(unsigned char *mem); 53 58 int getSize(); 54 59 bool updateData(syncData vars); 55 virtual void registerAllVariables() = 0; 56 60 virtual void registerAllVariables()=0; 61 virtual bool create(){return true;} 62 protected: 63 Synchronisable(); 57 64 private: 58 65 /* bool removeObject(Iterator<Synchronisable> it);*/
Note: See TracChangeset
for help on using the changeset viewer.