Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1741


Ignore:
Timestamp:
Sep 8, 2008, 11:09:28 AM (16 years ago)
Author:
scheusso
Message:

compressing doesnt work yet (maybe rather decompressing)

Location:
code/branches/network/src/network
Files:
6 edited

Legend:

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

    r1739 r1741  
    157157
    158158  packet::Gamestate *GamestateClient::processGamestate(packet::Gamestate *gs){
    159     if(gs->isCompressed())
    160       assert(gs->decompressData());
     159    if(gs->isCompressed()){
     160      bool b = gs->decompressData();
     161      assert(b);
     162    }
    161163    if(gs->isDiffed()){
    162164      packet::Gamestate *base = gamestateMap_[gs->getBaseID()];
  • code/branches/network/src/network/GamestateManager.cc

    r1739 r1741  
    129129    //why are we searching the same client's gamestate id as we searched in
    130130    //Server::sendGameState?
     131    packet::Gamestate *gs;
    131132    int gID = ClientInformation::findClient(clientID)->getGamestateID();
    132133    COUT(4) << "G.St.Man: popgamestate: sending gstate_id: " << id_ << " diffed from: " << gID << std::endl;
     
    134135    //chose wheather the next gamestate is the first or not
    135136    if(gID != GAMESTATEID_INITIAL){
    136       // TODO something with the gamestatemap is wrong
    137137      packet::Gamestate *client=NULL;
    138138      std::map<int, packet::Gamestate*>::iterator it = gamestateMap.find(gID);
    139139      if(it!=gamestateMap.end())
    140140        client = it->second;
    141       packet::Gamestate *gs;
    142141      if(client)
    143142        gs = reference->diff(client);
    144143      else
    145144        gs = new packet::Gamestate(*reference);
    146       gs->compressData();
    147       return gs;
    148145    } else {
    149146      COUT(4) << "we got a GAMESTATEID_INITIAL for clientID: " << clientID << std::endl;
    150 //       ackGameState(clientID, reference->id);
    151       return new packet::Gamestate(*reference);
    152       // return an undiffed gamestate and set appropriate flags
    153     }
     147      gs = new packet::Gamestate(*reference);
     148    }
     149#ifndef NDEBUG
     150    packet::Gamestate *ns = new packet::Gamestate(*gs);
     151    ns->compressData();
     152    ns->decompressData();
     153    assert(*gs==*ns);
     154    delete ns;
     155#endif
     156    assert(gs->compressData());
     157    return gs;
    154158  }
    155159 
  • code/branches/network/src/network/Synchronisable.cc

    r1735 r1741  
    9898    if(!id){
    9999      COUT(3) << "We could not identify a new object; classid: " << classID << " uint: " << (unsigned int)classID << " objectID: " << objectID << " size: " << size << std::endl;
     100      assert(0);
    100101      return false; // most probably the gamestate is corrupted
    101102    }
     
    224225    // end copy header
    225226   
    226    
    227227    COUT(5) << "Synchronisable getting data from objectID: " << objectID << " classID: " << classID << " length: " << size << std::endl;
    228228    // copy to location
  • code/branches/network/src/network/packet/Gamestate.cc

    r1739 r1741  
    4141 
    4242
    43 #define GAMESTATE_START(data) data + sizeof(GamestateHeader)
     43#define GAMESTATE_START(data) (data + sizeof(GamestateHeader))
    4444#define GAMESTATE_HEADER(data) ((GamestateHeader *)data)
    4545#define HEADER GAMESTATE_HEADER(data_)
     
    176176}
    177177
     178bool Gamestate::operator==(packet::Gamestate gs){
     179  unsigned char *d1 = data_+sizeof(GamestateHeader);
     180  unsigned char *d2 = gs.data_+sizeof(GamestateHeader);
     181  assert(!isCompressed());
     182  assert(!gs.isCompressed());
     183  while(d1<data_+HEADER->normsize)
     184  {
     185    if(*d1!=*d2)
     186      return false;
     187    d1++;
     188    d2++;
     189  }
     190  return true;
     191}
     192
    178193bool Gamestate::process()
    179194{
     
    184199{
    185200  assert(HEADER);
    186   uLongf buffer = (uLongf)((HEADER->normsize + 12)*1.01)+1;
     201  uLongf buffer = (uLongf)(((HEADER->normsize + 12)*1.01)+1);
    187202  if(buffer==0)
    188203    return false;
     
    190205  unsigned char *ndata = new unsigned char[buffer+sizeof(GamestateHeader)];
    191206  unsigned char *dest = GAMESTATE_START(ndata);
     207  //unsigned char *dest = new unsigned char[buffer];
     208  unsigned char *source = GAMESTATE_START(data_);
    192209  int retval;
    193   retval = compress( dest, &buffer, GAMESTATE_START(data_), (uLong)(HEADER->normsize) );
     210  retval = compress( dest, &buffer, source, (uLong)(HEADER->normsize) );
    194211  switch ( retval ) {
    195212    case Z_OK: COUT(5) << "G.St.Man: compress: successfully compressed" << std::endl; break;
    196     case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl;
    197     return false;
    198     case Z_BUF_ERROR: COUT(2) << "G.St.Man: compress: not enough memory available in the buffer in gamestate.compress" << std::endl;
    199     return false;
    200     case Z_DATA_ERROR: COUT(2) << "G.St.Man: compress: data corrupted in gamestate.compress" << std::endl;
    201     return false;
    202   }
     213    case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl; return false;
     214    case Z_BUF_ERROR: COUT(2) << "G.St.Man: compress: not enough memory available in the buffer in gamestate.compress" << std::endl; return false;
     215    case Z_DATA_ERROR: COUT(2) << "G.St.Man: compress: data corrupted in gamestate.compress" << std::endl; return false;
     216  }
     217#ifndef NDEBUG
     218  //decompress and compare the start and the decompressed data
     219  unsigned char *rdata = new unsigned char[HEADER->normsize+sizeof(GamestateHeader)];
     220  unsigned char *d2 = GAMESTATE_START(rdata);
     221  uLongf length2 = HEADER->normsize;
     222  uncompress(d2, &length2, dest, buffer);
     223  for(unsigned int i=0; i<HEADER->normsize; i++){
     224    assert(*(source+i)==*(d2+i));
     225  }
     226  delete[] rdata;
     227#endif
    203228
    204229  //copy and modify header
    205   HEADER->compsize = buffer;
    206   HEADER->compressed = true;
    207230  *GAMESTATE_HEADER(ndata) = *HEADER;
    208231  //delete old data
     
    210233  //save new data
    211234  data_ = ndata;
     235  HEADER->compsize = buffer;
     236  HEADER->compressed = true;
    212237  assert(HEADER->compressed);
    213238  COUT(3) << "gamestate compress normsize: " << HEADER->normsize << " compsize: " << HEADER->compsize << std::endl;
     
    217242{
    218243  assert(HEADER->compressed);
    219   //COUT(4) << "GameStateClient: uncompressing gamestate. id: " << a->id << ", baseid: " << a->base_id << ", normsize: " << a->normsize << ", compsize: " << a->compsize << std::endl;
    220   int normsize = HEADER->normsize;
    221   int compsize = HEADER->compsize;
    222   int bufsize;
    223   if(normsize < compsize)
    224     bufsize = compsize;
    225   else
    226     bufsize = normsize;
    227   if(bufsize==0)
    228     return NULL;
     244  COUT(3) << "GameStateClient: uncompressing gamestate. id: " << HEADER->id << ", baseid: " << HEADER->base_id << ", normsize: " << HEADER->normsize << ", compsize: " << HEADER->compsize << std::endl;
     245  unsigned int normsize = HEADER->normsize;
     246  unsigned int compsize = HEADER->compsize;
     247  unsigned int bufsize;
     248  assert(compsize<=normsize);
     249  bufsize = normsize;
     250  assert(bufsize!=0);
    229251  unsigned char *ndata = new unsigned char[bufsize + sizeof(GamestateHeader)];
    230252  unsigned char *dest = ndata + sizeof(GamestateHeader);
     253  unsigned char *source = data_ + sizeof(GamestateHeader);
    231254  int retval;
    232   uLongf length=normsize;
    233   retval = uncompress( dest, &length, data_+sizeof(GamestateHeader), (uLong)compsize );
     255  uLongf length=bufsize;
     256  retval = uncompress( dest, &length, source, (uLong)compsize );
    234257  switch ( retval ) {
    235258    case Z_OK: COUT(5) << "successfully decompressed" << std::endl; break;
     
    239262  }
    240263 
    241   HEADER->compressed = false;
    242264  //copy over the header
    243265  *GAMESTATE_HEADER(ndata) = *HEADER;
    244266  //delete old (compressed data)
    245267  delete[] data_;
    246   //set new pointers and create bytestream
     268  //set new pointers
    247269  data_ = ndata;
    248   //bs_ = new Bytestream(getGs(), GAMESTATE_HEADER->normsize);
    249  
     270  HEADER->compressed = false;
     271  assert(HEADER->normsize==normsize);
     272  assert(HEADER->compsize==compsize);
    250273  return true;
    251274}
     
    279302  GAMESTATE_HEADER(ndata)->diffed = true;
    280303  GAMESTATE_HEADER(ndata)->base_id = base->getID();
    281   Gamestate *g = new Gamestate(ndata, 0);
     304  Gamestate *g = new Gamestate(ndata, getClientID());
    282305  g->flags_=flags_;
    283306  g->packetDirection_ = packetDirection_;
    284   g->clientID_ = clientID_;
    285307  return g;
    286308}
     
    315337  *GAMESTATE_HEADER(ndata) = *HEADER;
    316338  GAMESTATE_HEADER(ndata)->diffed = false;
    317   Gamestate *g = new Gamestate(ndata, 0);
     339  Gamestate *g = new Gamestate(ndata, getClientID());
    318340  g->flags_=flags_;
    319341  g->packetDirection_ = packetDirection_;
    320   g->clientID_ = clientID_;
    321342  assert(!g->isDiffed());
    322343  assert(!g->isCompressed());
  • code/branches/network/src/network/packet/Gamestate.h

    r1739 r1741  
    7575    virtual bool process();
    7676
    77    
     77    bool operator ==(packet::Gamestate gs);
    7878  private:
    7979    unsigned int calcGamestateSize(int mode=0x0);
  • code/branches/network/src/network/packet/Packet.cc

    r1739 r1741  
    113113    packetMap_[enetPacket_] = this;
    114114  }
    115 #ifndef NDEBUG
     115#ifndef NDEBUG 
    116116  switch( *(ENUM::Type *)(data_ + _PACKETID) )
    117117  {
     
    123123      break;
    124124    default:
    125       assert(0); //TODO: repair this
     125      assert(0); //there was some error, if this is the case
    126126      break;
    127127  }
Note: See TracChangeset for help on using the changeset viewer.