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/GamestateManager.cc

    r3301 r3304  
    4242
    4343#include <cassert>
     44#include <queue>
     45// #include <boost/thread/mutex.hpp>
    4446
    4547#include "util/Debug.h"
     48#include "core/Executor.h"
     49#include "core/ThreadPool.h"
    4650#include "ClientInformation.h"
    4751#include "packet/Acknowledgement.h"
     
    5660  {
    5761    trafficControl_ = new TrafficControl();
     62//     threadMutex_ = new boost::mutex();
     63//     threadPool_ = new ThreadPool();
    5864  }
    5965
     
    6167  {
    6268    if( this->reference )
    63       delete this->reference;
    64     for( std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateQueue.begin(); it != gamestateQueue.end(); it++ )
     69        delete this->reference;std::map<unsigned int, packet::Gamestate*>::iterator it;
     70    for( it = gamestateQueue.begin(); it != gamestateQueue.end(); ++it )
    6571      delete (*it).second;
    66     delete trafficControl_;
     72    std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator it1;
     73    std::map<unsigned int, packet::Gamestate*>::iterator it2;
     74    for( it1 = gamestateMap_.begin(); it1 != gamestateMap_.end(); ++it1 )
     75    {
     76      for( it2 = it1->second.begin(); it2 != it1->second.end(); ++it2 )
     77        delete (*it2).second;
     78    }
     79    delete this->trafficControl_;
     80//     delete this->threadMutex_;
     81//     delete this->threadPool_;
    6782  }
    6883
     
    8499
    85100  bool GamestateManager::processGamestates(){
     101    if( this->gamestateQueue.empty() )
     102        return true;
    86103    std::map<unsigned int, packet::Gamestate*>::iterator it;
    87104    // now push only the most recent gamestates we received (ignore obsolete ones)
     
    109126    return true;
    110127  }
    111 
    112 
    113   packet::Gamestate *GamestateManager::popGameState(unsigned int clientID) {
     128 
     129  void GamestateManager::sendGamestates()
     130  {
     131    ClientInformation *temp = ClientInformation::getBegin();
     132    std::queue<packet::Gamestate*> clientGamestates;
     133    while(temp != NULL){
     134      if( !(temp->getSynched()) ){
     135        COUT(5) << "Server: not sending gamestate" << std::endl;
     136        temp=temp->next();
     137        if(!temp)
     138          break;
     139        continue;
     140      }
     141      COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl;
     142      COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
     143      int cid = temp->getID(); //get client id
     144     
     145      unsigned int gID = temp->getGamestateID();
     146      if(!reference)
     147        return;
     148     
     149      packet::Gamestate *client=0;
     150      if(gID != GAMESTATEID_INITIAL){
     151        assert(gamestateMap_.find(cid)!=gamestateMap_.end());
     152        std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateMap_[cid].find(gID);
     153        if(it!=gamestateMap_[cid].end())
     154        {
     155          client = it->second;
     156        }
     157      }
     158     
     159      clientGamestates.push(0);
     160      finishGamestate( cid, &clientGamestates.back(), client, reference );
     161      //FunctorMember<GamestateManager>* functor =
     162//       ExecutorMember<GamestateManager>* executor = createExecutor( createFunctor(&GamestateManager::finishGamestate) );
     163//       executor->setObject(this);
     164//       executor->setDefaultValues( cid, &clientGamestates.back(), client, reference );
     165//       (*static_cast<Executor*>(executor))();
     166//       this->threadPool_->passFunction( executor, true );
     167//       (*functor)( cid, &(clientGamestates.back()), client, reference );
     168     
     169      temp = temp->next();
     170    }
     171   
     172//     threadPool_->synchronise();
     173   
     174    while( !clientGamestates.empty() )
     175    {
     176      if(clientGamestates.front())
     177        clientGamestates.front()->send();
     178      clientGamestates.pop();
     179    }
     180  }
     181
     182
     183  void GamestateManager::finishGamestate( unsigned int clientID, packet::Gamestate** destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ) {
    114184    //why are we searching the same client's gamestate id as we searched in
    115185    //Server::sendGameState?
    116     packet::Gamestate *gs;
    117     unsigned int gID = ClientInformation::findClient(clientID)->getGamestateID();
    118     if(!reference)
    119       return 0;
    120     gs = reference->doSelection(clientID, 10000);
    121186    // save the (undiffed) gamestate in the clients gamestate map
    122     gamestateMap_[clientID][gs->getID()]=gs;
    123187    //chose wheather the next gamestate is the first or not
    124     packet::Gamestate *client=0;
    125     if(gID != GAMESTATEID_INITIAL){
    126       assert(gamestateMap_.find(clientID)!=gamestateMap_.end());
    127       std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateMap_[clientID].find(gID);
    128       if(it!=gamestateMap_[clientID].end())
    129       {
    130         client = it->second;
    131       }
    132     }
    133     if(client){
     188   
     189    packet::Gamestate *gs = gamestate->doSelection(clientID, 20000);
     190//     packet::Gamestate *gs = new packet::Gamestate(*gamestate);
     191//     packet::Gamestate *gs = new packet::Gamestate();
     192//     gs->collectData( id_, 0x1 );
     193//     this->threadMutex_->lock();
     194    gamestateMap_[clientID][gamestate->getID()]=gs;
     195//     this->threadMutex_->unlock();
     196   
     197    if(base)
     198    {
     199       
    134200//       COUT(3) << "diffing" << std::endl;
    135201//       packet::Gamestate* gs1  = gs;
    136       packet::Gamestate *diffed = gs->diff(client);
     202      packet::Gamestate *diffed = gs->diff(base);
    137203      //packet::Gamestate *gs2 = diffed->undiff(gs);
    138204//       assert(*gs == *gs2);
     
    143209    }
    144210    else{
    145 //       COUT(3) << "not diffing" << std::endl;
    146211      gs = new packet::Gamestate(*gs);
    147212    }
     213   
     214   
    148215    bool b = gs->compressData();
    149216    assert(b);
    150     COUT(4) << "sending gamestate with id " << gs->getID();
    151     if(gs->isDiffed())
    152     COUT(4) << " and baseid " << gs->getBaseID() << endl;
    153     else
    154     COUT(4) << endl;
    155     return gs;
     217//     COUT(4) << "sending gamestate with id " << gs->getID();
     218//     if(gamestate->isDiffed())
     219//     COUT(4) << " and baseid " << gs->getBaseID() << endl;
     220//     else
     221//     COUT(4) << endl;
     222    gs->setClientID(clientID);
     223    *destgamestate = gs;
    156224  }
    157225
     
    175243
    176244    assert(curid==GAMESTATEID_INITIAL || curid<gamestateID);
    177     COUT(4) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl;
     245    COUT(5) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl;
    178246    std::map<unsigned int, packet::Gamestate*>::iterator it;
    179247    for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end() && it->first<gamestateID; ){
Note: See TracChangeset for help on using the changeset viewer.