Index: code/trunk/src/network/GameStateManager.cc
===================================================================
--- code/trunk/src/network/GameStateManager.cc	(revision 871)
+++ code/trunk/src/network/GameStateManager.cc	(revision 1021)
@@ -43,4 +43,5 @@
 
 #include "core/CoreIncludes.h"
+
 #include "ClientInformation.h"
 #include "Synchronisable.h"
@@ -65,7 +66,7 @@
   }
 
-  GameStateCompressed GameStateManager::popGameState(int clientID) {
+  GameStateCompressed *GameStateManager::popGameState(int clientID) {
     int gID = head_->findClient(clientID)->getGamestateID();
-    std::cout << "popgamestate: sending gstate id: " << id << "diffed from: " << gID << std::endl;
+    COUT(4) << "popgamestate: sending gstate id: " << id << "diffed from: " << gID << std::endl;
     if(gID!=GAMESTATEID_INITIAL){
       GameState *client = gameStateMap[gID];
@@ -100,9 +101,9 @@
     GameState *retval=new GameState; //return value
     retval->id=id++;
-    std::cout << "producing gamestate with id: " << retval->id << std::endl;
+    COUT(4) << "producing gamestate with id: " << retval->id << std::endl;
     // reserve a little memory and increase it later on
-    //COUT(2) << "mallocing" << std::endl;
+    COUT(5) << "mallocing" << std::endl;
     retval->data = (unsigned char*)malloc(memsize);
-    //COUT(2) << "malloced" << std::endl;
+    COUT(5) << "malloced" << std::endl;
 
     // offset of memory functions
@@ -113,5 +114,5 @@
       //get size of the synchronisable
       tempsize=it->getSize();
-      //std::cout << "size of temp gamestate: " << tempsize << std::endl;
+//       COUT(5) << "size of temp gamestate: " << tempsize << std::endl;
       //COUT(2) << "size of synchronisable: " << tempsize << std::endl;
       // add place for data and 3 ints (length,classid,objectid)
@@ -137,22 +138,23 @@
       offset+=tempsize+3*sizeof(int);
     }
+    COUT(5) << "Gamestate size: " << totalsize << std::endl;
     retval->size=totalsize;
     return retval;
   }
 
-  GameStateCompressed GameStateManager::encode(GameState *a, GameState *b) {
+  GameStateCompressed *GameStateManager::encode(GameState *a, GameState *b) {
     //GameState r = diff(a,b);
     //r.diffed = true;
-    GameState r = *b;
-    r.diffed = false;
-    return compress_(&r);
-  }
-
-  GameStateCompressed GameStateManager::encode(GameState *a) {
+    GameState *r = b;
+    r->diffed = false;
+    return compress_(r);
+  }
+
+  GameStateCompressed *GameStateManager::encode(GameState *a) {
     a->diffed=false;
     return compress_(a);
   }
 
-  GameState GameStateManager::diff(GameState *a, GameState *b) {
+  GameState *GameStateManager::diff(GameState *a, GameState *b) {
     unsigned char *ap = a->data, *bp = b->data;
     int of=0; // pointers offset
@@ -181,12 +183,15 @@
       }
     }
-    // should be finished now
-    // FIXME: is it true or false now? (struct has changed, producing warnings)
-    GameState r = {b->id, dest_length, true, dp};
+    
+    GameState *r = new GameState;
+    r->id = b->id;
+    r->size = dest_length;
+    r->diffed = true;
+    r->data = dp;
     return r;
   }
 
-  GameStateCompressed GameStateManager::compress_(GameState *a) {
-    //COUT(2) << "compressing gamestate" << std::endl;
+  GameStateCompressed *GameStateManager::compress_(GameState *a) {
+    COUT(5) << "compressing gamestate" << std::endl;
     int size = a->size;
     uLongf buffer = (uLongf)((a->size + 12)*1.01)+1;
@@ -198,18 +203,21 @@
 
     switch ( retval ) {
-      case Z_OK: std::cout << "successfully compressed" << std::endl; break;
-      case Z_MEM_ERROR: std::cout << "not enough memory available" << std::endl; break;
-      case Z_BUF_ERROR: std::cout << "not enough memory available in the buffer" << std::endl; break;
-      case Z_DATA_ERROR: std::cout << "decompress: data corrupted" << std::endl; break;
-    }
-
-    GameStateCompressed compressedGamestate;
-    compressedGamestate.compsize = buffer;
-    //std::cout << "compressedGamestate.compsize = buffer; " << buffer << std::endl;
-    compressedGamestate.normsize = size;
-    //std::cout << "compressedGamestate.normsize = size; " << size << std::endl;
-    compressedGamestate.id = a->id;
-    compressedGamestate.data = dest;
-    compressedGamestate.diffed = a->diffed;
+      case Z_OK: COUT(5) << "successfully compressed" << std::endl; break;
+      case Z_MEM_ERROR: COUT(1) << "not enough memory available in gamestate.compress" << std::endl; 
+      return NULL;
+      case Z_BUF_ERROR: COUT(2) << "not enough memory available in the buffer in gamestate.compress" << std::endl;
+      return NULL;
+      case Z_DATA_ERROR: COUT(2) << "decompress: data corrupted in gamestate.compress" << std::endl;
+      return NULL;
+    }
+
+    GameStateCompressed *compressedGamestate = new GameStateCompressed;
+    compressedGamestate->compsize = buffer;
+//     std::cout << "compressedGamestate.compsize = buffer; " << buffer << std::endl;
+    compressedGamestate->normsize = size;
+//     std::cout << "compressedGamestate.normsize = size; " << size << std::endl;
+    compressedGamestate->id = a->id;
+    compressedGamestate->data = dest;
+    compressedGamestate->diffed = a->diffed;
 
     return compressedGamestate;
