Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 10, 2008, 5:03:34 PM (16 years ago)
Author:
bknecht
Message:

merged back that script-branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/network/GameStateManager.cc

    r871 r1021  
    4343
    4444#include "core/CoreIncludes.h"
     45
    4546#include "ClientInformation.h"
    4647#include "Synchronisable.h"
     
    6566  }
    6667
    67   GameStateCompressed GameStateManager::popGameState(int clientID) {
     68  GameStateCompressed *GameStateManager::popGameState(int clientID) {
    6869    int gID = head_->findClient(clientID)->getGamestateID();
    69     std::cout << "popgamestate: sending gstate id: " << id << "diffed from: " << gID << std::endl;
     70    COUT(4) << "popgamestate: sending gstate id: " << id << "diffed from: " << gID << std::endl;
    7071    if(gID!=GAMESTATEID_INITIAL){
    7172      GameState *client = gameStateMap[gID];
     
    100101    GameState *retval=new GameState; //return value
    101102    retval->id=id++;
    102     std::cout << "producing gamestate with id: " << retval->id << std::endl;
     103    COUT(4) << "producing gamestate with id: " << retval->id << std::endl;
    103104    // reserve a little memory and increase it later on
    104     //COUT(2) << "mallocing" << std::endl;
     105    COUT(5) << "mallocing" << std::endl;
    105106    retval->data = (unsigned char*)malloc(memsize);
    106     //COUT(2) << "malloced" << std::endl;
     107    COUT(5) << "malloced" << std::endl;
    107108
    108109    // offset of memory functions
     
    113114      //get size of the synchronisable
    114115      tempsize=it->getSize();
    115       //std::cout << "size of temp gamestate: " << tempsize << std::endl;
     116//       COUT(5) << "size of temp gamestate: " << tempsize << std::endl;
    116117      //COUT(2) << "size of synchronisable: " << tempsize << std::endl;
    117118      // add place for data and 3 ints (length,classid,objectid)
     
    137138      offset+=tempsize+3*sizeof(int);
    138139    }
     140    COUT(5) << "Gamestate size: " << totalsize << std::endl;
    139141    retval->size=totalsize;
    140142    return retval;
    141143  }
    142144
    143   GameStateCompressed GameStateManager::encode(GameState *a, GameState *b) {
     145  GameStateCompressed *GameStateManager::encode(GameState *a, GameState *b) {
    144146    //GameState r = diff(a,b);
    145147    //r.diffed = true;
    146     GameState r = *b;
    147     r.diffed = false;
    148     return compress_(&r);
    149   }
    150 
    151   GameStateCompressed GameStateManager::encode(GameState *a) {
     148    GameState *r = b;
     149    r->diffed = false;
     150    return compress_(r);
     151  }
     152
     153  GameStateCompressed *GameStateManager::encode(GameState *a) {
    152154    a->diffed=false;
    153155    return compress_(a);
    154156  }
    155157
    156   GameState GameStateManager::diff(GameState *a, GameState *b) {
     158  GameState *GameStateManager::diff(GameState *a, GameState *b) {
    157159    unsigned char *ap = a->data, *bp = b->data;
    158160    int of=0; // pointers offset
     
    181183      }
    182184    }
    183     // should be finished now
    184     // FIXME: is it true or false now? (struct has changed, producing warnings)
    185     GameState r = {b->id, dest_length, true, dp};
     185   
     186    GameState *r = new GameState;
     187    r->id = b->id;
     188    r->size = dest_length;
     189    r->diffed = true;
     190    r->data = dp;
    186191    return r;
    187192  }
    188193
    189   GameStateCompressed GameStateManager::compress_(GameState *a) {
    190     //COUT(2) << "compressing gamestate" << std::endl;
     194  GameStateCompressed *GameStateManager::compress_(GameState *a) {
     195    COUT(5) << "compressing gamestate" << std::endl;
    191196    int size = a->size;
    192197    uLongf buffer = (uLongf)((a->size + 12)*1.01)+1;
     
    198203
    199204    switch ( retval ) {
    200       case Z_OK: std::cout << "successfully compressed" << std::endl; break;
    201       case Z_MEM_ERROR: std::cout << "not enough memory available" << std::endl; break;
    202       case Z_BUF_ERROR: std::cout << "not enough memory available in the buffer" << std::endl; break;
    203       case Z_DATA_ERROR: std::cout << "decompress: data corrupted" << std::endl; break;
    204     }
    205 
    206     GameStateCompressed compressedGamestate;
    207     compressedGamestate.compsize = buffer;
    208     //std::cout << "compressedGamestate.compsize = buffer; " << buffer << std::endl;
    209     compressedGamestate.normsize = size;
    210     //std::cout << "compressedGamestate.normsize = size; " << size << std::endl;
    211     compressedGamestate.id = a->id;
    212     compressedGamestate.data = dest;
    213     compressedGamestate.diffed = a->diffed;
     205      case Z_OK: COUT(5) << "successfully compressed" << std::endl; break;
     206      case Z_MEM_ERROR: COUT(1) << "not enough memory available in gamestate.compress" << std::endl;
     207      return NULL;
     208      case Z_BUF_ERROR: COUT(2) << "not enough memory available in the buffer in gamestate.compress" << std::endl;
     209      return NULL;
     210      case Z_DATA_ERROR: COUT(2) << "decompress: data corrupted in gamestate.compress" << std::endl;
     211      return NULL;
     212    }
     213
     214    GameStateCompressed *compressedGamestate = new GameStateCompressed;
     215    compressedGamestate->compsize = buffer;
     216//     std::cout << "compressedGamestate.compsize = buffer; " << buffer << std::endl;
     217    compressedGamestate->normsize = size;
     218//     std::cout << "compressedGamestate.normsize = size; " << size << std::endl;
     219    compressedGamestate->id = a->id;
     220    compressedGamestate->data = dest;
     221    compressedGamestate->diffed = a->diffed;
    214222
    215223    return compressedGamestate;
Note: See TracChangeset for help on using the changeset viewer.