Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 22, 2010, 7:24:24 PM (13 years ago)
Author:
dafrick
Message:

Merging presentation2 branch back to trunk.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/network/Client.cc

    r7495 r7801  
    6464  */
    6565  Client::Client():
    66       gamestate(0),
    6766      isSynched_(false),
    6867      gameStateFailure_(false),
     
    8584  {
    8685    Synchronisable::setClient(true);
    87     this->gamestate = new GamestateClient();
    8886    if( ClientConnection::establishConnection() )
    8987    {
    9088      Host::setActive(true);
     89      GamestateManager::addPeer(NETWORK_PEER_ID_SERVER);
    9190      return true;
    9291    }
     
    101100  bool Client::closeConnection()
    102101  {
    103     assert(this->gamestate);
    104     delete this->gamestate;
    105     this->gamestate = 0;
    106102    Host::setActive(false);
     103    GamestateManager::removePeer(NETWORK_PEER_ID_SERVER);
    107104    return ClientConnection::closeConnection();
    108105  }
     
    114111  }
    115112
    116   bool Client::queuePacket(ENetPacket *packet, int clientID)
    117   {
    118     bool b = ClientConnection::addPacket(packet);
    119     assert(b);
    120     return b;
     113  void Client::queuePacket(ENetPacket *packet, int clientID, uint8_t channelID)
     114  {
     115    ClientConnection::addPacket(packet, channelID);
    121116  }
    122117
     
    140135  {
    141136    packet::Chat *m = new packet::Chat(message, Host::getPlayerID());
    142     return m->send();
     137    return m->send(static_cast<Host*>(this));
    143138  }
    144139
     
    159154      {
    160155        COUT(4) << "popping partial gamestate: " << std::endl;
    161         packet::Gamestate *gs = gamestate->getGamestate();
     156//         packet::Gamestate *gs = GamestateClient::getGamestate();
     157        GamestateManager::update();
     158        std::vector<packet::Gamestate*> gamestates = GamestateManager::getGamestates();
     159        std::vector<packet::Gamestate*>::iterator it;
     160        for( it = gamestates.begin(); it != gamestates.end(); ++it )
     161        {
     162          (*it)->send( static_cast<Host*>(this) );
     163        }
    162164        //assert(gs); <--- there might be the case that no data has to be sent, so its commented out now
    163         if(gs){
    164           COUT(4) << "client tick: sending gs " << gs << std::endl;
    165           if( !gs->send() )
    166             COUT(3) << "Problem adding partial gamestate to queue" << std::endl;
    167         // gs gets automatically deleted by enet callback
    168         }
    169         FunctionCallManager::sendCalls();
     165//         if(gs){
     166//           COUT(4) << "client tick: sending gs " << gs << std::endl;
     167//           if( !gs->send() )
     168//             COUT(2) << "Problem adding partial gamestate to queue" << std::endl;
     169//         // gs gets automatically deleted by enet callback
     170//         }
     171        FunctionCallManager::sendCalls(static_cast<Host*>(this));
    170172      }
    171173    }
    172     sendPackets(); // flush the enet queue
     174//     sendPackets(); // flush the enet queue
    173175
    174176    Connection::processQueue();
    175     if(gamestate->processGamestates())
     177    if(GamestateManager::processGamestates())
    176178    {
    177179      FunctionCallManager::processBufferedFunctionCalls();
     
    179181        isSynched_=true;
    180182    }
    181     gamestate->cleanup();
    182     Connection::sendPackets();
     183//     GamestateManager::cleanup();;
     184//     Connection::sendPackets();
    183185
    184186    return;
     
    200202    Game::getInstance().popState();
    201203  }
     204 
     205  void Client::processPacket(packet::Packet* packet)
     206  {
     207    if( packet->isReliable() )
     208    {
     209      if( this->getLastProcessedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() )
     210        packet->process(static_cast<Host*>(this));
     211      else
     212        this->packetQueue_.push_back(packet);
     213    }
     214    else
     215      packet->process(static_cast<Host*>(this));
     216  }
     217
    202218
    203219
Note: See TracChangeset for help on using the changeset viewer.