Changeset 2087 for code/trunk/src/network/GamestateManager.cc
- Timestamp:
- Nov 1, 2008, 7:04:09 PM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/network/GamestateManager.cc
r1907 r2087 64 64 return getSnapshot(); 65 65 } 66 67 bool GamestateManager::add(packet::Gamestate *gs, int clientID){66 67 bool GamestateManager::add(packet::Gamestate *gs, unsigned int clientID){ 68 68 assert(gs); 69 std::map< int, packet::Gamestate*>::iterator it = gamestateQueue.find(clientID);69 std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateQueue.find(clientID); 70 70 if(it!=gamestateQueue.end()){ 71 71 // delete obsolete gamestate … … 75 75 return true; 76 76 } 77 77 78 78 bool GamestateManager::processGamestates(){ 79 std::map< int, packet::Gamestate*>::iterator it;79 std::map<unsigned int, packet::Gamestate*>::iterator it; 80 80 // now push only the most recent gamestates we received (ignore obsolete ones) 81 81 for(it = gamestateQueue.begin(); it!=gamestateQueue.end(); it++){ 82 assert(processGamestate(it->second)); 82 bool b = processGamestate(it->second); 83 assert(b); 83 84 delete it->second; 84 85 } … … 87 88 return true; 88 89 } 89 90 90 91 91 92 bool GamestateManager::getSnapshot(){ 92 93 reference = new packet::Gamestate(); 93 reference->collectData(++id_);94 //COUT(4) << "inserting gamestate: " << reference << std::endl;95 //gamestateMap_.insert(std::pair<int, packet::Gamestate*>(id_, reference));96 // gamestateUsed[id_]=0; 97 return true; 98 } 99 94 if(!reference->collectData(++id_)){ //we have no data to send 95 delete reference; 96 reference=0; 97 } 98 return true; 99 } 100 100 101 /** 101 102 * this function is used to keep the memory usage low 102 103 * it tries to delete all the unused gamestates 103 * 104 * 104 * 105 * 105 106 */ 106 107 /* void GamestateManager::cleanup(){ … … 126 127 }*/ 127 128 128 packet::Gamestate *GamestateManager::popGameState( int clientID) {129 packet::Gamestate *GamestateManager::popGameState(unsigned int clientID) { 129 130 //why are we searching the same client's gamestate id as we searched in 130 131 //Server::sendGameState? 131 132 packet::Gamestate *gs; 132 int gID = ClientInformation::findClient(clientID)->getGamestateID(); 133 unsigned int gID = ClientInformation::findClient(clientID)->getGamestateID(); 134 if(!reference) 135 return 0; 133 136 gs = reference->doSelection(clientID); 134 137 // gs = new packet::Gamestate(*reference); … … 139 142 packet::Gamestate *client=NULL; 140 143 if(gID != GAMESTATEID_INITIAL){ 141 std::map<unsigned int, std::map< int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(clientID);144 std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(clientID); 142 145 if(clientMap!=gamestateMap_.end()){ 143 std::map< int, packet::Gamestate*>::iterator it = clientMap->second.find(gID);146 std::map<unsigned int, packet::Gamestate*>::iterator it = clientMap->second.find(gID); 144 147 if(it!=clientMap->second.end()) 145 148 client = it->second; … … 158 161 return gs; 159 162 } 160 161 162 bool GamestateManager::ack( int gamestateID,int clientID) {163 164 165 bool GamestateManager::ack(unsigned int gamestateID, unsigned int clientID) { 163 166 ClientInformation *temp = ClientInformation::findClient(clientID); 164 167 assert(temp); 165 int curid = temp->getGamestateID();166 168 unsigned int curid = temp->getGamestateID(); 169 167 170 if(gamestateID == 0){ 168 171 temp->setGamestateID(GAMESTATEID_INITIAL); 169 172 return true; 170 173 } 171 172 assert(curid <gamestateID);174 175 assert(curid==(unsigned int)GAMESTATEID_INITIAL || curid<gamestateID); 173 176 COUT(4) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl; 174 std::map< int, packet::Gamestate*>::iterator it, tempit;177 std::map<unsigned int, packet::Gamestate*>::iterator it, tempit; 175 178 for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end() && it->first<gamestateID; it++){ 176 179 delete it->second; … … 184 187 void GamestateManager::removeClient(ClientInformation* client){ 185 188 assert(client); 186 std::map<unsigned int, std::map< int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(client->getID());189 std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(client->getID()); 187 190 // first delete all remained gamestates 188 std::map< int, packet::Gamestate*>::iterator it;191 std::map<unsigned int, packet::Gamestate*>::iterator it; 189 192 for(it=clientMap->second.begin(); it!=clientMap->second.end(); it++) 190 193 delete it->second; … … 192 195 gamestateMap_.erase(clientMap); 193 196 } 194 197 195 198 bool GamestateManager::processGamestate(packet::Gamestate *gs){ 196 199 if(gs->isCompressed())
Note: See TracChangeset
for help on using the changeset viewer.