Changeset 3240 for code/branches/netp6/src/network/GamestateManager.cc
- Timestamp:
- Jun 28, 2009, 3:04:30 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/netp6/src/network/GamestateManager.cc
r3227 r3240 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 … … 71 77 delete (*it2).second; 72 78 } 73 delete trafficControl_; 79 delete this->trafficControl_; 80 delete this->threadMutex_; 81 delete this->threadPool_; 74 82 } 75 83 … … 116 124 return true; 117 125 } 118 119 120 packet::Gamestate *GamestateManager::popGameState(unsigned int clientID) { 126 127 void GamestateManager::sendGamestates() 128 { 129 ClientInformation *temp = ClientInformation::getBegin(); 130 std::queue<packet::Gamestate*> clientGamestates; 131 while(temp != NULL){ 132 if( !(temp->getSynched()) ){ 133 COUT(5) << "Server: not sending gamestate" << std::endl; 134 temp=temp->next(); 135 if(!temp) 136 break; 137 continue; 138 } 139 COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl; 140 COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl; 141 int cid = temp->getID(); //get client id 142 143 packet::Gamestate *gs; 144 unsigned int gID = temp->getGamestateID(); 145 if(!reference) 146 return; 147 148 packet::Gamestate *client=0; 149 if(gID != GAMESTATEID_INITIAL){ 150 assert(gamestateMap_.find(cid)!=gamestateMap_.end()); 151 std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateMap_[cid].find(gID); 152 if(it!=gamestateMap_[cid].end()) 153 { 154 client = it->second; 155 } 156 } 157 158 clientGamestates.push(0); 159 // finishGamestate( cid, clientGamestates.back(), client, reference ); 160 //FunctorMember<GamestateManager>* functor = 161 ExecutorMember<GamestateManager>* executor = createExecutor( createFunctor(&GamestateManager::finishGamestate) ); 162 executor->setObject(this); 163 executor->setDefaultValues( cid, &clientGamestates.back(), client, reference ); 164 // (*static_cast<Executor*>(executor))(); 165 this->threadPool_->passFunction( executor, true ); 166 // (*functor)( cid, &(clientGamestates.back()), client, reference ); 167 168 temp = temp->next(); 169 } 170 171 threadPool_->synchronise(); 172 173 while( !clientGamestates.empty() ) 174 { 175 if(clientGamestates.front()) 176 clientGamestates.front()->send(); 177 clientGamestates.pop(); 178 } 179 } 180 181 182 void GamestateManager::finishGamestate( unsigned int clientID, packet::Gamestate** destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ) { 121 183 //why are we searching the same client's gamestate id as we searched in 122 184 //Server::sendGameState? 123 packet::Gamestate *gs;124 unsigned int gID = ClientInformation::findClient(clientID)->getGamestateID();125 if(!reference)126 return 0;127 gs = reference->doSelection(clientID, 10000);128 185 // save the (undiffed) gamestate in the clients gamestate map 129 gamestateMap_[clientID][gs->getID()]=gs;130 186 //chose wheather the next gamestate is the first or not 131 packet::Gamestate *client=0; 132 if(gID != GAMESTATEID_INITIAL){ 133 assert(gamestateMap_.find(clientID)!=gamestateMap_.end()); 134 std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateMap_[clientID].find(gID); 135 if(it!=gamestateMap_[clientID].end()) 136 { 137 client = it->second; 138 } 139 } 140 if(client){ 187 188 packet::Gamestate *gs = gamestate->doSelection(clientID, 20000); 189 // packet::Gamestate *gs = new packet::Gamestate(*gamestate); 190 // packet::Gamestate *gs = new packet::Gamestate(); 191 // gs->collectData( id_, 0x1 ); 192 this->threadMutex_->lock(); 193 gamestateMap_[clientID][gamestate->getID()]=gs; 194 this->threadMutex_->unlock(); 195 196 if(base) 197 { 198 141 199 // COUT(3) << "diffing" << std::endl; 142 200 // packet::Gamestate* gs1 = gs; 143 packet::Gamestate *diffed = gs->diff( client);201 packet::Gamestate *diffed = gs->diff(base); 144 202 //packet::Gamestate *gs2 = diffed->undiff(gs); 145 203 // assert(*gs == *gs2); … … 150 208 } 151 209 else{ 152 // COUT(3) << "not diffing" << std::endl;153 210 gs = new packet::Gamestate(*gs); 154 211 } 212 213 155 214 bool b = gs->compressData(); 156 215 assert(b); 157 COUT(4) << "sending gamestate with id " << gs->getID(); 158 if(gs->isDiffed()) 159 COUT(4) << " and baseid " << gs->getBaseID() << endl; 160 else 161 COUT(4) << endl; 162 return gs; 216 // COUT(4) << "sending gamestate with id " << gs->getID(); 217 // if(gamestate->isDiffed()) 218 // COUT(4) << " and baseid " << gs->getBaseID() << endl; 219 // else 220 // COUT(4) << endl; 221 gs->setClientID(clientID); 222 *destgamestate = gs; 163 223 } 164 224
Note: See TracChangeset
for help on using the changeset viewer.