Changeset 1425 for code/branches/network/src/network
- Timestamp:
- May 25, 2008, 11:08:19 PM (16 years ago)
- Location:
- code/branches/network/src/network
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/Client.cc
r1409 r1425 246 246 elaborate(event->packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server) 247 247 } 248 int gameStateID = gamestate.processGameState(); 249 if(gameStateID!=GAMESTATEID_INITIAL){ 250 // ack gamestate and set synched 251 if(!isSynched_) 252 isSynched_=true; 253 if(!client_connection.addPacket(pck_gen.acknowledgement(gameStateID))) 254 COUT(3) << "could not ack gamestate" << std::endl; 255 } 256 gamestate.cleanup(); 248 257 if(!client_connection.sendPackets()) 249 258 COUT(3) << "Problem sending packets to server" << std::endl; … … 252 261 253 262 void Client::processGamestate( GameStateCompressed *data, int clientID){ 254 int id = data->id;255 263 COUT(5) << "received gamestate id: " << data->id << std::endl; 256 if(gamestate.pushGameState(data)){ 257 if(!isSynched_) 258 isSynched_=true; 259 if(!client_connection.addPacket(pck_gen.acknowledgement(id))) 260 return; 261 // we do this at the end of a tick 262 if(!client_connection.sendPackets()) 263 COUT(2) << "Could not send acknowledgment" << std::endl; 264 } 264 gamestate.addGameState(data); 265 265 } 266 266 -
code/branches/network/src/network/GameStateClient.cc
r1360 r1425 21 21 * 22 22 * Author: 23 * ...23 * Oliver Scheuss 24 24 * Co-authors: 25 * ...25 * Dumeni Manatschal 26 26 * 27 27 */ … … 35 35 #include "Synchronisable.h" 36 36 37 #define GAMESTATEID_INITIAL -138 37 39 38 namespace network … … 48 47 last_diff_=0; 49 48 last_gamestate_=GAMESTATEID_INITIAL-1; 49 tempGameState_=NULL; 50 myShip_=NULL; 50 51 } 51 52 … … 102 103 delete gs; 103 104 return cgs; 105 } 106 107 void GameStateClient::addGameState(GameStateCompressed *gs){ 108 if(tempGameState_!=NULL){ 109 //delete the obsolete gamestate 110 if(tempGameState_->id>gs->id) 111 return; 112 delete[] tempGameState_->data; 113 delete tempGameState_; 114 } 115 tempGameState_=gs; 116 } 117 int GameStateClient::processGameState(){ 118 if(tempGameState_==NULL) 119 return GAMESTATEID_INITIAL; 120 int id=tempGameState_->id; 121 bool b = saveShipCache(); 122 if(pushGameState(tempGameState_)){ 123 if(b) 124 loadShipCache(); 125 return id; 126 } 127 else 128 return GAMESTATEID_INITIAL; 104 129 } 105 130 … … 388 413 gameStateMap.erase(temp); 389 414 } 415 tempGameState_=NULL; 390 416 } 391 417 … … 400 426 } 401 427 428 bool GameStateClient::saveShipCache(){ 429 if(myShip_==NULL) 430 myShip_ = orxonox::SpaceShip::getLocalShip(); 431 if(myShip_){ 432 // unsigned char *data = new unsigned char[myShip_->getSize()]; 433 int size=myShip_->getSize(0x3); 434 if(size==0) 435 return false; 436 unsigned char *data = new unsigned char [size]; 437 shipCache_ = myShip_->getData(data, 0x1); 438 return true; 439 }else 440 return false; 441 } 442 443 bool GameStateClient::loadShipCache(){ 444 if(myShip_){ 445 myShip_->updateData(shipCache_, 0x2); 446 if(shipCache_.data){ 447 delete[] shipCache_.data; 448 } 449 return true; 450 }else 451 return false; 452 } 402 453 403 454 //##### ADDED FOR TESTING PURPOSE ##### -
code/branches/network/src/network/GameStateClient.h
r1360 r1425 21 21 * 22 22 * Author: 23 * ...23 * Oliver Scheuss 24 24 * Co-authors: 25 * ...25 * Dumeni Manatschal 26 26 * 27 27 */ … … 33 33 // 34 34 // 35 // Author: <>, (C) 200735 // Author: Oliver Scheuss, (C) 2007 36 36 // 37 37 // Copyright: See COPYING file that comes with this distribution … … 46 46 #include "core/CorePrereqs.h" 47 47 #include "PacketTypes.h" 48 #include "objects/SpaceShip.h" 48 49 50 51 #define GAMESTATEID_INITIAL -1 49 52 50 53 namespace network … … 56 59 ~GameStateClient(); 57 60 61 void addGameState(GameStateCompressed *gs); 62 int processGameState(); 63 GameStateCompressed *popPartialGameState(); 64 void cleanup(); 65 private: 58 66 bool pushGameState(GameStateCompressed *compstate); 59 GameStateCompressed *popPartialGameState();60 private:61 67 bool loadSnapshot(GameState *state); 62 68 GameState *getPartialSnapshot(); 63 void cleanup();64 69 GameState *undiff(GameState *old, GameState *diff); 65 70 GameStateCompressed *compress_(GameState *a); … … 69 74 void removeObject(orxonox::Iterator<Synchronisable> &it); 70 75 void printGameStateMap(); 76 bool saveShipCache(); 77 bool loadShipCache(); 71 78 72 79 int last_diff_; 73 80 int last_gamestate_; 74 81 std::map<int, GameState *> gameStateMap; 82 GameStateCompressed *tempGameState_; // we save the received gamestates here during processQueue 83 orxonox::SpaceShip *myShip_; 84 syncData shipCache_; 75 85 76 86 -
code/branches/network/src/network/GameStateManager.cc
r1360 r1425 68 68 printGameStates(); 69 69 return; 70 } 71 72 void GameStateManager::addGameState(GameStateCompressed *gs, int clientID){ 73 if(!gs) 74 return; 75 std::map<int, GameStateCompressed*>::iterator it = gameStateQueue.find(clientID); 76 if(it!=gameStateQueue.end()){ 77 // delete obsolete gamestate 78 delete[] it->second->data; 79 delete it->second; 80 } 81 gameStateQueue[clientID] = gs; 82 return; 83 } 84 85 void GameStateManager::processGameStates(){ 86 std::map<int, GameStateCompressed*>::iterator it; 87 // now push only the most recent gamestates we received (ignore obsolete ones) 88 for(it = gameStateQueue.begin(); it!=gameStateQueue.end(); it++){ 89 pushGameState(it->second, it->first); 90 } 91 // now clear the queue 92 gameStateQueue.clear(); 70 93 } 71 94 -
code/branches/network/src/network/GameStateManager.h
r1293 r1425 72 72 ~GameStateManager(); 73 73 74 void addGameState(GameStateCompressed *gs, int clientID); 75 void processGameStates(); 76 74 77 void update(); 75 78 GameStateCompressed *popGameState(int clientID); 76 bool pushGameState(GameStateCompressed *gs, int clientID);77 79 void ackGameState(int clientID, int gamestateID); 78 80 void removeClient(ClientInformation *client); 79 private: 81 private: 82 bool pushGameState(GameStateCompressed *gs, int clientID); 80 83 void cleanup(); // "garbage handler" 81 84 GameState *getSnapshot(); … … 91 94 std::map<int, GameState*> gameStateMap; //map gsID to gamestate* 92 95 std::map<int, int> gameStateUsed; // save the number of clients, that use the specific gamestate 96 std::map<int, GameStateCompressed*> gameStateQueue; 93 97 GameState *reference; 94 98 ClientInformation *head_; -
code/branches/network/src/network/Server.cc
r1409 r1425 157 157 void Server::tick(float time) { 158 158 processQueue(); 159 gamestates->processGameStates(); 159 160 updateGamestate(); 160 161 // usleep(500000); // TODO remove … … 245 246 disconnectClient(temp); 246 247 //std::cout << "added gamestate" << std::endl; 247 } 248 }else 249 temp->resetFailures(); 248 250 added=true; 249 251 temp=temp->next(); … … 276 278 void Server::processGamestate( GameStateCompressed *data, int clientID){ 277 279 COUT(4) << "processing partial gamestate from client " << clientID << std::endl; 278 if(!gamestates->pushGameState(data, clientID))279 COUT(3) << "Could not push gamestate\t\t\t\t=====" << std::endl;280 gamestates->addGameState(data, clientID); 281 /*COUT(3) << "Could not push gamestate\t\t\t\t=====" << std::endl; 280 282 else 281 283 if(clients->findClient(clientID)) 282 clients->findClient(clientID)->resetFailures(); 284 clients->findClient(clientID)->resetFailures();*/ 283 285 } 284 286 -
code/branches/network/src/network/Synchronisable.cc
r1418 r1425 70 70 bool Synchronisable::create(){ 71 71 this->classID = this->getIdentifier()->getNetworkID(); 72 COUT(4) << "setting classid from " << this->getIdentifier()->getName() << " to: " << classID << std::endl; 72 73 return true; 73 74 } … … 156 157 * @return data containing all variables and their sizes 157 158 */ 158 syncData Synchronisable::getData(unsigned char *mem ){159 syncData Synchronisable::getData(unsigned char *mem, int mode){ 159 160 //std::cout << "inside getData" << std::endl; 161 if(mode==0x0) 162 mode=state_; 160 163 if(classID==0) 161 164 COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl; … … 172 175 for(i=syncList->begin(); n<datasize && i!=syncList->end(); ++i){ 173 176 //(std::memcpy(retVal.data+n, (const void*)(&(i->size)), sizeof(int)); 174 if( ((*i)->mode & state_) == 0 ){177 if( ((*i)->mode & mode) == 0 ){ 175 178 COUT(5) << "not getting data: " << std::endl; 176 179 continue; // this variable should only be received … … 199 202 * @return true/false 200 203 */ 201 bool Synchronisable::updateData(syncData vars){ 204 bool Synchronisable::updateData(syncData vars, int mode){ 205 if(mode==0x0) 206 mode=state_; 202 207 unsigned char *data=vars.data; 203 208 std::list<synchronisableVariable *>::iterator i; … … 208 213 COUT(5) << "Synchronisable: objectID " << vars.objectID << ", classID " << vars.classID << " size: " << vars.length << " synchronising data" << std::endl; 209 214 for(i=syncList->begin(); i!=syncList->end(); i++){ 210 if( ((*i)->mode ^ state_) == 0 ){215 if( ((*i)->mode ^ mode) == 0 ){ 211 216 COUT(5) << "synchronisable: not updating variable " << std::endl; 212 continue; // this variable should only be updated217 continue; // this variable should only be set 213 218 } 214 219 COUT(5) << "Synchronisable: element size: " << (*i)->size << " type: " << (*i)->type << std::endl; … … 235 240 * @return amount of bytes 236 241 */ 237 int Synchronisable::getSize( ){242 int Synchronisable::getSize(int mode){ 238 243 int tsize=0; 244 if(mode==0x0) 245 mode=state_; 239 246 std::list<synchronisableVariable *>::iterator i; 240 247 for(i=syncList->begin(); i!=syncList->end(); i++){ 241 if( ((*i)->mode & state_) == 0 )248 if( ((*i)->mode & mode) == 0 ) 242 249 continue; // this variable should only be received, so dont add its size to the send-size 243 250 switch((*i)->type){ -
code/branches/network/src/network/Synchronisable.h
r1418 r1425 83 83 void registerVar(void *var, int size, variableType t, int mode=1); 84 84 // syncData getData(); 85 syncData getData(unsigned char *mem );86 int getSize( );87 bool updateData(syncData vars );85 syncData getData(unsigned char *mem, int mode=0x0); 86 int getSize(int mode=0x0); 87 bool updateData(syncData vars, int mode=0x0); 88 88 void setBacksync(bool sync); 89 89 bool getBacksync();
Note: See TracChangeset
for help on using the changeset viewer.