Changeset 3304 for code/trunk/src/network/GamestateManager.cc
- Timestamp:
- Jul 18, 2009, 6:23:31 PM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/netp6 (added) merged: 3215,3226-3227,3229-3231,3240,3242,3251-3252,3256,3258-3259,3263-3264,3267-3268,3277,3283-3284,3289,3298-3299,3302
- Property svn:mergeinfo changed
-
code/trunk/src/network/GamestateManager.cc
r3301 r3304 42 42 43 43 #include <cassert> 44 #include <queue> 45 // #include <boost/thread/mutex.hpp> 44 46 45 47 #include "util/Debug.h" 48 #include "core/Executor.h" 49 #include "core/ThreadPool.h" 46 50 #include "ClientInformation.h" 47 51 #include "packet/Acknowledgement.h" … … 56 60 { 57 61 trafficControl_ = new TrafficControl(); 62 // threadMutex_ = new boost::mutex(); 63 // threadPool_ = new ThreadPool(); 58 64 } 59 65 … … 61 67 { 62 68 if( this->reference ) 63 delete this->reference;64 for( std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateQueue.begin(); it != gamestateQueue.end(); it++)69 delete this->reference;std::map<unsigned int, packet::Gamestate*>::iterator it; 70 for( it = gamestateQueue.begin(); it != gamestateQueue.end(); ++it ) 65 71 delete (*it).second; 66 delete trafficControl_; 72 std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator it1; 73 std::map<unsigned int, packet::Gamestate*>::iterator it2; 74 for( it1 = gamestateMap_.begin(); it1 != gamestateMap_.end(); ++it1 ) 75 { 76 for( it2 = it1->second.begin(); it2 != it1->second.end(); ++it2 ) 77 delete (*it2).second; 78 } 79 delete this->trafficControl_; 80 // delete this->threadMutex_; 81 // delete this->threadPool_; 67 82 } 68 83 … … 84 99 85 100 bool GamestateManager::processGamestates(){ 101 if( this->gamestateQueue.empty() ) 102 return true; 86 103 std::map<unsigned int, packet::Gamestate*>::iterator it; 87 104 // now push only the most recent gamestates we received (ignore obsolete ones) … … 109 126 return true; 110 127 } 111 112 113 packet::Gamestate *GamestateManager::popGameState(unsigned int clientID) { 128 129 void GamestateManager::sendGamestates() 130 { 131 ClientInformation *temp = ClientInformation::getBegin(); 132 std::queue<packet::Gamestate*> clientGamestates; 133 while(temp != NULL){ 134 if( !(temp->getSynched()) ){ 135 COUT(5) << "Server: not sending gamestate" << std::endl; 136 temp=temp->next(); 137 if(!temp) 138 break; 139 continue; 140 } 141 COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl; 142 COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl; 143 int cid = temp->getID(); //get client id 144 145 unsigned int gID = temp->getGamestateID(); 146 if(!reference) 147 return; 148 149 packet::Gamestate *client=0; 150 if(gID != GAMESTATEID_INITIAL){ 151 assert(gamestateMap_.find(cid)!=gamestateMap_.end()); 152 std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateMap_[cid].find(gID); 153 if(it!=gamestateMap_[cid].end()) 154 { 155 client = it->second; 156 } 157 } 158 159 clientGamestates.push(0); 160 finishGamestate( cid, &clientGamestates.back(), client, reference ); 161 //FunctorMember<GamestateManager>* functor = 162 // ExecutorMember<GamestateManager>* executor = createExecutor( createFunctor(&GamestateManager::finishGamestate) ); 163 // executor->setObject(this); 164 // executor->setDefaultValues( cid, &clientGamestates.back(), client, reference ); 165 // (*static_cast<Executor*>(executor))(); 166 // this->threadPool_->passFunction( executor, true ); 167 // (*functor)( cid, &(clientGamestates.back()), client, reference ); 168 169 temp = temp->next(); 170 } 171 172 // threadPool_->synchronise(); 173 174 while( !clientGamestates.empty() ) 175 { 176 if(clientGamestates.front()) 177 clientGamestates.front()->send(); 178 clientGamestates.pop(); 179 } 180 } 181 182 183 void GamestateManager::finishGamestate( unsigned int clientID, packet::Gamestate** destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ) { 114 184 //why are we searching the same client's gamestate id as we searched in 115 185 //Server::sendGameState? 116 packet::Gamestate *gs;117 unsigned int gID = ClientInformation::findClient(clientID)->getGamestateID();118 if(!reference)119 return 0;120 gs = reference->doSelection(clientID, 10000);121 186 // save the (undiffed) gamestate in the clients gamestate map 122 gamestateMap_[clientID][gs->getID()]=gs;123 187 //chose wheather the next gamestate is the first or not 124 packet::Gamestate *client=0; 125 if(gID != GAMESTATEID_INITIAL){ 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; 131 } 132 } 133 if(client){ 188 189 packet::Gamestate *gs = gamestate->doSelection(clientID, 20000); 190 // packet::Gamestate *gs = new packet::Gamestate(*gamestate); 191 // packet::Gamestate *gs = new packet::Gamestate(); 192 // gs->collectData( id_, 0x1 ); 193 // this->threadMutex_->lock(); 194 gamestateMap_[clientID][gamestate->getID()]=gs; 195 // this->threadMutex_->unlock(); 196 197 if(base) 198 { 199 134 200 // COUT(3) << "diffing" << std::endl; 135 201 // packet::Gamestate* gs1 = gs; 136 packet::Gamestate *diffed = gs->diff( client);202 packet::Gamestate *diffed = gs->diff(base); 137 203 //packet::Gamestate *gs2 = diffed->undiff(gs); 138 204 // assert(*gs == *gs2); … … 143 209 } 144 210 else{ 145 // COUT(3) << "not diffing" << std::endl;146 211 gs = new packet::Gamestate(*gs); 147 212 } 213 214 148 215 bool b = gs->compressData(); 149 216 assert(b); 150 COUT(4) << "sending gamestate with id " << gs->getID(); 151 if(gs->isDiffed()) 152 COUT(4) << " and baseid " << gs->getBaseID() << endl; 153 else 154 COUT(4) << endl; 155 return gs; 217 // COUT(4) << "sending gamestate with id " << gs->getID(); 218 // if(gamestate->isDiffed()) 219 // COUT(4) << " and baseid " << gs->getBaseID() << endl; 220 // else 221 // COUT(4) << endl; 222 gs->setClientID(clientID); 223 *destgamestate = gs; 156 224 } 157 225 … … 175 243 176 244 assert(curid==GAMESTATEID_INITIAL || curid<gamestateID); 177 COUT( 4) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl;245 COUT(5) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl; 178 246 std::map<unsigned int, packet::Gamestate*>::iterator it; 179 247 for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end() && it->first<gamestateID; ){
Note: See TracChangeset
for help on using the changeset viewer.