Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 18, 2009, 6:23:31 PM (15 years ago)
Author:
rgrieder
Message:

Merged netp6 branch back to the trunk.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/network/Server.cc

    r3214 r3304  
    4848#include "core/Clock.h"
    4949#include "core/ObjectList.h"
     50#include "core/Executor.h"
    5051#include "packet/Chat.h"
    5152#include "packet/ClassID.h"
     
    6869  */
    6970  Server::Server() {
    70     timeSinceLastUpdate_=0;
    71     gamestates_ = new GamestateManager();
     71    this->timeSinceLastUpdate_=0;
    7272  }
    7373
    7474  Server::Server(int port){
    7575    this->setPort( port );
    76     timeSinceLastUpdate_=0;
    77     gamestates_ = new GamestateManager();
     76    this->timeSinceLastUpdate_=0;
    7877  }
    7978
     
    8685    this->setPort( port );
    8786    this->setBindAddress( bindAddress );
    88     timeSinceLastUpdate_=0;
    89     gamestates_ = new GamestateManager();
     87    this->timeSinceLastUpdate_=0;
    9088  }
    9189
     
    9492  */
    9593  Server::~Server(){
    96     if(gamestates_)
    97       delete gamestates_;
    9894  }
    9995
     
    138134  */
    139135  void Server::update(const Clock& time) {
     136    // receive incoming packets
    140137    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() )
    145140    {
    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
    148145      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    }
    151156  }
    152157
     
    175180  */
    176181  void Server::updateGamestate() {
    177 //     if( ClientInformation::getBegin()==NULL )
     182    if( ClientInformation::getBegin()==NULL )
    178183      //no client connected
    179 //       return;
    180     gamestates_->update();
     184      return;
     185    GamestateManager::update();
    181186    COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;
    182187    //std::cout << "updated gamestate, sending it" << std::endl;
     
    197202  */
    198203  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();
    233236    return true;
    234237  }
     
    324327  void Server::disconnectClient( ClientInformation *client ){
    325328    ServerConnection::disconnectClient( client );
    326     gamestates_->removeClient(client);
     329    GamestateManager::removeClient(client);
    327330// inform all the listeners
    328331    ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin();
Note: See TracChangeset for help on using the changeset viewer.