Changeset 1901
- Timestamp:
- Oct 12, 2008, 12:15:30 PM (16 years ago)
- Location:
- code/branches/network
- Files:
-
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/TODO
r1834 r1901 2 2 !!! check that enet does not cause a packet traffic jam when a reliable packet gets missed !!! 3 3 [implemented] new gamestate concept 4 check Projectiles 5 check that we dont have to much registervar because of virtual function calls4 5 !!! ensure that objects get synched, when newly created, even if not their tick 6 6 7 7 setvariable mode 8 8 objectmode 9 friend classes 10 priorities 11 static (sync once) 12 triggerSync 9 priorities (put into gamestatehandler) 10 manage delete object handling (only send deletes of acked objects) 11 static (sync once) & triggerSync 12 13 REMARKS: 14 try to allocate sort the bytestream before copy (putt all 0's in one place) -
code/branches/network/src/network/Client.cc
r1793 r1901 60 60 isSynched_=false; 61 61 gameStateFailure_=false; 62 isServer_ = false;63 62 } 64 63 … … 72 71 isSynched_=false; 73 72 gameStateFailure_=false; 74 isServer_ = false;75 73 } 76 74 … … 84 82 isSynched_=false; 85 83 gameStateFailure_=false; 86 isServer_ = false;87 84 } 88 85 … … 155 152 COUT(5) << "tick packet size " << event->packet->dataLength << std::endl; 156 153 packet::Packet *packet = packet::Packet::createPacket(event->packet, event->peer); 157 assert(packet->process()); 154 bool b = packet->process(); 155 assert(b); 158 156 } 159 157 if(gamestate.processGamestates()) -
code/branches/network/src/network/Client.h
r1793 r1901 85 85 86 86 private: 87 virtual bool isServer_(){return false;} 87 88 88 89 ClientConnection client_connection; -
code/branches/network/src/network/ClientConnection.cc
r1755 r1901 77 77 } 78 78 79 80 /*ENetPacket *ClientConnection::getPacket(ENetAddress &address) { 81 if(!buffer.isEmpty()) { 82 //std::cout << "###BUFFER IS NOT EMPTY###" << std::endl; 83 return buffer.pop(address); 84 } 85 else{ 86 return NULL; 87 } 88 } 89 90 ENetPacket *ClientConnection::getPacket() { 91 ENetAddress address; //sems that address is not needed 92 return getPacket(address); 93 }*/ 79 ClientConnection::~ClientConnection(){ 80 if(established) 81 closeConnection(); 82 } 94 83 95 84 ENetEvent *ClientConnection::getEvent(){ -
code/branches/network/src/network/ClientConnection.h
r1755 r1901 64 64 ClientConnection(int port, std::string address); 65 65 ClientConnection(int port, const char* address); 66 //ENetPacket *getPacket(ENetAddress &address); // thread1 67 //ENetPacket *getPacket(); // thread1 66 ~ClientConnection(); 68 67 ENetEvent *getEvent(); 69 68 // check wheter the packet queue is empty -
code/branches/network/src/network/ConnectionManager.cc
r1834 r1901 80 80 boost::recursive_mutex ConnectionManager::enet_mutex; 81 81 82 // ConnectionManager::ConnectionManager(ClientInformation *head) : receiverThread_(0) {83 // assert(instance_==0);84 // instance_=this;85 // quit=false;86 // bindAddress.host = ENET_HOST_ANY;87 // bindAddress.port = NETWORK_PORT;88 // }89 90 82 ConnectionManager::ConnectionManager(int port){ 91 83 assert(instance_==0); … … 113 105 114 106 ConnectionManager::~ConnectionManager(){ 115 instance_=0;116 107 if(!quit) 117 108 quitListener(); 118 } 119 120 /*ENetPacket *ConnectionManager::getPacket(ENetAddress &address) { 121 if(!buffer.isEmpty()) 122 return buffer.pop(address); 123 else 124 return NULL; 125 }*/ 126 /** 127 This function only pops the first element in PacketBuffer (first in first out) 128 used by processQueue in Server.cc 129 */ 130 /*ENetPacket *ConnectionManager::getPacket(int &clientID) { 131 ENetAddress address; 132 ENetPacket *packet=getPacket(address); 133 ClientInformation *temp =head_->findClient(&address); 134 if(!temp) 135 return NULL; 136 clientID=temp->getID(); 137 return packet; 138 }*/ 109 instance_=0; 110 } 111 139 112 140 113 ENetEvent *ConnectionManager::getEvent(){ … … 163 136 } 164 137 165 // bool ConnectionManager::addPacket(Packet::Packet *packet){166 // ClientInformation *temp = instance_->head_->findClient(packet->getClientID());167 // if(!temp){168 // COUT(3) << "C.Man: addPacket findClient failed" << std::endl;169 // return false;170 // }171 // ENetPacket *packet = new ENetPacket;172 // // TODO: finish implementation173 // }174 //175 138 176 139 bool ConnectionManager::addPacket(ENetPacket *packet, ENetPeer *peer) { -
code/branches/network/src/network/GamestateClient.cc
r1827 r1901 182 182 packet::Gamestate *GamestateClient::processGamestate(packet::Gamestate *gs){ 183 183 if(gs->isCompressed()) 184 assert(gs->decompressData()); 184 { 185 bool b = gs->decompressData(); 186 assert(b); 187 } 185 188 if(gs->isDiffed()){ 186 189 packet::Gamestate *base = gamestateMap_[gs->getBaseID()]; -
code/branches/network/src/network/GamestateManager.cc
r1827 r1901 154 154 gs = new packet::Gamestate(*gs); 155 155 } 156 assert(gs->compressData()); 156 bool b = gs->compressData(); 157 assert(b); 157 158 return gs; 158 159 } … … 194 195 bool GamestateManager::processGamestate(packet::Gamestate *gs){ 195 196 if(gs->isCompressed()) 196 assert(gs->decompressData()); 197 { 198 bool b = gs->decompressData(); 199 assert(b); 200 } 197 201 assert(!gs->isDiffed()); 198 202 return gs->spreadData(); -
code/branches/network/src/network/Host.h
r1793 r1901 52 52 virtual bool chat(std::string message)=0; 53 53 virtual bool processChat(std::string message, unsigned int playerID)=0; 54 virtual bool isServer_()=0; 54 55 55 56 … … 59 60 virtual ~Host(); 60 61 static Host *instance_; 61 bool isServer_;62 62 unsigned int clientID_; 63 63 unsigned int shipID_; … … 72 72 static void setClientID(unsigned int id){ instance_->clientID_ = id; } 73 73 static void setShipID(unsigned int id){ instance_->shipID_ = id; } 74 static bool isServer(){ return instance_->isServer_ ; }74 static bool isServer(){ return instance_->isServer_(); } 75 75 static bool Chat(std::string message); 76 76 static bool incomingChat(std::string message, unsigned int playerID); -
code/branches/network/src/network/Server.cc
r1834 r1901 72 72 connection = new ConnectionManager(); 73 73 gamestates_ = new GamestateManager(); 74 isServer_ = true;75 74 } 76 75 … … 79 78 connection = new ConnectionManager(port); 80 79 gamestates_ = new GamestateManager(); 81 isServer_ = true;82 80 } 83 81 … … 91 89 connection = new ConnectionManager(port, bindAddress); 92 90 gamestates_ = new GamestateManager(); 93 isServer_ = true;94 91 } 95 92 … … 103 100 connection = new ConnectionManager(port, bindAddress); 104 101 gamestates_ = new GamestateManager(); 105 isServer_ = true; 102 } 103 104 /** 105 * @brief Destructor 106 */ 107 Server::~Server(){ 108 if(connection) 109 delete connection; 110 if(gamestates_) 111 delete gamestates_; 106 112 } 107 113 … … 198 204 //std::cout << "updated gamestate, sending it" << std::endl; 199 205 //if(clients->getGamestateID()!=GAMESTATEID_INITIAL) 206 sendGameState(); 200 207 sendObjectDeletes(); 201 sendGameState();202 208 COUT(5) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl; 203 209 //std::cout << "sent gamestate" << std::endl; … … 254 260 if(!del->fetchIDs()) 255 261 return true; //everything ok (no deletes this tick) 262 // COUT(3) << "sending DeleteObjects" << std::endl; 256 263 while(temp != NULL){ 257 264 if( !(temp->getSynched()) ){ … … 307 314 packet::Welcome *w = new packet::Welcome(temp->getID(), temp->getShipID()); 308 315 w->setClientID(temp->getID()); 309 assert(w->send()); 316 bool b = w->send(); 317 assert(b); 310 318 packet::Gamestate *g = new packet::Gamestate(); 311 319 g->setClientID(temp->getID()); 312 assert(g->collectData(0)); 313 assert(g->compressData()); 314 assert(g->send()); 320 b = g->collectData(0); 321 assert(b); 322 b = g->compressData(); 323 assert(b); 324 b = g->send(); 325 assert(b); 315 326 return true; 316 327 } -
code/branches/network/src/network/Server.h
r1793 r1901 63 63 Server(int port, std::string bindAddress); 64 64 Server(int port, const char *bindAddress); 65 ~Server(); 65 66 66 67 void open(); … … 73 74 void updateGamestate(); 74 75 private: 76 virtual bool isServer_(){return true;} 75 77 unsigned int shipID(){return 0;} 76 78 unsigned int playerID(){return 0;} -
code/branches/network/src/network/Synchronisable.cc
r1834 r1901 64 64 Synchronisable::Synchronisable(){ 65 65 RegisterRootObject(Synchronisable); 66 static u nsigned int idCounter=0;66 static uint32_t idCounter=0; 67 67 objectFrequency_=1; 68 68 objectMode_=0x1; // by default do not send data to server 69 69 objectID=idCounter++; 70 // COUT(3) << " bump +++" << objectID << " | " << &objectMap_ << std::endl;71 70 syncList = new std::list<synchronisableVariable *>; 72 71 } … … 81 80 for(std::list<synchronisableVariable *>::iterator it = syncList->begin(); it!=syncList->end(); it++) 82 81 delete (*it)->callback; 82 deletedObjects_.push(objectID); 83 // COUT(3) << "destruct synchronisable +++" << objectID << " | " << classID << std::endl; 83 84 // COUT(3) << " bump ---" << objectID << " | " << &objectMap_ << std::endl; 84 85 // assert(objectMap_[objectID]->objectID==objectID); … … 94 95 bool Synchronisable::create(){ 95 96 this->classID = this->getIdentifier()->getNetworkID(); 96 COUT(4) << "creating synchronisable: setting classid from " << this->getIdentifier()->getName() << " to: " << classID << std::endl; 97 97 // COUT(4) << "creating synchronisable: setting classid from " << this->getIdentifier()->getName() << " to: " << classID << std::endl; 98 99 // COUT(3) << "construct synchronisable +++" << objectID << " | " << classID << std::endl; 98 100 // objectMap_[objectID]=this; 99 101 // assert(objectMap_[objectID]==this); … … 121 123 * @return pointer to the newly created synchronisable 122 124 */ 123 Synchronisable *Synchronisable::fabricate(u nsigned char*& mem, int mode)125 Synchronisable *Synchronisable::fabricate(uint8_t*& mem, int mode) 124 126 { 125 127 synchronisableHeader *header = (synchronisableHeader *)mem; 128 129 COUT(3) << "fabricating object with id: " << header->objectID << std::endl; 126 130 127 131 orxonox::Identifier* id = GetIdentifier(header->classID); … … 134 138 COUT(3) << "fabricate objectID: " << no->objectID << " classID: " << no->classID << std::endl; 135 139 // update data and create object/entity... 136 assert(no->updateData(mem, mode)); 137 assert( no->create() ); 140 bool b = no->updateData(mem, mode); 141 assert(b); 142 b = no->create(); 143 assert(b); 138 144 return no; 139 145 } … … 146 152 */ 147 153 bool Synchronisable::deleteObject(unsigned int objectID){ 148 assert(getSynchronisable(objectID)); 154 // assert(getSynchronisable(objectID)); 155 if(!getSynchronisable(objectID)) 156 return false; 149 157 assert(getSynchronisable(objectID)->objectID==objectID); 150 158 // delete objectMap_[objectID]; … … 222 230 * @return true: if !isMyTick or if everything was successfully saved 223 231 */ 224 bool Synchronisable::getData(u nsigned char*& mem, unsigned int id, int mode){232 bool Synchronisable::getData(uint8_t*& mem, unsigned int id, int mode){ 225 233 //if this tick is we dont synchronise, then abort now 226 234 if(!isMyTick(id)) … … 232 240 if(classID==0) 233 241 COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl; 234 this->classID=this->getIdentifier()->getNetworkID(); // TODO: correct this 242 assert(this->classID==this->getIdentifier()->getNetworkID()); 243 // this->classID=this->getIdentifier()->getNetworkID(); // TODO: correct this 235 244 std::list<synchronisableVariable *>::iterator i; 236 245 unsigned int size; … … 283 292 * @return true/false 284 293 */ 285 bool Synchronisable::updateData(u nsigned char*& mem, int mode){294 bool Synchronisable::updateData(uint8_t*& mem, int mode){ 286 295 if(mode==0x0) 287 296 mode=state_; … … 291 300 return false; 292 301 } 293 u nsigned char*data=mem;302 uint8_t *data=mem; 294 303 // start extract header 295 304 synchronisableHeader *syncHeader = (synchronisableHeader *)mem; … … 322 331 break; 323 332 case STRING: 324 (*i)->size = *( int *)mem;333 (*i)->size = *(uint32_t *)mem; 325 334 COUT(5) << "string size: " << (*i)->size << std::endl; 326 335 mem+=sizeof(int); … … 346 355 * @return amount of bytes 347 356 */ 348 int Synchronisable::getSize(unsigned int id, int mode){357 uint32_t Synchronisable::getSize(unsigned int id, int mode){ 349 358 if(!isMyTick(id)) 350 359 return 0; … … 388 397 * @param mem pointer to the bytestream 389 398 */ 390 bool Synchronisable::isMyData(u nsigned char* mem)399 bool Synchronisable::isMyData(uint8_t* mem) 391 400 { 392 401 synchronisableHeader *header = (synchronisableHeader *)mem; -
code/branches/network/src/network/Synchronisable.h
r1834 r1901 57 57 bidirectional=0x3 58 58 }; 59 59 } 60 61 namespace syncmode{ 62 enum mode{ 63 one=0, 64 always=1 65 }; 60 66 } 61 67 … … 66 72 67 73 struct synchronisableHeader{ 68 u nsigned int size;69 bool dataAvailable ;70 u nsigned int objectID;71 u nsigned int classID;74 uint32_t size:31; 75 bool dataAvailable:1; 76 uint32_t objectID; 77 uint32_t classID; 72 78 }; 73 79 … … 97 103 static void setClient(bool b); 98 104 99 static Synchronisable *fabricate(u nsigned char*& mem, int mode=0x0);105 static Synchronisable *fabricate(uint8_t*& mem, int mode=0x0); 100 106 static bool deleteObject(unsigned int objectID); 101 107 static Synchronisable *getSynchronisable(unsigned int objectID); … … 114 120 115 121 private: 116 bool getData(u nsigned char*& men, unsigned int id, int mode=0x0);117 int getSize(unsigned int id, int mode=0x0);118 bool updateData(u nsigned char*& mem, int mode=0x0);119 bool isMyData(u nsigned char* mem);122 bool getData(uint8_t*& men, unsigned int id, int mode=0x0); 123 uint32_t getSize(unsigned int id, int mode=0x0); 124 bool updateData(uint8_t*& mem, int mode=0x0); 125 bool isMyData(uint8_t* mem); 120 126 bool doSelection(unsigned int id); 121 127 bool isMyTick(unsigned int id); -
code/branches/network/src/network/packet/DeleteObjects.cc
r1890 r1901 37 37 namespace packet { 38 38 39 #define PACKET_FLAG S_DELETEENET_PACKET_FLAG_RELIABLE39 #define PACKET_FLAG_DELETE ENET_PACKET_FLAG_RELIABLE 40 40 #define _PACKETID 0 41 41 #define _QUANTITY _PACKETID + sizeof(ENUM::Type) … … 45 45 : Packet() 46 46 { 47 flags_ = flags_ | PACKET_FLAG S_DELETE;47 flags_ = flags_ | PACKET_FLAG_DELETE; 48 48 } 49 49 … … 61 61 if(number==0) 62 62 return false; 63 COUT(3) << "sending DeleteObjects: "; 63 64 unsigned int size = sizeof(ENUM::Type) + sizeof(uint32_t)*(number+1); 64 65 data_ = new uint8_t[size]; 65 *(ENUM::Type *)(data_ + _PACKETID ) = ENUM::DeleteObjects; 66 *(uint32_t *)(data_ + _QUANTITY) = number; 66 uint8_t *tdata = data_; 67 *(ENUM::Type *)(tdata) = ENUM::DeleteObjects; 68 tdata += sizeof(ENUM::Type); 69 *(uint32_t *)tdata = number; 70 tdata += sizeof(uint32_t); 67 71 for(unsigned int i=0; i<number; i++){ 68 *(uint32_t *)(data_ + sizeof(ENUM::Type) + (i+1)*sizeof(uint32_t)) = Synchronisable::popDeletedObject(); 72 unsigned int temp = Synchronisable::popDeletedObject(); 73 // assert(temp<10000); //ugly hack 74 *(uint32_t *)(tdata) = temp; 75 COUT(3) << temp << " "; 76 tdata += sizeof(uint32_t); 69 77 } 78 COUT(3) << std::endl; 70 79 return true; 71 80 } -
code/branches/network/src/network/packet/Gamestate.cc
r1834 r1901 47 47 48 48 49 #define PACKET_FLAG_GAMESTATE ENET_PACKET_FLAG_RELIABLE 50 49 51 Gamestate::Gamestate() 50 52 { 51 } 52 53 Gamestate::Gamestate(unsigned char *data, int clientID): 53 flags_ = flags_ | PACKET_FLAG_GAMESTATE; 54 } 55 56 Gamestate::Gamestate(uint8_t *data, unsigned int clientID): 54 57 Packet(data, clientID) 55 58 { 56 } 57 58 Gamestate::Gamestate(unsigned char *data) 59 { 59 flags_ = flags_ | PACKET_FLAG_GAMESTATE; 60 } 61 62 Gamestate::Gamestate(uint8_t *data) 63 { 64 flags_ = flags_ | PACKET_FLAG_GAMESTATE; 60 65 data_=data; 61 66 } … … 86 91 #endif 87 92 //start collect data synchronisable by synchronisable 88 u nsigned char*mem=data_;93 uint8_t *mem=data_; 89 94 mem+=sizeof(GamestateHeader); 90 95 orxonox::ObjectList<Synchronisable>::iterator it; … … 99 104 while(++temp) 100 105 addsize+=temp->getSize(id, mode); 101 data_ = (u nsigned char*)realloc(data_, sizeof(GamestateHeader) + currentsize + addsize);106 data_ = (uint8_t *)realloc(data_, sizeof(GamestateHeader) + currentsize + addsize); 102 107 if(!data_) 103 108 return false; … … 140 145 assert(!HEADER->compressed); 141 146 assert(!HEADER->diffed); 142 u nsigned char*mem=data_+sizeof(GamestateHeader);147 uint8_t *mem=data_+sizeof(GamestateHeader); 143 148 // get the start of the Synchronisable list 144 149 //orxonox::ObjectList<Synchronisable>::iterator it=orxonox::ObjectList<Synchronisable>::begin(); … … 159 164 else 160 165 { 161 assert(s->updateData(mem, mode)); 166 bool b = s->updateData(mem, mode); 167 assert(b); 162 168 //if(!s->updateData(mem, mode)) 163 169 //return false; … … 186 192 187 193 bool Gamestate::operator==(packet::Gamestate gs){ 188 u nsigned char*d1 = data_+sizeof(GamestateHeader);189 u nsigned char*d2 = gs.data_+sizeof(GamestateHeader);194 uint8_t *d1 = data_+sizeof(GamestateHeader); 195 uint8_t *d2 = gs.data_+sizeof(GamestateHeader); 190 196 assert(!isCompressed()); 191 197 assert(!gs.isCompressed()); … … 215 221 return false; 216 222 217 u nsigned char *ndata = new unsigned char[buffer+sizeof(GamestateHeader)];218 u nsigned char*dest = GAMESTATE_START(ndata);223 uint8_t *ndata = new uint8_t[buffer+sizeof(GamestateHeader)]; 224 uint8_t *dest = GAMESTATE_START(ndata); 219 225 //unsigned char *dest = new unsigned char[buffer]; 220 u nsigned char*source = GAMESTATE_START(data_);226 uint8_t *source = GAMESTATE_START(data_); 221 227 int retval; 222 228 retval = compress( dest, &buffer, source, (uLong)(HEADER->datasize) ); … … 229 235 #ifndef NDEBUG 230 236 //decompress and compare the start and the decompressed data 231 u nsigned char *rdata = new unsigned char[HEADER->datasize+sizeof(GamestateHeader)];232 u nsigned char*d2 = GAMESTATE_START(rdata);237 uint8_t *rdata = new uint8_t[HEADER->datasize+sizeof(GamestateHeader)]; 238 uint8_t *d2 = GAMESTATE_START(rdata); 233 239 uLongf length2 = HEADER->datasize; 234 240 uncompress(d2, &length2, dest, buffer); … … 265 271 bufsize = datasize; 266 272 assert(bufsize!=0); 267 u nsigned char *ndata = new unsigned char[bufsize + sizeof(GamestateHeader)];268 u nsigned char*dest = ndata + sizeof(GamestateHeader);269 u nsigned char*source = data_ + sizeof(GamestateHeader);273 uint8_t *ndata = new uint8_t[bufsize + sizeof(GamestateHeader)]; 274 uint8_t *dest = ndata + sizeof(GamestateHeader); 275 uint8_t *source = data_ + sizeof(GamestateHeader); 270 276 int retval; 271 277 uLongf length=bufsize; … … 299 305 assert(!HEADER->diffed); 300 306 //unsigned char *basep = base->getGs()/*, *gs = getGs()*/; 301 u nsigned char*basep = GAMESTATE_START(base->data_), *gs = GAMESTATE_START(this->data_);307 uint8_t *basep = GAMESTATE_START(base->data_), *gs = GAMESTATE_START(this->data_); 302 308 unsigned int of=0; // pointers offset 303 309 unsigned int dest_length=0; … … 305 311 if(dest_length==0) 306 312 return NULL; 307 u nsigned char *ndata = new unsigned char[dest_length*sizeof(unsigned char)+sizeof(GamestateHeader)];308 u nsigned char*dest = ndata + sizeof(GamestateHeader);313 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+sizeof(GamestateHeader)]; 314 uint8_t *dest = ndata + sizeof(GamestateHeader); 309 315 while(of < GAMESTATE_HEADER(base->data_)->datasize && of < HEADER->datasize){ 310 316 *(dest+of)=*(basep+of)^*(gs+of); // do the xor … … 312 318 } 313 319 if(GAMESTATE_HEADER(base->data_)->datasize!=HEADER->datasize){ 314 u nsigned charn=0;320 uint8_t n=0; 315 321 if(GAMESTATE_HEADER(base->data_)->datasize < HEADER->datasize){ 316 322 while(of<dest_length){ … … 335 341 336 342 Gamestate *gs = new Gamestate(*this); 337 u nsigned char*ndata = gs->data_ + sizeof(GamestateHeader);343 uint8_t *ndata = gs->data_ + sizeof(GamestateHeader); 338 344 synchronisableHeader *objectheader; 339 345 unsigned int objectOffset; … … 344 350 unsigned int objectsize = objectheader->size; 345 351 assert(it->second->objectID==objectheader->objectID); 346 objectOffset=sizeof(u nsigned int)+sizeof(bool); //skip the size and the availableDate variables in the objectheader352 objectOffset=sizeof(uint8_t)+sizeof(bool); //skip the size and the availableDate variables in the objectheader 347 353 if(!it->second->doSelection(HEADER->id)){ 348 354 while(objectOffset<objectsize){ … … 370 376 //preparations 371 377 std::map<unsigned int, Synchronisable *>::iterator it; 372 u nsigned char*origdata, *basedata, *destdata, *ndata;378 uint8_t *origdata, *basedata, *destdata, *ndata; 373 379 unsigned int objectOffset, streamOffset=0; //data offset 374 380 unsigned int minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize; … … 378 384 origdata = GAMESTATE_START(this->data_); 379 385 basedata = GAMESTATE_START(base->data_); 380 ndata = new u nsigned char[HEADER->datasize + sizeof(GamestateHeader)];386 ndata = new uint8_t[HEADER->datasize + sizeof(GamestateHeader)]; 381 387 destdata = ndata + sizeof(GamestateHeader); 382 388 … … 390 396 //copy and partially diff the object header 391 397 assert(sizeof(synchronisableHeader)==3*sizeof(unsigned int)+sizeof(bool)); 392 *(u nsigned int*)destdata = *(unsigned int*)origdata; //size (do not diff)393 *(bool*)(destdata+sizeof(u nsigned int)) = sendData;398 *(uint32_t*)destdata = *(uint32_t*)origdata; //size (do not diff) 399 *(bool*)(destdata+sizeof(uint32_t)) = sendData; 394 400 if(sendData){ 395 *(u nsigned int*)(destdata+sizeof(unsigned int)+sizeof(bool)) = *(unsigned int*)(basedata+sizeof(unsigned int)+sizeof(bool)) ^ *(unsigned int*)(origdata+sizeof(unsigned int)+sizeof(bool)); //objectid (diff it)396 *(u nsigned int*)(destdata+2*sizeof(unsigned int)+sizeof(bool)) = *(unsigned int*)(basedata+2*sizeof(unsigned int)+sizeof(bool)) ^ *(unsigned int*)(origdata+2*sizeof(unsigned int)+sizeof(bool)); //classid (diff it)401 *(uint32_t*)(destdata+sizeof(uint32_t)+sizeof(bool)) = *(uint32_t*)(basedata+sizeof(uint32_t)+sizeof(bool)) ^ *(uint32_t*)(origdata+sizeof(uint32_t)+sizeof(bool)); //objectid (diff it) 402 *(uint32_t*)(destdata+2*sizeof(uint32_t)+sizeof(bool)) = *(uint32_t*)(basedata+2*sizeof(uint32_t)+sizeof(bool)) ^ *(uint32_t*)(origdata+2*sizeof(uint32_t)+sizeof(bool)); //classid (diff it) 397 403 }else{ 398 *(u nsigned int*)(destdata+sizeof(unsigned int)+sizeof(bool)) = 0;399 *(u nsigned int*)(destdata+2*sizeof(unsigned int)+sizeof(bool)) = 0;404 *(uint32_t*)(destdata+sizeof(uint32_t)+sizeof(bool)) = 0; 405 *(uint32_t*)(destdata+2*sizeof(uint32_t)+sizeof(bool)) = 0; 400 406 } 401 407 objectOffset=sizeof(synchronisableHeader); … … 408 414 *(destdata+objectOffset)=*(basedata+objectOffset)^*(origdata+objectOffset); // do the xor 409 415 else if(sendData) 410 *(destdata+objectOffset)=((u nsigned char)0)^*(origdata+objectOffset); // xor with 0 (basestream is too short)416 *(destdata+objectOffset)=((uint8_t)0)^*(origdata+objectOffset); // xor with 0 (basestream is too short) 411 417 else 412 418 *(destdata+objectOffset)=0; // set to 0 because this object should not be transfered … … 438 444 //preparations 439 445 std::map<unsigned int, Synchronisable *>::iterator it; 440 u nsigned char*origdata, *basedata, *destdata, *ndata;446 uint8_t *origdata, *basedata, *destdata, *ndata; 441 447 unsigned int objectOffset, streamOffset=0; //data offset 442 448 unsigned int minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize; … … 446 452 origdata = GAMESTATE_START(this->data_); 447 453 basedata = GAMESTATE_START(base->data_); 448 ndata = new u nsigned char[HEADER->datasize + sizeof(GamestateHeader)];454 ndata = new uint8_t[HEADER->datasize + sizeof(GamestateHeader)]; 449 455 destdata = ndata + sizeof(GamestateHeader); 450 456 … … 502 508 assert(!HEADER->compressed && !GAMESTATE_HEADER(base->data_)->compressed); 503 509 //unsigned char *basep = base->getGs()/*, *gs = getGs()*/; 504 u nsigned char*basep = GAMESTATE_START(base->data_);505 u nsigned char*gs = GAMESTATE_START(this->data_);510 uint8_t *basep = GAMESTATE_START(base->data_); 511 uint8_t *gs = GAMESTATE_START(this->data_); 506 512 unsigned int of=0; // pointers offset 507 513 unsigned int dest_length=0; … … 509 515 if(dest_length==0) 510 516 return NULL; 511 u nsigned char *ndata = new unsigned char[dest_length*sizeof(unsigned char)+sizeof(GamestateHeader)];512 u nsigned char*dest = ndata + sizeof(GamestateHeader);517 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+sizeof(GamestateHeader)]; 518 uint8_t *dest = ndata + sizeof(GamestateHeader); 513 519 while(of < GAMESTATE_HEADER(base->data_)->datasize && of < HEADER->datasize){ 514 520 *(dest+of)=*(basep+of)^*(gs+of); // do the xor … … 516 522 } 517 523 if(GAMESTATE_HEADER(base->data_)->datasize!=HEADER->datasize){ 518 u nsigned charn=0;524 uint8_t n=0; 519 525 if(GAMESTATE_HEADER(base->data_)->datasize < HEADER->datasize){ 520 526 while(of < dest_length){ -
code/branches/network/src/network/packet/Gamestate.h
r1827 r1901 44 44 struct GamestateHeader{ 45 45 ENUM::Type packetType; 46 int id; // id of the gamestate47 u nsigned int compsize;48 u nsigned int datasize;49 int base_id; // id of the base-gamestate diffed from50 bool diffed ; // wheter diffed or not51 bool complete ; // wheter it is a complete gamestate or only partial52 bool compressed ;46 int32_t id; // id of the gamestate 47 uint32_t compsize; 48 uint32_t datasize; 49 int32_t base_id; // id of the base-gamestate diffed from 50 bool diffed:1; // wheter diffed or not 51 bool complete:1; // wheter it is a complete gamestate or only partial 52 bool compressed:1; 53 53 #ifndef NDEBUG 54 54 uint32_t crc32; … … 62 62 public: 63 63 Gamestate(); 64 Gamestate(u nsigned char *data,int clientID);65 Gamestate(u nsigned char*data);64 Gamestate(uint8_t *data, unsigned int clientID); 65 Gamestate(uint8_t *data); 66 66 67 67 ~Gamestate(); -
code/branches/network/src/network/packet/Packet.cc
r1890 r1901 120 120 case ENUM::Gamestate: 121 121 case ENUM::Welcome: 122 case ENUM::DeleteObjects: 122 123 break; 123 124 default: -
code/branches/network/src/orxonox/Settings.h
r1892 r1901 53 53 friend class GSGraphics; 54 54 friend class GSServer; 55 friend class GSClient; 55 56 friend class GSDedicated; 56 friend class GSClient;57 57 58 58 public: -
code/branches/network/src/orxonox/gamestates/GSServer.cc
r1755 r1901 78 78 79 79 // TODO: Remove and destroy console command 80 Settings::_getInstance().bHasServer_ = false; 80 81 81 82 this->unloadLevel(); -
code/branches/network/src/orxonox/objects/Backlight.cc
r1755 r1901 53 53 this->traillength_ = 1; 54 54 55 this->getNode()->setInheritScale(false); 55 this->configure(maxspeed, brakingtime, scale); 56 } 57 58 bool Backlight::create(){ 59 if(!WorldEntity::create()) 60 return false; 61 62 this->getNode()->setInheritScale(false); 56 63 57 58 64 this->billboard_.setBillboardSet("Flares/backlightflare"); 65 this->attachObject(this->billboard_.getBillboardSet()); 59 66 60 61 62 63 67 this->ribbonTrail_ = GraphicsEngine::getInstance().getLevelSceneManager()->createRibbonTrail(this->getName() + "RibbonTrail"); 68 this->ribbonTrailNode_ = GraphicsEngine::getInstance().getLevelSceneManager()->getRootSceneNode()->createChildSceneNode(this->getName() + "RibbonTrailNode"); 69 this->ribbonTrailNode_->attachObject(this->ribbonTrail_); 70 this->ribbonTrail_->addNode(this->getNode()); 64 71 65 this->configure(maxspeed, brakingtime, scale);66 72 67 68 73 this->ribbonTrail_->setTrailLength(this->maxTraillength_); 74 this->ribbonTrail_->setMaterialName("Trail/backlighttrail"); 69 75 70 76 //this->setTimeFactor(Orxonox::getInstance().getTimeFactor()); 71 this->setTimeFactor(1.0f); 77 this->setTimeFactor(1.0f); 78 79 this->ribbonTrail_->setMaxChainElements(this->maxTrailsegments_); 80 this->ribbonTrail_->setTrailLength(this->traillength_ = 2 * this->maxTrailsegments_); 81 this->ribbonTrail_->setInitialWidth(0, this->width_ * this->getScale()); 82 this->ribbonTrail_->setWidthChange(0, this->width_ * this->getScale() / this->maxLifeTime_ * Backlight::timeFactor_s); 83 return true; 72 84 } 73 85 … … 100 112 { 101 113 this->ribbonTrail_->setColourChange(0, ColourValue(0, 0, 0, this->maxTraillength_ / this->traillength_ / this->maxLifeTime_ * Backlight::timeFactor_s)); 114 } 115 116 117 void Backlight::XMLPort(Element& xmlelement, XMLPort::Mode mode){ 118 SUPER(Backlight, XMLPort, xmlelement, mode); 119 120 Backlight::create(); 102 121 } 103 122 … … 136 155 this->maxTraillength_ = this->maxLifeTime_ * maxspeed; 137 156 this->maxTrailsegments_ = (size_t)(this->maxTraillength_ / this->trailSegmentLength_); 138 this->ribbonTrail_->setMaxChainElements(this->maxTrailsegments_);139 this->ribbonTrail_->setTrailLength(this->traillength_ = 2 * this->maxTrailsegments_);140 157 141 158 this->brakefactor_ = this->maxLifeTime_ / brakingtime; 142 159 143 160 this->scale(scale); 144 this->ribbonTrail_->setInitialWidth(0, this->width_ * scale);145 this->ribbonTrail_->setWidthChange(0, this->width_ * scale / this->maxLifeTime_ * Backlight::timeFactor_s);146 161 } 147 162 -
code/branches/network/src/orxonox/objects/Backlight.h
r1608 r1901 45 45 46 46 void setConfigValues(); 47 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 48 virtual void tick(float dt); 48 49 virtual void changedVisibility(); 50 virtual bool create(); 49 51 50 52 void setColour(const ColourValue& colour); -
code/branches/network/src/orxonox/objects/Model.cc
r1793 r1901 46 46 47 47 /** 48 * 48 * @brief Constructor 49 49 */ 50 50 Model::Model() … … 54 54 } 55 55 56 /** 57 * @brief Destructor 58 */ 56 59 Model::~Model() 57 60 { -
code/branches/network/src/orxonox/objects/Projectile.cc
r1834 r1901 41 41 #include "ParticleSpawner.h" 42 42 #include "Model.h" 43 #include "Settings.h" 43 44 44 45 namespace orxonox … … 64 65 } 65 66 66 this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject))); 67 if(!orxonox::Settings::isClient()) //only if not on client 68 this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject))); 67 69 } 68 70 -
code/branches/network/src/orxonox/objects/SpaceShip.cc
r1834 r1901 181 181 this->setRadarObjectColour(this->getProjectileColour()); 182 182 } 183 assert(Model::create());183 Model::create(); 184 184 this->init(); 185 185 return true; … … 255 255 256 256 // START CREATING ADDITIONAL EFFECTS 257 /*this->backlight_ = new Backlight(this->maxSpeed_, 0.8); 258 this->attachObject(this->backlight_); 259 this->backlight_->setPosition(-2.35, 0, 0.2); 260 this->backlight_->setColour(this->getProjectileColour()); 261 262 this->smoke_ = new ParticleSpawner(); 263 this->smoke_->setParticle("Orxonox/smoke5", LODParticle::normal, 0, 0, 3); 264 this->attachObject(this->smoke_); 265 266 this->fire_ = new ParticleSpawner(); 267 this->fire_->setParticle("Orxonox/fire3", LODParticle::normal, 0, 0, 1); 268 this->attachObject(this->fire_); 269 */ 257 if(!network::Host::running()){ 258 this->backlight_ = new Backlight(this->maxSpeed_, 0.8); 259 this->backlight_->create(); 260 this->attachObject(this->backlight_); 261 this->backlight_->setPosition(-2.35, 0, 0.2); 262 this->backlight_->setColour(this->getProjectileColour()); 263 264 this->smoke_ = new ParticleSpawner(); 265 this->smoke_->setParticle("Orxonox/smoke5", LODParticle::normal, 0, 0, 3); 266 this->attachObject(this->smoke_); 267 268 this->fire_ = new ParticleSpawner(); 269 this->fire_->setParticle("Orxonox/fire3", LODParticle::normal, 0, 0, 1); 270 this->attachObject(this->fire_); 271 } 272 270 273 // END CREATING ADDITIONAL EFFECTS 271 274
Note: See TracChangeset
for help on using the changeset viewer.