Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2660


Ignore:
Timestamp:
Feb 14, 2009, 6:01:05 PM (16 years ago)
Author:
scheusso
Message:

fixed a problem with gamestate caching and diffing

Location:
code/branches/presentation/src/network
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation/src/network/GamestateClient.cc

    r2655 r2660  
    7575    if(tempGamestate_==NULL)
    7676      return false;
     77    bool isDiffed = tempGamestate_->isDiffed();
    7778    int id = GAMESTATEID_INITIAL;
    7879    packet::Gamestate *processed = processGamestate(tempGamestate_);
     
    8384   
    8485    if (!processed){
    85 //      sendAck(0);
     86      sendAck(0);
    8687      return false;
    8788    }
     
    8990    tempGamestate_=NULL;
    9091    gamestateMap_[processed->getID()]=processed;
    91     last_diff_ = processed->getID();
     92    if(isDiffed)
     93      last_diff_ = processed->getBaseID();
    9294    id = processed->getID();
    93 //     sendAck(id);
     95    sendAck(id);
    9496    return true;
    9597  }
     
    160162      packet::Gamestate *base = gamestateMap_[gs->getBaseID()];
    161163      if(!base){
    162 COUT(0) << "could not find base gamestate id: " << gs->getBaseID() << endl;
     164        COUT(3) << "could not find base gamestate id: " << gs->getBaseID() << endl;
    163165        delete gs;
    164166        return 0;
     
    173175      return gs;
    174176    else
    175 COUT(0) << "could not spread gamestate" << endl;
     177    {
     178      COUT(3) << "could not spread gamestate" << endl;
    176179      return NULL;
     180    }
    177181  }
    178182
  • code/branches/presentation/src/network/GamestateManager.cc

    r2655 r2660  
    113113    //why are we searching the same client's gamestate id as we searched in
    114114    //Server::sendGameState?
    115     packet::Gamestate *gs;
     115    packet::Gamestate *gs, *temp;
    116116    unsigned int gID = ClientInformation::findClient(clientID)->getGamestateID();
    117117    if(!reference)
    118118      return 0;
    119119    gs = reference->doSelection(clientID, 10000);
     120    temp = gs;
    120121//     gs = new packet::Gamestate(*reference);
    121122    // save the (undiffed) gamestate in the clients gamestate map
     
    142143    bool b = gs->compressData();
    143144    assert(b);
     145    COUT(4) << "sending gamestate with id " << gs->getID();
     146    if(gs->isDiffed())
     147    COUT(4) << " and baseid " << gs->getBaseID() << endl;
     148    else
     149    COUT(4) << endl;
    144150    return gs;
    145151  }
  • code/branches/presentation/src/network/packet/Acknowledgement.cc

    r2171 r2660  
    6464
    6565bool Acknowledgement::process(){
     66COUT(0) << "processing ACK with ID: " << getAckID() << endl;
    6667  bool b = GamestateHandler::ackGamestate(getAckID(), clientID_);
    6768  delete this;
  • code/branches/presentation/src/network/packet/Gamestate.cc

    r2655 r2660  
    7070  flags_ = flags_ | PACKET_FLAG_GAMESTATE;
    7171  data_=data;
     72  header_ = new GamestateHeader(data_);
     73}
     74
     75Gamestate::Gamestate(const Gamestate& g) :
     76    Packet( *(Packet*)&g )
     77{
     78  flags_ = flags_ | PACKET_FLAG_GAMESTATE;
    7279  header_ = new GamestateHeader(data_);
    7380}
     
    146153bool Gamestate::spreadData(uint8_t mode)
    147154{
     155  COUT(4) << "processing gamestate with id " << header_->getID() << endl;
    148156  assert(data_);
    149157  assert(!header_->isCompressed());
  • code/branches/presentation/src/network/packet/Gamestate.h

    r2655 r2660  
    4848class _NetworkExport GamestateHeader{
    4949  public:
    50     GamestateHeader(uint8_t *data){ data_ = data; *(uint32_t*)data_ = ENUM::Gamestate; }
     50    GamestateHeader(uint8_t *data){ assert(data); data_ = data; *(uint32_t*)data_ = ENUM::Gamestate; }
    5151    GamestateHeader(uint8_t *data, GamestateHeader* h)
    52       { data_=data; memcpy(data_, h->data_, getSize()); }
     52    { assert(data); data_=data; memcpy(data_, h->data_, getSize()); }
    5353    static inline uint32_t getSize()
    54       { return 21; }
     54    { return 21; }
    5555
    5656    inline int32_t getID() const
    57       { return *(int32_t*)(data_+4); }
     57    { assert(data_); return *(int32_t*)(data_+4); }
    5858    inline void setID(int32_t id)
    59       { *(int32_t*)(data_+4) = id; }
     59    { assert(data_); *(int32_t*)(data_+4) = id; }
    6060
    6161    inline int32_t getBaseID() const
    62       { return *(int32_t*)(data_+8); }
     62    { assert(data_); return *(int32_t*)(data_+8); }
    6363    inline void setBaseID(int32_t id)
    64       { *(int32_t*)(data_+8) = id; }
     64    { assert(data_); *(int32_t*)(data_+8) = id; }
    6565
    6666    inline uint32_t getDataSize() const
    67       { return *(uint32_t*)(data_+12); }
     67    { assert(data_); return *(uint32_t*)(data_+12); }
    6868    inline void setDataSize(uint32_t size)
    69       { *(uint32_t*)(data_+12) = size; }
     69    { assert(data_); *(uint32_t*)(data_+12) = size; }
    7070
    7171    inline uint32_t getCompSize() const
    72       { return *(uint32_t*)(data_+16); }
     72    { assert(data_); return *(uint32_t*)(data_+16); }
    7373    inline void setCompSize(uint32_t size)
    74       { *(uint32_t*)(data_+16) = size; }
     74    { assert(data_); *(uint32_t*)(data_+16) = size; }
    7575
    7676    inline bool isDiffed() const
    77       { return *(int8_t*)(data_+20) & 0x1; }
     77    { assert(data_); return *(int8_t*)(data_+20) & 0x1; }
    7878    inline void setDiffed(bool b)
    79       { *(int8_t*)(data_+20) = (b<<0) | (*(int8_t*)(data_+20) & 0x6 ); }
     79    { assert(data_); *(int8_t*)(data_+20) = (b<<0) | (*(int8_t*)(data_+20) & 0x6 ); }
    8080
    8181    inline bool isComplete() const
    82       { return *(int8_t*)(data_+20) & 0x2; }
     82    { assert(data_); return *(int8_t*)(data_+20) & 0x2; }
    8383    inline void setComplete(bool b)
    84       { *(int8_t*)(data_+20) = (b<<1) | (*(int8_t*)(data_+20) & 0x5 ); }
     84    { assert(data_); *(int8_t*)(data_+20) = (b<<1) | (*(int8_t*)(data_+20) & 0x5 ); }
    8585
    8686    inline bool isCompressed() const
    87       { return *(int8_t*)(data_+20) & 0x4; }
     87    { assert(data_); return *(int8_t*)(data_+20) & 0x4; }
    8888    inline void setCompressed(bool b)
    89       { *(int8_t*)(data_+20) = (b<<2) | (*(int8_t*)(data_+20) & 0x3 ); }
     89    { assert(data_); *(int8_t*)(data_+20) = (b<<2) | (*(int8_t*)(data_+20) & 0x3 ); }
    9090
    9191    inline void operator=(GamestateHeader& h)
    92       { memcpy( data_, h.data_, getSize()); }
     92    { assert(data_); assert(h.data_); memcpy( data_, h.data_, getSize()); }
    9393  private:
    9494    uint8_t *data_;
     
    107107    Gamestate(uint8_t *data, unsigned int clientID);
    108108    Gamestate(uint8_t *data);
     109    Gamestate(const Gamestate& g);
    109110
    110111    ~Gamestate();
Note: See TracChangeset for help on using the changeset viewer.