Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 413 for code/branches/FICN


Ignore:
Timestamp:
Dec 5, 2007, 5:59:25 PM (17 years ago)
Author:
scheusso
Message:

still errors

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

Legend:

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

    r405 r413  
    2222    // set server address to localhost
    2323    isConnected=false;
    24     pck_gen = PacketGenerator();
    25     gamestate = GameStateManager();
    2624  }
    2725
     
    3331  Client::Client(std::string address, int port) : client_connection(port, address){
    3432    isConnected=false;
    35     pck_gen = PacketGenerator();
    36     gamestate = GameStateManager();
    3733  }
    3834
     
    4440  Client::Client(const char *address, int port) : client_connection(port, address){
    4541    isConnected=false;
    46     pck_gen = PacketGenerator();
    47     gamestate = GameStateManager();
    4842  }
    4943
     
    147141 
    148142  void Client::processGamestate( GameStateCompressed *data){
    149     gamestate.loadSnapshot( *data );
     143    gamestate.pushGameState(*data);
    150144    return;
    151145  }
     
    153147  void Client::processClassid(classid *clid){
    154148    orxonox::Identifier *id;
    155     orxonox::ID(std::string(clid->message))->setNetworkID(clid->classid);
     149    id=orxonox::ID(std::string(clid->message));
     150    if(id!=NULL)
     151      id->setNetworkID(clid->classid);
     152    return;
    156153  }
    157154 
  • code/branches/FICN/src/network/Client.h

    r405 r413  
    1818#include "ClientConnection.h"
    1919#include "PacketManager.h"
    20 #include "GameStateManager.h"
     20#include "GameStateClient.h"
    2121#include "orxonox/core/IdentifierIncludes.h"
    2222
     
    5252  ClientConnection client_connection;
    5353  PacketGenerator pck_gen;
    54   GameStateManager gamestate;
     54  GameStateClient gamestate;
    5555  bool isConnected;
    5656 
  • code/branches/FICN/src/network/GameStateManager.cc

    r407 r413  
    1616GameStateManager::GameStateManager()
    1717{
     18  id=0;
    1819}
    1920
     
    2223}
    2324
     25void GameStateManager::update(){
     26  reference = getSnapshot(id++);
     27  return;
     28}
     29
     30GameStateCompressed GameStateManager::popGameState(int clientID){
     31  GameState *client = clientGameState[clientID]; 
     32  GameState *server = &reference;
     33  return encode(client, server);
     34}
     35
     36
     37
    2438/**
    2539 * This function goes through the whole list of synchronisables and
     
    2741 * @return struct of type gamestate containing the size of the whole gamestate and a pointer linking to the flat list
    2842 */
    29 GameStateCompressed GameStateManager::getSnapshot(int id)
     43GameState GameStateManager::getSnapshot(int id)
    3044{
    3145  //the size of the gamestate
     
    6377  }
    6478  retval.size=totalsize;
    65   return compress(retval);
     79  return retval;
    6680}
    6781
    68 /**
    69  * This function loads a Snapshort of the gamestate into the universe
    70  * @param state a GameState struct containing the size of the gamestate and a pointer linking to a flat list (returned by getSnapshot)
    71  */
    72 bool GameStateManager::loadSnapshot(GameStateCompressed compstate)
    73 {
    74   GameState state = decompress(compstate);
    75   unsigned char *data=state.data;
    76   // get the start of the Synchronisable list
    77   orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::start();
    78   syncData sync;
    79   // loop as long as we have some data ;)
    80   while(data < state.data+state.size){
    81     // prepare the syncData struct
    82     sync.length = *(int *)data;
    83     data+=sizeof(int);
    84     sync.objectID = *(int *)data;
    85     data+=sizeof(int);
    86     sync.classID = *(int *)data;
    87     data+=sizeof(int);
    88     sync.data = data;
    89     data+=sync.length;
    90    
    91     if(it->objectID!=sync.objectID){
    92       // bad luck ;)
    93       // delete the synchronisable (obviously seems to be deleted on the server)
    94       while(it != 0 && it->objectID!=sync.objectID){
    95         removeObject(it);
    96       }
    97       if(it==0){  // add the new object
    98         // =================== factory command to add object
    99         // can we be sure the object really was added?
    100         it=orxonox::ObjectList<Synchronisable>::end();
    101         it->objectID=sync.objectID;
    102         it->classID=sync.classID;
    103       }
    104     } else {
    105       // we have our object
    106       if(! it->updateData(sync))
    107         std::cout << "We couldn't update objectID: " \
    108           << sync.objectID << "; classID: " << sync.classID << std::endl;
    109     }
    110    
    111   }
    112  
    113   return true;
     82
     83
     84GameStateCompressed GameStateManager::encode(GameState *a, GameState *b){
     85  GameState r = diff(a,b);
     86  return compress_(r);
    11487}
    11588
    116 /**
    117  * This function removes a Synchronisable out of the universe
    118  * @param it iterator of the list pointing to the object
    119  * @return iterator pointing to the next object in the list
    120  */
    121 void GameStateManager::removeObject(orxonox::Iterator<Synchronisable> &it){
    122   orxonox::Iterator<Synchronisable> temp=it;
    123   ++it;
    124   delete  *temp;
    125 //   return it;
    126 }
    12789
    128 GameStateCompressed GameStateManager::encode(GameState a, GameState b){
    129   GameState r = diff(a,b);
    130   return compress(r);
    131 }
    132 
    133 GameState GameStateManager::decode(GameState a, GameStateCompressed x){
    134   GameState t = decompress(x);
    135   return diff(a, t);
    136 }
    137 
    138 GameState GameStateManager::diff(GameState a, GameState b){
    139   unsigned char *ap = a.data, *bp = b.data;
     90GameState GameStateManager::diff(GameState *a, GameState *b){
     91  unsigned char *ap = a->data, *bp = b->data;
    14092  int of=0; // pointers offset
    14193  int dest_length=0;
    142   if(a.size>=b.size)
    143     dest_length=a.size;
     94  if(a->size>=b->size)
     95    dest_length=a->size;
    14496  else
    145     dest_length=b.size;
     97    dest_length=b->size;
    14698  unsigned char *dp = (unsigned char *)malloc(dest_length*sizeof(unsigned char));
    147   while(of<a.size && of<b.size){
     99  while(of<a->size && of<b->size){
    148100    *(dp+of)=*(ap+of)^*(bp+of); // do the xor
    149101    ++of;
    150102  }
    151   if(a.size!=b.size){ // do we have to fill up ?
     103  if(a->size!=b->size){ // do we have to fill up ?
    152104    unsigned char n=0;
    153     if(a.size<b.size){
     105    if(a->size<b->size){
    154106      while(of<dest_length){
    155107        *(dp+of)=n^*(bp+of);
     
    164116  }
    165117  // should be finished now
    166   GameState r = {b.id, dest_length, dp};
     118  GameState r = {b->id, dest_length, dp};
    167119  return r;
    168120}
    169121
    170 GameStateCompressed GameStateManager::compress(GameState a) {
     122GameStateCompressed GameStateManager::compress_(GameState a) {
    171123  int size = a.size;
    172124  uLongf buffer = (uLongf)((a.size + 12)*1.01)+1;
     
    176128 
    177129  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;
     130  case Z_OK: std::cout << "successfully compressed" << std::endl; break;
     131  case Z_MEM_ERROR: std::cout << "not enough memory available" << std::endl; break;
     132  case Z_BUF_ERROR: std::cout << "not enough memory available in the buffer" << std::endl; break;
     133  case Z_DATA_ERROR: std::cout << "data corrupted" << std::endl; break;
    182134  }
    183135 
    184   GameStateCompressed compressedGamestate = new GameStateCompressed;
     136  GameStateCompressed compressedGamestate;
    185137  compressedGamestate.compsize = buffer;
    186138  compressedGamestate.normsize = size;
     
    191143}
    192144
    193 GameState GameStateManager::decompress(GameStateCompressed a){
    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 }
     145
    214146
    215147}
  • code/branches/FICN/src/network/GameStateManager.h

    r405 r413  
    1313#define NETWORK_GAMESTATEMANAGER_H
    1414
     15#include <vector>
     16
     17#include "zlib.h"
     18
    1519#include "Synchronisable.h"
    1620#include "orxonox/core/IdentifierIncludes.h"
    1721#include "orxonox/core/Iterator.h"
     22#include "PacketManager.h"
    1823
    1924namespace network {
     
    6267  GameStateManager();
    6368  ~GameStateManager();
    64   GameStateCompressed getSnapshot(int id);
    65   bool loadSnapshot(GameStateCompressed state);
    66   GameStateCompressed encode(GameState a, GameState b);
    67   GameState decode(GameState a, GameStateCompressed x);
     69  void update();
     70  GameStateCompressed popGameState(int clientID);
    6871private:
    69   void removeObject(orxonox::Iterator<Synchronisable> &it);
    70   GameState diff(GameState a, GameState b);
    71   GameStateCompressed compress(GameState a);
    72   GameState decompress(GameStateCompressed a);
     72  GameState getSnapshot(int id);
     73  GameStateCompressed encode(GameState *a, GameState *b);
     74  GameState diff(GameState *a, GameState *b);
     75  GameStateCompressed compress_(GameState a);
     76 
     77  std::vector<GameState *> clientGameState;
     78  GameState reference;
     79  int id;
    7380};
    7481
  • code/branches/FICN/src/network/PacketManager.h

    r405 r413  
    77
    88//enum netowk generaly used to set the type ID of a packet
    9 namespace network
    10 {
     9namespace network{
     10 
    1111enum packet_id {
    1212        ACK,
     
    3232        ENetPacket* mousem( double x, double y, int reliable = ENET_PACKET_FLAG_RELIABLE );
    3333        ENetPacket* keystrike( char press, int reliable = ENET_PACKET_FLAG_RELIABLE );
    34         ENetPacket* chatMessage( const char* message, int reliable = ENET_PACKET_FLAG_RELIABLE );
    35         ENetPacket* gstate( GameStateCompressed* states, int reliable = ENET_PACKET_FLAG_RELIABLE );
     34        ENetPacket* chatMessage( const char* message, int reliable = ENET_PACKET_FLAG_RELIABLE );
     35        ENetPacket* gstate( GameStateCompressed *states, int reliable = ENET_PACKET_FLAG_RELIABLE );
    3636        ENetPacket* clid( int classid, std::string classname, int reliable = ENET_PACKET_FLAG_RELIABLE );
    3737private:
     
    116116        void printKey( keyboard* data );
    117117        void printChat( chat* data );
    118         void printGamestate( GameStateCompressed* data );
     118        void printGamestate( GameStateCompressed *data );
    119119    void printClassid( classid *cid);
    120120};
  • code/branches/FICN/src/network/Server.h

    r380 r413  
    1818#include "ConnectionManager.h"
    1919#include "PacketManager.h"
     20#include "GameStateManager.h"
    2021#include "enet/enet.h"
    2122
Note: See TracChangeset for help on using the changeset viewer.