Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 19, 2010, 2:27:06 PM (14 years ago)
Author:
scheusso
Message:

some () structural changes
some functional changes (GamestateClient replaced through GamestateManager on client)
reliable packets get buffered until a recent gamestate arrived and got processed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network5/src/libraries/network/Client.cc

    r7772 r7777  
    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  }
     
    138135  {
    139136    packet::Chat *m = new packet::Chat(message, Host::getPlayerID());
    140     return m->send();
     137    return m->send(static_cast<Host*>(this));
    141138  }
    142139
     
    157154      {
    158155        COUT(4) << "popping partial gamestate: " << std::endl;
    159         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        }
    160164        //assert(gs); <--- there might be the case that no data has to be sent, so its commented out now
    161         if(gs){
    162           COUT(4) << "client tick: sending gs " << gs << std::endl;
    163           if( !gs->send() )
    164             COUT(2) << "Problem adding partial gamestate to queue" << std::endl;
    165         // gs gets automatically deleted by enet callback
    166         }
    167         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));
    168172      }
    169173    }
     
    171175
    172176    Connection::processQueue();
    173     if(gamestate->processGamestates())
     177    if(GamestateManager::processGamestates())
    174178    {
    175179      FunctionCallManager::processBufferedFunctionCalls();
     
    177181        isSynched_=true;
    178182    }
    179     gamestate->cleanup();
     183//     GamestateManager::cleanup();;
    180184//     Connection::sendPackets();
    181185
     
    198202    Game::getInstance().popState();
    199203  }
     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
    200218
    201219
Note: See TracChangeset for help on using the changeset viewer.