Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 28, 2009, 3:04:30 PM (15 years ago)
Author:
scheusso
Message:

a lot of cleanup
some bugfixes (Thread, ThreadPool)
the biggest part of the network (~80% cpu time) is now multithreaded (1 thread for each client)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/netp6/src/network/Server.cc

    r3214 r3240  
    4848#include "core/Clock.h"
    4949#include "core/ObjectList.h"
     50#include "core/Executor.h"
     51#include "core/ThreadPool.h"
    5052#include "packet/Chat.h"
    5153#include "packet/ClassID.h"
     
    6870  */
    6971  Server::Server() {
    70     timeSinceLastUpdate_=0;
    71     gamestates_ = new GamestateManager();
     72    this->timeSinceLastUpdate_=0;
     73    this->threadPool_ = new ThreadPool();
    7274  }
    7375
    7476  Server::Server(int port){
    7577    this->setPort( port );
    76     timeSinceLastUpdate_=0;
    77     gamestates_ = new GamestateManager();
     78    this->timeSinceLastUpdate_=0;
     79    this->threadPool_ = new ThreadPool();
    7880  }
    7981
     
    8688    this->setPort( port );
    8789    this->setBindAddress( bindAddress );
    88     timeSinceLastUpdate_=0;
    89     gamestates_ = new GamestateManager();
     90    this->timeSinceLastUpdate_=0;
     91    this->threadPool_ = new ThreadPool();
    9092  }
    9193
     
    9496  */
    9597  Server::~Server(){
    96     if(gamestates_)
    97       delete gamestates_;
     98    delete this->threadPool_;
    9899  }
    99100
     
    138139  */
    139140  void Server::update(const Clock& time) {
     141    // receive incoming packets
    140142    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   
    142152    //this steers our network frequency
    143153    timeSinceLastUpdate_+=time.getDeltaTime();
     
    145155    {
    146156      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 );
    147160      updateGamestate();
    148       FunctionCallManager::sendCalls();
    149161    }
    150162    sendPackets(); // flush the enet queue
     
    175187  */
    176188  void Server::updateGamestate() {
    177 //     if( ClientInformation::getBegin()==NULL )
     189    if( ClientInformation::getBegin()==NULL )
    178190      //no client connected
    179 //       return;
    180     gamestates_->update();
     191      return;
     192    GamestateManager::update();
    181193    COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;
    182194    //std::cout << "updated gamestate, sending it" << std::endl;
     
    197209  */
    198210  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();
    233243    return true;
    234244  }
     
    324334  void Server::disconnectClient( ClientInformation *client ){
    325335    ServerConnection::disconnectClient( client );
    326     gamestates_->removeClient(client);
     336    GamestateManager::removeClient(client);
    327337// inform all the listeners
    328338    ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin();
Note: See TracChangeset for help on using the changeset viewer.