Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 407 for code


Ignore:
Timestamp:
Dec 5, 2007, 4:58:02 PM (17 years ago)
Author:
dumenim
Message:

compress/decompress funcions added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/FICN/src/network/GameStateManager.cc

    r405 r407  
    168168}
    169169
    170 GameStateCompressed GameStateManager::compress(GameState a){
    171   //to be implemented
    172   GameStateCompressed b;
    173   return b;
     170GameStateCompressed GameStateManager::compress(GameState a) {
     171  int size = a.size;
     172  uLongf buffer = (uLongf)((a.size + 12)*1.01)+1;
     173  unsigned char* dest = (unsigned char*)malloc( buffer );
     174  int retval;
     175  retval = compress( dest, &buffer, a.data, (uLong)size ); 
     176 
     177  switch ( retval ) {
     178  case Z_OK: cout << "successfully compressed" << endl; break;
     179  case Z_MEM_ERROR: cout << "not enough memory available" << endl; break;
     180  case Z_BUF_ERROR: cout << "not enough memory available in the buffer" << endl; break;
     181  case Z_DATA_ERROR: cout << "data corrupted" << endl; break;
     182  }
     183 
     184  GameStateCompressed compressedGamestate = new GameStateCompressed;
     185  compressedGamestate.compsize = buffer;
     186  compressedGamestate.normsize = size;
     187  compressedGamestate.id = GAMESTATE;
     188  compressedGamestate.data = dest;
     189 
     190  return compressedGamestate;
    174191}
    175192
    176193GameState GameStateManager::decompress(GameStateCompressed a){
    177   // to be implemented !!!!!!!!!!!!!!
    178   GameState b;
    179   return b;
    180 }
    181 
    182 }
    183 
    184 
     194  int normsize = a.normsize;
     195  int compsize = a.compsize;
     196  unsigned char* dest = (unsigned char*)malloc( normsize );
     197  int retval;
     198  retval = uncompress( dest, &normsize, a.data, compsize );
     199 
     200  switch ( retval ) {
     201  case Z_OK: cout << "successfully compressed" << endl; break;
     202  case Z_MEM_ERROR: cout << "not enough memory available" << endl; break;
     203  case Z_BUF_ERROR: cout << "not enough memory available in the buffer" << endl; break;
     204  case Z_DATA_ERROR: cout << "data corrupted" << endl; break;
     205  }
     206 
     207  GameState gamestate = new GameState;
     208  gamestate.id = a.id;
     209  gamestate.size = normsize;
     210  gamestate.data = dest;
     211 
     212  return gamestate;
     213}
     214
     215}
     216
     217
Note: See TracChangeset for help on using the changeset viewer.