Changeset 3240 for code/branches/netp6/src/network/Server.cc
- Timestamp:
- Jun 28, 2009, 3:04:30 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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();
Note: See TracChangeset
for help on using the changeset viewer.