Changeset 1047
- Timestamp:
- Apr 14, 2008, 12:20:27 AM (17 years ago)
- Location:
- code/branches/network/src/network
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/Server.cc
r1008 r1047 114 114 updateGamestate(); 115 115 116 //sleep(1); // TODO remove116 sleep(1); // TODO remove 117 117 return; 118 118 } -
code/branches/network/src/network/Synchronisable.cc
r1018 r1047 41 41 void Synchronisable::registerVar(const void *var, int size, variableType t){ 42 42 // create temporary synch.Var struct 43 synchronisableVariable temp={size, var, t}; 43 synchronisableVariable *temp = new synchronisableVariable; 44 temp->size = size; 45 temp->var = var; 46 temp->type = t; 47 COUT(5) << "registering var with size: " << temp->size << " and type: " << temp->type << std::endl; 44 48 // increase datasize 45 49 datasize+=sizeof(int)+size; … … 105 109 syncData Synchronisable::getData(unsigned char *mem){ 106 110 //std::cout << "inside getData" << std::endl; 107 std::list< SYNCVAR>::iterator i;111 std::list<synchronisableVariable *>::iterator i; 108 112 syncData retVal; 109 113 retVal.objectID=this->objectID; … … 115 119 for(i=syncList.begin(); n<datasize && i!=syncList.end(); ++i){ 116 120 //(std::memcpy(retVal.data+n, (const void*)(&(i->size)), sizeof(int)); 117 memcpy( (void *)(retVal.data+n), (const void *)&(i->size), sizeof(int) );121 memcpy( (void *)(retVal.data+n), (const void *)&((*i)->size), sizeof(int) ); 118 122 n+=sizeof(int); 119 switch( i->type){123 switch((*i)->type){ 120 124 case DATA: 121 std::memcpy( (void *)(retVal.data+n), (const void*)( i->var), i->size);122 n+= i->size;125 std::memcpy( (void *)(retVal.data+n), (const void*)((*i)->var), (*i)->size); 126 n+=(*i)->size; 123 127 break; 124 128 case STRING: 125 std::memcpy( retVal.data+n, (const void*)( ( (std::string *) i->var)->c_str()), ( (std::string *)i->var )->length()+1);126 n+=((std::string *) i->var)->length()+1;129 std::memcpy( retVal.data+n, (const void*)( ( (std::string *) (*i)->var)->c_str()), ( (std::string *)(*i)->var )->length()+1); 130 n+=((std::string *) (*i)->var)->length()+1; 127 131 break; 128 132 } … … 138 142 bool Synchronisable::updateData(syncData vars){ 139 143 unsigned char *data=vars.data; 140 std::list<synchronisableVariable>::iterator i; 141 for(i=syncList.begin(); i!=syncList.end(); i++){ 142 if(*(int *)data==i->size || i->type==STRING){ 143 switch(i->type){ 144 std::list<synchronisableVariable *>::iterator i; 145 if(syncList.empty()){ 146 COUT(4) << "Synchronisable::updateData syncList is empty" << std::endl; 147 return false; 148 } 149 COUT(5) << "Synchronisable: synchronising data" << std::endl; 150 i=syncList.begin(); 151 COUT(5) << "element size: " << (*syncList.begin())->size << std::endl; 152 COUT(5) << "*i.size" << (*i)->size << std::endl; 153 for(; i!=syncList.end(); i++){ 154 if(*(int *)data==(*i)->size || (*i)->type==STRING){ 155 switch((*i)->type){ 144 156 case DATA: 145 157 data+=sizeof(int); 146 memcpy((void*) i->var, data, i->size);147 data+= i->size;158 memcpy((void*)(*i)->var, data, (*i)->size); 159 data+=(*i)->size; 148 160 break; 149 161 case STRING: 150 i->size = *(int *)data;162 (*i)->size = *(int *)data; 151 163 data+=sizeof(int); 152 *((std::string *) i->var) = std::string((const char*)data);153 data += i->size;164 *((std::string *)((*i)->var)) = std::string((const char*)data); 165 data += (*i)->size; 154 166 break; 155 167 } … … 166 178 int Synchronisable::getSize(){ 167 179 int tsize=0; 168 std::list< SYNCVAR>::iterator i;180 std::list<synchronisableVariable *>::iterator i; 169 181 for(i=syncList.begin(); i!=syncList.end(); i++){ 170 switch( i->type){182 switch((*i)->type){ 171 183 case DATA: 172 184 tsize+=sizeof(int); 173 tsize+= i->size;185 tsize+=(*i)->size; 174 186 break; 175 187 case STRING: 176 188 tsize+=sizeof(int); 177 tsize+=((std::string *) i->var)->length()+1;189 tsize+=((std::string *)(*i)->var)->length()+1; 178 190 break; 179 191 } -
code/branches/network/src/network/Synchronisable.h
r1008 r1047 63 63 /* bool removeObject(Iterator<Synchronisable> it);*/ 64 64 65 std::list< SYNCVAR> syncList;65 std::list<synchronisableVariable *> syncList; 66 66 int datasize; 67 67 };
Note: See TracChangeset
for help on using the changeset viewer.