Changeset 3304 for code/trunk/src/network/Server.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/Server.cc
r3214 r3304 48 48 #include "core/Clock.h" 49 49 #include "core/ObjectList.h" 50 #include "core/Executor.h" 50 51 #include "packet/Chat.h" 51 52 #include "packet/ClassID.h" … … 68 69 */ 69 70 Server::Server() { 70 timeSinceLastUpdate_=0; 71 gamestates_ = new GamestateManager(); 71 this->timeSinceLastUpdate_=0; 72 72 } 73 73 74 74 Server::Server(int port){ 75 75 this->setPort( port ); 76 timeSinceLastUpdate_=0; 77 gamestates_ = new GamestateManager(); 76 this->timeSinceLastUpdate_=0; 78 77 } 79 78 … … 86 85 this->setPort( port ); 87 86 this->setBindAddress( bindAddress ); 88 timeSinceLastUpdate_=0; 89 gamestates_ = new GamestateManager(); 87 this->timeSinceLastUpdate_=0; 90 88 } 91 89 … … 94 92 */ 95 93 Server::~Server(){ 96 if(gamestates_)97 delete gamestates_;98 94 } 99 95 … … 138 134 */ 139 135 void Server::update(const Clock& time) { 136 // receive incoming packets 140 137 Connection::processQueue(); 141 gamestates_->processGamestates(); 142 //this steers our network frequency 143 timeSinceLastUpdate_+=time.getDeltaTime(); 144 if(timeSinceLastUpdate_>=NETWORK_PERIOD) 138 139 if ( ClientInformation::hasClients() ) 145 140 { 146 timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD; 147 updateGamestate(); 141 // process incoming gamestates 142 GamestateManager::processGamestates(); 143 144 // send function calls to clients 148 145 FunctionCallManager::sendCalls(); 149 } 150 sendPackets(); // flush the enet queue 146 147 //this steers our network frequency 148 timeSinceLastUpdate_+=time.getDeltaTime(); 149 if(timeSinceLastUpdate_>=NETWORK_PERIOD) 150 { 151 timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD; 152 updateGamestate(); 153 } 154 sendPackets(); // flush the enet queue 155 } 151 156 } 152 157 … … 175 180 */ 176 181 void Server::updateGamestate() { 177 //if( ClientInformation::getBegin()==NULL )182 if( ClientInformation::getBegin()==NULL ) 178 183 //no client connected 179 //return;180 gamestates_->update();184 return; 185 GamestateManager::update(); 181 186 COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl; 182 187 //std::cout << "updated gamestate, sending it" << std::endl; … … 197 202 */ 198 203 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 } 204 // COUT(5) << "Server: starting function sendGameState" << std::endl; 205 // ClientInformation *temp = ClientInformation::getBegin(); 206 // bool added=false; 207 // while(temp != NULL){ 208 // if( !(temp->getSynched()) ){ 209 // COUT(5) << "Server: not sending gamestate" << std::endl; 210 // temp=temp->next(); 211 // if(!temp) 212 // break; 213 // continue; 214 // } 215 // COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl; 216 // COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl; 217 // int cid = temp->getID(); //get client id 218 // packet::Gamestate *gs = GamestateManager::popGameState(cid); 219 // if(gs==NULL){ 220 // COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl; 221 // temp = temp->next(); 222 // continue; 223 // } 224 // //std::cout << "adding gamestate" << std::endl; 225 // gs->setClientID(cid); 226 // if ( !gs->send() ){ 227 // COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl; 228 // temp->addFailure(); 229 // }else 230 // temp->resetFailures(); 231 // added=true; 232 // temp=temp->next(); 233 // // gs gets automatically deleted by enet callback 234 // } 235 GamestateManager::sendGamestates(); 233 236 return true; 234 237 } … … 324 327 void Server::disconnectClient( ClientInformation *client ){ 325 328 ServerConnection::disconnectClient( client ); 326 gamestates_->removeClient(client);329 GamestateManager::removeClient(client); 327 330 // inform all the listeners 328 331 ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin();
Note: See TracChangeset
for help on using the changeset viewer.