- Timestamp:
- Sep 8, 2008, 2:21:00 PM (16 years ago)
- Location:
- code/branches/network
- Files:
-
- 2 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/bin/levels/sample.oxw
r1680 r1742 22 22 <NPC position="0,-200,450" scale="1" mesh="razor.mesh"/> 23 23 <NPC position="100,0,400" scale="1" mesh="razor.mesh"/> 24 25 <?lua26 for i = 1, 10, 127 do ?>28 <SpaceShipAI position="<?lua print(math.random() * 6000 - 3000) ?>,<?lua print(math.random() * 6000 - 3000) ?>,<?lua print(math.random() * 6000 - 3000) ?>" scale="10" yawpitchroll="0,0,0" mesh="assff.mesh" maxSpeed="500" maxSideAndBackSpeed="50" maxRotation="1.0" transAcc="200" rotAcc="3.0" transDamp="75" rotDamp="1.0" />29 <?lua30 end31 ?>32 24 33 25 <!--Model name="starship" position="200,0,500" scale="10" mesh="starship.mesh" yawpitchroll="-90,-90,0" /> -
code/branches/network/src/network/GamestateClient.cc
r1741 r1742 73 73 return 0; 74 74 int id = GAMESTATEID_INITIAL; 75 //bool b = saveShipCache();75 bool b = saveShipCache(); 76 76 packet::Gamestate *processed = processGamestate(tempGamestate_); 77 77 assert(processed); … … 81 81 last_diff_ = processed->getBaseID(); 82 82 last_gamestate_ = processed->getID(); 83 //if(b)84 //loadShipCache();83 if(b) 84 loadShipCache(); 85 85 id = processed->getID(); 86 86 cleanup(); … … 134 134 if(myShip_){ 135 135 // unsigned char *data = new unsigned char[myShip_->getSize()]; 136 int size=myShip_->getSize (0x1);136 int size=myShip_->getSize2(0, 0x1); 137 137 if(size==0) 138 138 return false; 139 139 shipCache_ = new unsigned char [size]; 140 140 unsigned char *temp = shipCache_; 141 if(!myShip_->getData 2(temp, 0x1))141 if(!myShip_->getData(temp, 0, 0x1)) 142 142 COUT(3) << "could not save shipCache" << std::endl; 143 143 return true; … … 157 157 158 158 packet::Gamestate *GamestateClient::processGamestate(packet::Gamestate *gs){ 159 if(gs->isCompressed()){ 160 bool b = gs->decompressData(); 161 assert(b); 162 } 159 if(gs->isCompressed()) 160 assert(gs->decompressData()); 163 161 if(gs->isDiffed()){ 164 162 packet::Gamestate *base = gamestateMap_[gs->getBaseID()]; -
code/branches/network/src/network/GamestateManager.cc
r1741 r1742 131 131 packet::Gamestate *gs; 132 132 int gID = ClientInformation::findClient(clientID)->getGamestateID(); 133 COUT(4) << "G.St.Man: popgamestate: sending gstate_id: " << id_ << " diffed from: " << gID << std::endl; 134 // COUT(3) << "gamestatemap: " << &gameStateMap << std::endl; 133 //COUT(4) << "G.St.Man: popgamestate: sending gstate_id: " << id_ << " diffed from: " << gID << std::endl; 135 134 //chose wheather the next gamestate is the first or not 136 135 if(gID != GAMESTATEID_INITIAL){ … … 147 146 gs = new packet::Gamestate(*reference); 148 147 } 149 #ifndef NDEBUG150 packet::Gamestate *ns = new packet::Gamestate(*gs);151 ns->compressData();152 ns->decompressData();153 assert(*gs==*ns);154 delete ns;155 #endif156 148 assert(gs->compressData()); 157 149 return gs; -
code/branches/network/src/network/Server.cc
r1739 r1742 264 264 //std::cout << "adding gamestate" << std::endl; 265 265 gs->setClientID(cid); 266 assert(gs->compressData());267 266 if ( !gs->send() ){ 268 267 COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl; … … 298 297 return false; 299 298 } 300 if(temp->prev()->getBegin()) { //not good if you use anything else than insertBack 301 temp->prev()->setID(0); //bugfix: not necessary but usefull 299 if(temp==ClientInformation::getBegin()) { //not good if you use anything else than insertBack 302 300 temp->setID(1); 303 301 } -
code/branches/network/src/network/Synchronisable.cc
r1741 r1742 63 63 static int idCounter=0; 64 64 datasize=0; 65 objectFrequency_=1; 65 66 objectID=idCounter++; 66 67 syncList = new std::list<synchronisableVariable *>; … … 94 95 objectID = *(unsigned int*)(mem+sizeof(unsigned int)); 95 96 classID = *(unsigned int*)(mem+2*sizeof(unsigned int)); 97 98 if(size==3*sizeof(unsigned int)) //not our turn, dont do anything 99 return true; 96 100 97 101 orxonox::Identifier* id = ID(classID); … … 141 145 syncList->push_back(temp); 142 146 } 143 144 145 /**146 * This function takes all SynchronisableVariables out of the Synchronisable and saves it into a syncData struct147 * Difference to the above function:148 * takes a pointer to already allocated memory (must have at least getSize bytes length)149 * structure of the bitstream:150 * (var1_size,var1,var2_size,var2,...)151 * varx_size: size = sizeof(int)152 * varx: size = varx_size153 * @return data containing all variables and their sizes154 */155 syncData Synchronisable::getData(unsigned char *mem, int mode){156 //std::cout << "inside getData" << std::endl;157 if(mode==0x0)158 mode=state_;159 if(classID==0)160 COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl;161 this->classID=this->getIdentifier()->getNetworkID();162 std::list<synchronisableVariable *>::iterator i;163 syncData retVal;164 retVal.objectID=this->objectID;165 retVal.classID=this->classID;166 retVal.length=getSize();167 COUT(5) << "Synchronisable getting data from objectID: " << retVal.objectID << " classID: " << retVal.classID << " length: " << retVal.length << std::endl;168 retVal.data=mem;169 // copy to location170 int n=0; //offset171 for(i=syncList->begin(); n<datasize && i!=syncList->end(); ++i){172 //(std::memcpy(retVal.data+n, (const void*)(&(i->size)), sizeof(int));173 if( ((*i)->mode & mode) == 0 ){174 COUT(5) << "not getting data: " << std::endl;175 continue; // this variable should only be received176 }177 switch((*i)->type){178 case DATA:179 memcpy( (void *)(retVal.data+n), (void*)((*i)->var), (*i)->size);180 n+=(*i)->size;181 break;182 case STRING:183 memcpy( (void *)(retVal.data+n), (void *)&((*i)->size), sizeof(int) );184 n+=sizeof(int);185 const char *data = ( ( *(std::string *) (*i)->var).c_str());186 memcpy( retVal.data+n, (void*)data, (*i)->size);187 COUT(5) << "synchronisable: char: " << (const char *)(retVal.data+n) << " data: " << data << " string: " << *(std::string *)((*i)->var) << std::endl;188 n+=(*i)->size;189 break;190 }191 }192 return retVal;193 }194 147 195 148 /** 196 149 * This function takes all SynchronisableVariables out of the Synchronisable and saves it into a syncData struct 197 * Difference to the above function:150 * Difference to the above function: 198 151 * takes a pointer to already allocated memory (must have at least getSize bytes length) 199 * structure of the bitstream:152 * structure of the bitstream: 200 153 * (var1_size,var1,var2_size,var2,...) 201 154 * varx_size: size = sizeof(int) … … 203 156 * @return data containing all variables and their sizes 204 157 */ 205 bool Synchronisable::getData 2(unsigned char*& mem, int mode){158 bool Synchronisable::getData(unsigned char*& mem, unsigned int id, int mode){ 206 159 //std::cout << "inside getData" << std::endl; 207 160 unsigned int tempsize = 0; … … 210 163 if(classID==0) 211 164 COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl; 212 this->classID=this->getIdentifier()->getNetworkID(); 165 this->classID=this->getIdentifier()->getNetworkID(); // TODO: correct this 213 166 std::list<synchronisableVariable *>::iterator i; 214 167 unsigned int size; 215 size=getSize2( mode);168 size=getSize2(id, mode); 216 169 217 170 // start copy header … … 224 177 tempsize+=12; 225 178 // end copy header 179 180 //if this tick is we dont synchronise, then abort now 181 if(!isMyTick(id)) 182 return true; 226 183 227 184 COUT(5) << "Synchronisable getting data from objectID: " << objectID << " classID: " << classID << " length: " << size << std::endl; … … 254 211 } 255 212 256 /*bool Synchronisable::getData(Bytestream& bs, int mode)257 {258 //std::cout << "inside getData" << std::endl;259 if(mode==0x0)260 mode=state_;261 if(classID==0)262 COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl;263 this->classID=this->getIdentifier()->getNetworkID();264 std::list<synchronisableVariable *>::iterator i;265 bs << this->getSize();266 bs << this->objectID;267 bs << this->classID;268 // copy to location269 for(i=syncList->begin(); i!=syncList->end(); ++i){270 if( ((*i)->mode & mode) == 0 ){271 COUT(5) << "not getting data: " << std::endl;272 continue; // this variable should only be received273 }274 switch((*i)->type){275 case DATA:276 bs << *(*i)->var;277 //std::memcpy( (void *)(retVal.data+n), (void*)((*i)->var), (*i)->size);278 //n+=(*i)->size;279 break;280 case STRING:281 bs << *(String *)((*i)->var);282 //memcpy( (void *)(retVal.data+n), (void *)&((*i)->size), sizeof(int) );283 //n+=sizeof(int);284 //const char *data = ( ( *(std::string *) (*i)->var).c_str());285 //std::memcpy( retVal.data+n, (void*)data, (*i)->size);286 //COUT(5) << "synchronisable: char: " << (const char *)(retVal.data+n) << " data: " << data << " string: " << *(std::string *)((*i)->var) << std::endl;287 //n+=(*i)->size;288 break;289 }290 }291 return true;292 }*/293 294 295 /**296 * This function takes a syncData struct and takes it to update the variables297 * @param vars data of the variables298 * @return true/false299 */300 bool Synchronisable::updateData(syncData vars, int mode){301 if(mode==0x0)302 mode=state_;303 unsigned char *data=vars.data;304 std::list<synchronisableVariable *>::iterator i;305 if(syncList->empty()){306 COUT(4) << "Synchronisable::updateData syncList is empty" << std::endl;307 return false;308 }309 COUT(5) << "Synchronisable: objectID " << vars.objectID << ", classID " << vars.classID << " size: " << vars.length << " synchronising data" << std::endl;310 for(i=syncList->begin(); i!=syncList->end(); i++){311 if( ((*i)->mode ^ mode) == 0 ){312 COUT(5) << "synchronisable: not updating variable " << std::endl;313 continue; // this variable should only be set314 }315 COUT(5) << "Synchronisable: element size: " << (*i)->size << " type: " << (*i)->type << std::endl;316 bool callback=false;317 switch((*i)->type){318 case DATA:319 if((*i)->callback) // check whether this variable changed (but only if callback was set)320 if(strncmp((char *)(*i)->var, (char *)data, (*i)->size)!=0)321 callback=true;322 memcpy((void*)(*i)->var, data, (*i)->size);323 data+=(*i)->size;324 break;325 case STRING:326 (*i)->size = *(int *)data;327 COUT(5) << "string size: " << (*i)->size << std::endl;328 data+=sizeof(int);329 if((*i)->callback) // check whether this string changed330 if( *(std::string *)((*i)->var) != std::string((char *)data) )331 callback=true;332 *((std::string *)((*i)->var)) = std::string((const char*)data);333 COUT(5) << "synchronisable: char: " << (const char*)data << " string: " << std::string((const char*)data) << std::endl;334 data += (*i)->size;335 break;336 }337 // call the callback function, if defined338 if(callback && (*i)->callback)339 (*i)->callback->call();340 }341 return true;342 }343 213 344 214 /** … … 368 238 assert(this->objectID==objectID); 369 239 assert(this->classID==classID); 240 if(size==3*sizeof(unsigned int)) //if true, only the header is available 241 return true; 242 //assert(0); 370 243 371 244 COUT(5) << "Synchronisable: objectID " << objectID << ", classID " << classID << " size: " << size << " synchronising data" << std::endl; … … 408 281 * @return amount of bytes 409 282 */ 410 int Synchronisable::getSize(int mode){ 283 int Synchronisable::getSize(unsigned int id, int mode){ 284 if(!isMyTick(id)) 285 return 0; 411 286 int tsize=0; 412 287 if(mode==0x0) … … 435 310 * @return amount of bytes 436 311 */ 437 int Synchronisable::getSize2(int mode){ 438 return 3*sizeof(unsigned int) + getSize( mode ); 312 int Synchronisable::getSize2(unsigned int id, int mode){ 313 return sizeof(synchronisableHeader) + getSize( id, mode ); 314 } 315 316 bool Synchronisable::isMyTick(unsigned int id){ 317 // return true; 318 return id==0 || id%objectFrequency_==objectID%objectFrequency_; 439 319 } 440 320 -
code/branches/network/src/network/Synchronisable.h
r1735 r1742 43 43 }; 44 44 45 struct sync Data{46 unsigned int length;45 struct synchronisableHeader{ 46 unsigned int size; 47 47 unsigned int objectID; 48 48 unsigned int classID; 49 unsigned char *data;50 49 }; 51 50 … … 73 72 74 73 void registerVar(void *var, int size, variableType t, int mode=1, NetworkCallbackBase *cb=0); 75 // syncData getData(); 76 syncData getData(unsigned char *mem, int mode=0x0); 77 bool getData2(unsigned char*& men, int mode=0x0); 78 //bool getData(Bytestream& bs, int mode=0x0); 79 int getSize(int mode=0x0); 80 int getSize2(int mode=0x0); 81 bool updateData(syncData vars, int mode=0x0); 74 bool getData(unsigned char*& men, unsigned int id, int mode=0x0); 75 int getSize2(unsigned int id, int mode=0x0); 82 76 bool updateData(unsigned char*& mem, int mode=0x0); 83 77 bool isMyData(unsigned char* mem); … … 92 86 Synchronisable(); 93 87 private: 94 /* bool removeObject(Iterator<Synchronisable> it);*/95 88 int getSize(unsigned int id, int mode=0x0); 89 bool isMyTick(unsigned int id); 96 90 std::list<synchronisableVariable *> *syncList; 97 91 int datasize; 98 92 static int state_; // detemines wheter we are server (default) or client 99 93 bool backsync_; // if true the variables with mode > 1 will be synchronised to server (client -> server) 94 unsigned int objectFrequency_; 100 95 }; 101 96 } -
code/branches/network/src/network/packet/Gamestate.cc
r1741 r1742 62 62 { 63 63 int tempsize=0, currentsize=0; 64 assert(data_==0 /*&& bs_==0*/);65 int size = calcGamestateSize( mode);64 assert(data_==0); 65 int size = calcGamestateSize(id, mode); 66 66 67 67 COUT(4) << "G.ST.Man: producing gamestate with id: " << id << std::endl; 68 //retval->data = (unsigned char*)malloc(size);69 68 if(size==0) 70 69 return false; 71 70 data_ = new unsigned char[size + sizeof(GamestateHeader)]; 72 //bs_ = new Bytestream(data_+sizeof(GamestateHeader), size);73 71 if(!data_){ 74 72 COUT(2) << "GameStateManager: could not allocate memory" << std::endl; … … 81 79 orxonox::Iterator<Synchronisable> it; 82 80 for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it){ 83 tempsize=it->getSize2( mode);81 tempsize=it->getSize2(id, mode); 84 82 85 83 if(currentsize+tempsize > size){ … … 89 87 int addsize=tempsize; 90 88 while(++temp) 91 addsize+=temp->getSize2( mode);89 addsize+=temp->getSize2(id, mode); 92 90 data_ = (unsigned char *)realloc(data_, sizeof(GamestateHeader) + currentsize + addsize); 93 91 if(!data_) … … 96 94 }// stop allocate additional memory 97 95 98 if(!it->getData 2(mem, mode))96 if(!it->getData(mem, id, mode)) 99 97 return false; // mem pointer gets automatically increased because of call by reference 100 98 // increase size counter by size of current synchronisable … … 199 197 { 200 198 assert(HEADER); 199 assert(!HEADER->compressed); 201 200 uLongf buffer = (uLongf)(((HEADER->normsize + 12)*1.01)+1); 202 201 if(buffer==0) … … 228 227 229 228 //copy and modify header 229 #ifndef NDEBUG 230 HEADER->crc32 = calcCRC(data_+sizeof(GamestateHeader), HEADER->normsize); 231 #endif 230 232 *GAMESTATE_HEADER(ndata) = *HEADER; 231 233 //delete old data … … 241 243 bool Gamestate::decompressData() 242 244 { 245 assert(HEADER); 243 246 assert(HEADER->compressed); 244 247 COUT(3) << "GameStateClient: uncompressing gamestate. id: " << HEADER->id << ", baseid: " << HEADER->base_id << ", normsize: " << HEADER->normsize << ", compsize: " << HEADER->compsize << std::endl; … … 261 264 case Z_DATA_ERROR: COUT(2) << "data corrupted (zlib)" << std::endl; return false; 262 265 } 266 #ifndef NDEBUG 267 assert(HEADER->crc32==calcCRC(ndata+sizeof(GamestateHeader), HEADER->normsize)); 268 #endif 263 269 264 270 //copy over the header … … 276 282 Gamestate *Gamestate::diff(Gamestate *base) 277 283 { 284 assert(HEADER); 285 assert(!HEADER->compressed); 286 assert(!HEADER->diffed); 278 287 //unsigned char *basep = base->getGs()/*, *gs = getGs()*/; 279 288 unsigned char *basep = GAMESTATE_START(base->data_), *gs = GAMESTATE_START(this->data_); … … 310 319 Gamestate *Gamestate::undiff(Gamestate *base) 311 320 { 312 assert(this && base); 321 assert(this && base);assert(HEADER); 322 assert(HEADER->diffed); 313 323 assert(!HEADER->compressed && !GAMESTATE_HEADER(base->data_)->compressed); 314 324 //unsigned char *basep = base->getGs()/*, *gs = getGs()*/; … … 346 356 347 357 348 unsigned int Gamestate::calcGamestateSize( int mode)358 unsigned int Gamestate::calcGamestateSize(unsigned int id, int mode) 349 359 { 350 360 int size=0; … … 353 363 // get total size of gamestate 354 364 for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it) 355 size+=it->getSize2( mode); // size of the actual data of the synchronisable365 size+=it->getSize2(id, mode); // size of the actual data of the synchronisable 356 366 // size+=sizeof(GamestateHeader); 357 367 return size; -
code/branches/network/src/network/packet/Gamestate.h
r1741 r1742 29 29 #include "Packet.h" 30 30 #include "network/Synchronisable.h" 31 //#include "util/Bytestream.h" 31 #ifndef NDEBUG 32 #include "util/CRC32.h" 33 #endif 32 34 #include "core/CoreIncludes.h" 33 35 … … 48 50 bool complete; // wheter it is a complete gamestate or only partial 49 51 bool compressed; 52 #ifndef NDEBUG 53 uint32_t crc32; 54 #endif 50 55 }; 51 56 … … 77 82 bool operator ==(packet::Gamestate gs); 78 83 private: 79 unsigned int calcGamestateSize( int mode=0x0);84 unsigned int calcGamestateSize(unsigned int id, int mode=0x0); 80 85 void removeObject(orxonox::Iterator<Synchronisable> &it); 81 86 -
code/branches/network/src/orxonox/objects/SpaceShip.cc
r1735 r1742 243 243 244 244 // START CREATING ADDITIONAL EFFECTS 245 this->backlight_ = new Backlight(this->maxSpeed_, 0.8); 246 this->attachObject(this->backlight_); 247 this->backlight_->setPosition(-2.35, 0, 0.2); 248 this->backlight_->setColour(this->getProjectileColour()); 249 250 this->smoke_ = new ParticleSpawner(); 251 this->smoke_->setParticle("Orxonox/smoke5", LODParticle::normal, 0, 0, 3); 252 this->attachObject(this->smoke_); 253 254 this->fire_ = new ParticleSpawner(); 255 this->fire_->setParticle("Orxonox/fire3", LODParticle::normal, 0, 0, 1); 256 this->attachObject(this->fire_); 245 /*if(!network::Host::running() || network::Host::isServer()){ 246 this->backlight_ = new Backlight(this->maxSpeed_, 0.8); 247 this->attachObject(this->backlight_); 248 this->backlight_->setPosition(-2.35, 0, 0.2); 249 this->backlight_->setColour(this->getProjectileColour()); 250 251 this->smoke_ = new ParticleSpawner(); 252 this->smoke_->setParticle("Orxonox/smoke5", LODParticle::normal, 0, 0, 3); 253 this->attachObject(this->smoke_); 254 255 this->fire_ = new ParticleSpawner(); 256 this->fire_->setParticle("Orxonox/fire3", LODParticle::normal, 0, 0, 1); 257 this->attachObject(this->fire_); 258 }*/ 257 259 // END CREATING ADDITIONAL EFFECTS 258 260 -
code/branches/network/src/util/CMakeLists.txt
r1505 r1742 2 2 ArgReader.cc 3 3 Clipboard.cc 4 CRC32.cc 4 5 ExprParser.cc 5 6 Math.cc
Note: See TracChangeset
for help on using the changeset viewer.