Changeset 3240 for code/branches/netp6/src/network
- Timestamp:
- Jun 28, 2009, 3:04:30 PM (16 years ago)
- Location:
- code/branches/netp6/src/network
- Files:
-
- 8 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 -
code/branches/netp6/src/network/GamestateManager.h
r3214 r3240 45 45 #include <map> 46 46 #include "GamestateHandler.h" 47 #include "core/CorePrereqs.h" 47 48 48 49 namespace orxonox … … 73 74 bool processGamestates(); 74 75 bool update(); 75 packet::Gamestate *popGameState(unsigned int clientID); 76 void sendGamestates(); 77 // packet::Gamestate *popGameState(unsigned int clientID); 78 void finishGamestate( unsigned int clientID, packet::Gamestate** destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ); 76 79 77 80 bool getSnapshot(); … … 79 82 bool ack(unsigned int gamestateID, unsigned int clientID); 80 83 void removeClient(ClientInformation *client); 81 84 private: 82 85 bool processGamestate(packet::Gamestate *gs); 83 86 84 87 std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> > gamestateMap_; 85 //std::map<int, packet::Gamestate*> gamestateMap; //map gsID to gamestate*86 //std::map<int, int> gamestateUsed; // save the number of clients, that use the specific gamestate87 88 std::map<unsigned int, packet::Gamestate*> gamestateQueue; 88 89 packet::Gamestate *reference; 89 90 TrafficControl *trafficControl_; 90 91 unsigned int id_; 92 boost::mutex* threadMutex_; 93 ThreadPool* threadPool_; 91 94 }; 92 95 -
code/branches/netp6/src/network/Host.cc
r3214 r3240 74 74 } 75 75 76 77 // bool Host::chat(std::string& message){78 // if(!instance_)79 // return false;80 // packet::Chat *c = new packet::Chat(message, getPlayerID());81 // return instance_->sendChat(c);82 // }83 84 // bool Host::receiveChat(packet::Chat *message, unsigned int clientID){85 // if(instance_)86 // return instance_->processChat(message, clientID);87 // else88 // return false;89 // }90 91 76 /** 92 77 * This function returns the ID of the player -
code/branches/netp6/src/network/Server.cc
r3214 r3240 48 48 #include "core/Clock.h" 49 49 #include "core/ObjectList.h" 50 #include "core/Executor.h" 51 #include "core/ThreadPool.h" 50 52 #include "packet/Chat.h" 51 53 #include "packet/ClassID.h" … … 68 70 */ 69 71 Server::Server() { 70 t imeSinceLastUpdate_=0;71 gamestates_ = new GamestateManager();72 this->timeSinceLastUpdate_=0; 73 this->threadPool_ = new ThreadPool(); 72 74 } 73 75 74 76 Server::Server(int port){ 75 77 this->setPort( port ); 76 t imeSinceLastUpdate_=0;77 gamestates_ = new GamestateManager();78 this->timeSinceLastUpdate_=0; 79 this->threadPool_ = new ThreadPool(); 78 80 } 79 81 … … 86 88 this->setPort( port ); 87 89 this->setBindAddress( bindAddress ); 88 t imeSinceLastUpdate_=0;89 gamestates_ = new GamestateManager();90 this->timeSinceLastUpdate_=0; 91 this->threadPool_ = new ThreadPool(); 90 92 } 91 93 … … 94 96 */ 95 97 Server::~Server(){ 96 if(gamestates_) 97 delete gamestates_; 98 delete this->threadPool_; 98 99 } 99 100 … … 138 139 */ 139 140 void Server::update(const Clock& time) { 141 // receive incoming packets 140 142 Connection::processQueue(); 141 gamestates_->processGamestates(); 143 // process incoming gamestates 144 GamestateManager::processGamestates(); 145 146 // pass sendFunctionCalls to worker thread pool 147 ExecutorStatic* functioncalls = createExecutor( createFunctor(&FunctionCallManager::sendCalls) ); 148 this->threadPool_->passFunction( functioncalls, true ); 149 150 this->threadPool_->synchronise(); 151 142 152 //this steers our network frequency 143 153 timeSinceLastUpdate_+=time.getDeltaTime(); … … 145 155 { 146 156 timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD; 157 // ExecutorMember<GamestateManager>* updategamestate = createExecutor( createFunctor(&GamestateManager::updateGamestate); 158 // updategamestate->setObject( static_cast<GamestateManager*>(this) ); 159 // this->threadPool_->passFunction( updategamestate ); 147 160 updateGamestate(); 148 FunctionCallManager::sendCalls();149 161 } 150 162 sendPackets(); // flush the enet queue … … 175 187 */ 176 188 void Server::updateGamestate() { 177 //if( ClientInformation::getBegin()==NULL )189 if( ClientInformation::getBegin()==NULL ) 178 190 //no client connected 179 //return;180 gamestates_->update();191 return; 192 GamestateManager::update(); 181 193 COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl; 182 194 //std::cout << "updated gamestate, sending it" << std::endl; … … 197 209 */ 198 210 bool Server::sendGameState() { 199 COUT(5) << "Server: starting function sendGameState" << std::endl; 200 ClientInformation *temp = ClientInformation::getBegin(); 201 bool added=false; 202 while(temp != NULL){ 203 if( !(temp->getSynched()) ){ 204 COUT(5) << "Server: not sending gamestate" << std::endl; 205 temp=temp->next(); 206 if(!temp) 207 break; 208 //think this works without continue 209 continue; 210 } 211 COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl; 212 COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl; 213 int gid = temp->getGamestateID(); //get gamestate id 214 int cid = temp->getID(); //get client id 215 COUT(5) << "Server: got acked (gamestate) ID from clientlist: " << gid << std::endl; 216 packet::Gamestate *gs = gamestates_->popGameState(cid); 217 if(gs==NULL){ 218 COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl; 219 temp = temp->next(); 220 continue; 221 } 222 //std::cout << "adding gamestate" << std::endl; 223 gs->setClientID(cid); 224 if ( !gs->send() ){ 225 COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl; 226 temp->addFailure(); 227 }else 228 temp->resetFailures(); 229 added=true; 230 temp=temp->next(); 231 // gs gets automatically deleted by enet callback 232 } 211 // COUT(5) << "Server: starting function sendGameState" << std::endl; 212 // ClientInformation *temp = ClientInformation::getBegin(); 213 // bool added=false; 214 // while(temp != NULL){ 215 // if( !(temp->getSynched()) ){ 216 // COUT(5) << "Server: not sending gamestate" << std::endl; 217 // temp=temp->next(); 218 // if(!temp) 219 // break; 220 // continue; 221 // } 222 // COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl; 223 // COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl; 224 // int cid = temp->getID(); //get client id 225 // packet::Gamestate *gs = GamestateManager::popGameState(cid); 226 // if(gs==NULL){ 227 // COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl; 228 // temp = temp->next(); 229 // continue; 230 // } 231 // //std::cout << "adding gamestate" << std::endl; 232 // gs->setClientID(cid); 233 // if ( !gs->send() ){ 234 // COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl; 235 // temp->addFailure(); 236 // }else 237 // temp->resetFailures(); 238 // added=true; 239 // temp=temp->next(); 240 // // gs gets automatically deleted by enet callback 241 // } 242 GamestateManager::sendGamestates(); 233 243 return true; 234 244 } … … 324 334 void Server::disconnectClient( ClientInformation *client ){ 325 335 ServerConnection::disconnectClient( client ); 326 gamestates_->removeClient(client);336 GamestateManager::removeClient(client); 327 337 // inform all the listeners 328 338 ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin(); -
code/branches/netp6/src/network/Server.h
r3214 r3240 34 34 #include "core/CorePrereqs.h" 35 35 #include "Host.h" 36 #include "GamestateManager.h" 36 37 #include "ServerConnection.h" 37 38 … … 43 44 * It implements all functions necessary for a Server 44 45 */ 45 class _NetworkExport Server : public Host, public ServerConnection {46 class _NetworkExport Server : public Host, public ServerConnection, public GamestateManager{ 46 47 public: 47 48 Server(); … … 63 64 unsigned int shipID(){return 0;} 64 65 unsigned int playerID(){return 0;} 65 66 66 67 void addClient(ENetEvent *event); 67 68 bool createClient(int clientID); … … 75 76 void syncClassid(unsigned int clientID); 76 77 77 GamestateManager *gamestates_; 78 79 78 ThreadPool* threadPool_; 80 79 float timeSinceLastUpdate_; 81 80 }; -
code/branches/netp6/src/network/synchronisable/NetworkCallbackManager.cc
r3214 r3240 44 44 if (it != callbackSet_.end()) 45 45 { 46 delete (*it);47 46 callbackSet_.erase(it); 47 delete cb; 48 48 } 49 49 } -
code/branches/netp6/src/network/synchronisable/Synchronisable.cc
r3214 r3240 247 247 return 0; 248 248 uint32_t tempsize = 0; 249 #ifndef NDEBUG 249 250 if (this->classID==0) 250 251 COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl; 252 #endif 251 253 252 254 if (this->classID == static_cast<uint32_t>(-1)) -
code/branches/netp6/src/network/synchronisable/SynchronisableVariable.h
r3214 r3240 114 114 { 115 115 if (this->callback_ != 0) 116 { 116 117 NetworkCallbackManager::deleteCallback(this->callback_); //safe call for deletion 118 // this is neccessary because for example for a Vector3 all 3 components of the vector use the same callback 119 } 117 120 } 118 121
Note: See TracChangeset
for help on using the changeset viewer.