Changeset 2662 for code/trunk/src/network/GamestateManager.cc
- Timestamp:
- Feb 14, 2009, 10:17:35 PM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/network/GamestateManager.cc
r2171 r2662 49 49 #include "core/BaseObject.h" 50 50 #include "ClientInformation.h" 51 #include "Synchronisable.h" 51 #include "synchronisable/Synchronisable.h" 52 #include "synchronisable/NetworkCallbackManager.h" 53 #include "packet/Acknowledgement.h" 52 54 53 55 namespace orxonox 54 56 { 55 GamestateManager::GamestateManager() { 56 id_=0; 57 } 58 59 GamestateManager::~GamestateManager() { 57 GamestateManager::GamestateManager() : 58 reference(0), id_(0) 59 { 60 trafficControl_ = new TrafficControl(); 61 } 62 63 GamestateManager::~GamestateManager() 64 { 65 delete trafficControl_; 60 66 } 61 67 … … 86 92 // now clear the queue 87 93 gamestateQueue.clear(); 94 //and call all queued callbacks 95 NetworkCallbackManager::callCallbacks(); 88 96 return true; 89 97 } … … 91 99 92 100 bool GamestateManager::getSnapshot(){ 101 if ( reference != 0 ) 102 delete reference; 93 103 reference = new packet::Gamestate(); 94 104 if(!reference->collectData(++id_)){ //we have no data to send … … 99 109 } 100 110 101 /**102 * this function is used to keep the memory usage low103 * it tries to delete all the unused gamestates104 *105 *106 */107 /* void GamestateManager::cleanup(){108 std::map<int,int>::iterator it = gamestateUsed.begin();109 while(it!=gamestateUsed.end()){110 if((id_-(*it).first)<KEEP_GAMESTATES)111 break;112 if( (*it).second <= 0 ){113 COUT(5) << "GameStateManager: deleting gamestate with id: " << (*it).first << ", uses: " << (*it).second << std::endl;114 std::map<int, packet::Gamestate *>::iterator tempit = gamestateMap.find((*it).first);115 if( tempit != gamestateMap.end() ){116 packet::Gamestate *temp = tempit->second;117 if(temp){118 delete gamestateMap[(*it).first];119 gamestateMap.erase((*it).first);120 }121 }122 gamestateUsed.erase(it++);123 continue;124 }125 it++;126 }127 }*/128 111 129 112 packet::Gamestate *GamestateManager::popGameState(unsigned int clientID) { … … 134 117 if(!reference) 135 118 return 0; 136 gs = reference->doSelection(clientID); 137 // gs = new packet::Gamestate(*reference); 119 gs = reference->doSelection(clientID, 10000); 138 120 // gs = new packet::Gamestate(*reference); 139 121 // save the (undiffed) gamestate in the clients gamestate map 140 gamestateMap_[clientID] .insert(std::pair<int, packet::Gamestate*>(gs->getID(), gs));122 gamestateMap_[clientID][gs->getID()]=gs; 141 123 //chose wheather the next gamestate is the first or not 142 packet::Gamestate *client= NULL;124 packet::Gamestate *client=0; 143 125 if(gID != GAMESTATEID_INITIAL){ 144 std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(clientID);145 if(clientMap!=gamestateMap_.end()){146 std::map<unsigned int, packet::Gamestate*>::iterator it = clientMap->second.find(gID);147 if(it!=clientMap->second.end())148 126 assert(gamestateMap_.find(clientID)!=gamestateMap_.end()); 127 std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateMap_[clientID].find(gID); 128 if(it!=gamestateMap_[clientID].end()) 129 { 130 client = it->second; 149 131 } 150 132 } … … 152 134 // COUT(3) << "diffing" << std::endl; 153 135 gs = gs->diff(client); 136 // gs = new packet::Gamestate(*gs); 154 137 } 155 138 else{ … … 159 142 bool b = gs->compressData(); 160 143 assert(b); 144 COUT(4) << "sending gamestate with id " << gs->getID(); 145 if(gs->isDiffed()) 146 COUT(4) << " and baseid " << gs->getBaseID() << endl; 147 else 148 COUT(4) << endl; 161 149 return gs; 162 150 } … … 168 156 unsigned int curid = temp->getGamestateID(); 169 157 170 if(gamestateID == 0){158 if(gamestateID == ACKID_NACK){ 171 159 temp->setGamestateID(GAMESTATEID_INITIAL); 160 // now delete all saved gamestates for this client 161 std::map<unsigned int, packet::Gamestate*>::iterator it; 162 for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end(); ){ 163 delete it->second; 164 gamestateMap_[clientID].erase(it++); 165 } 172 166 return true; 173 167 } … … 175 169 assert(curid==(unsigned int)GAMESTATEID_INITIAL || curid<gamestateID); 176 170 COUT(4) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl; 177 std::map<unsigned int, packet::Gamestate*>::iterator it, tempit; 178 for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end() && it->first<gamestateID; it++){ 179 delete it->second; 180 tempit=it++; 181 gamestateMap_[clientID].erase(tempit); 171 std::map<unsigned int, packet::Gamestate*>::iterator it; 172 for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end() && it->first<gamestateID; ){ 173 delete it->second; 174 gamestateMap_[clientID].erase(it++); 182 175 } 183 176 temp->setGamestateID(gamestateID); 177 TrafficControl::processAck(clientID, gamestateID); 184 178 return true; 185 179 }
Note: See TracChangeset
for help on using the changeset viewer.