Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 620 for code/branches/FICN


Ignore:
Timestamp:
Dec 18, 2007, 5:51:47 PM (17 years ago)
Author:
scheusso
Message:

gamestatehandling, error correction

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

Legend:

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

    r601 r620  
    189189
    190190  void Client::processGamestate( GameStateCompressed *data){
    191     gamestate.pushGameState(*data);
     191    gamestate.pushGameState(data);
    192192    client_connection.addPacket(pck_gen.acknowledgement(data->id));
    193193    client_connection.sendPackets();
  • code/branches/FICN/src/network/ClientConnection.cc

    r605 r620  
    148148    while(!quit){
    149149      //std::cout << "connection loop" << std::endl;
    150       if(enet_host_service(client, &event, NETWORK_WAIT_TIMEOUT)<0){
     150      if(enet_host_service(client, &event, NETWORK_CLIENT_TIMEOUT)<0){
    151151        // we should never reach this point
    152152        quit=true;
     
    157157      case ENET_EVENT_TYPE_CONNECT:
    158158      case ENET_EVENT_TYPE_RECEIVE:
    159         std::cout << "got packet" << std::endl;
     159        //std::cout << "got packet" << std::endl;
    160160        processData(&event);
    161161        break;
     
    180180    ENetEvent event;
    181181    enet_peer_disconnect(server, 0);
    182     while(enet_host_service(client, &event, NETWORK_WAIT_TIMEOUT) > 0){
     182    while(enet_host_service(client, &event, NETWORK_CLIENT_TIMEOUT) > 0){
    183183      switch (event.type)
    184184      {
     
    204204      return false;
    205205    // handshake
    206     if(enet_host_service(client, &event, NETWORK_WAIT_TIMEOUT)>0 && event.type == ENET_EVENT_TYPE_CONNECT){
     206    if(enet_host_service(client, &event, NETWORK_CLIENT_TIMEOUT)>0 && event.type == ENET_EVENT_TYPE_CONNECT){
    207207      established=true;
    208208      return true;
     
    213213
    214214  bool ClientConnection::processData(ENetEvent *event){
    215     std::cout << "got packet, pushing to queue" << std::endl;
     215    //std::cout << "got packet, pushing to queue" << std::endl;
    216216    // just add packet to the buffer
    217217    // this can be extended with some preprocessing
  • code/branches/FICN/src/network/ClientConnection.h

    r605 r620  
    2828#define NETWORK_PORT 55556
    2929#define NETWORK_CLIENT_MAX_CONNECTIONS 5
    30 #define NETWORK_WAIT_TIMEOUT 5
     30#define NETWORK_CLIENT_TIMEOUT 5
    3131#define NETWORK_SEND_WAIT 5
    3232#define NETWORK_CLIENT_CHANNELS 2
  • code/branches/FICN/src/network/ClientInformation.cc

    r514 r620  
    190190ClientInformation *ClientInformation::findClient(int clientID, bool look_backwards){
    191191  ClientInformation *temp = this;
     192  if (temp->head)
     193    temp=temp->next();
    192194  while(temp!=0 && temp->getID()!=clientID){
    193     if (temp->head)
    194       continue;
    195195    temp = temp->next();
    196196  }
  • code/branches/FICN/src/network/ConnectionManager.cc

    r514 r620  
    200200          break;
    201201        case ENET_EVENT_TYPE_DISCONNECT:
     202          std::cout << "disconnecting client" << std::endl;
    202203          delete head_->findClient(&(event.peer->address));
    203204          temp = temp->next();
     
    227228  bool ConnectionManager::addClient(ENetEvent *event){
    228229    ClientInformation *temp = head_->insertBack(new ClientInformation);
    229     temp->setID(temp->prev()->getID()+1);
     230    if(temp->prev()->head)
     231      temp->setID(1);
     232    else
     233      temp->setID(temp->prev()->getID()+1);
    230234    temp->setPeer(event->peer);
    231235    std::cout << "added client id: " << temp->prev()->getID() << std::endl;
  • code/branches/FICN/src/network/GameStateClient.cc

    r567 r620  
    3939}
    4040
    41 bool GameStateClient::pushGameState(GameStateCompressed compstate){
    42   if(compstate.diffed)
    43     return loadSnapshot(decode(reference, compstate));
     41bool GameStateClient::pushGameState(GameStateCompressed *compstate){
     42  if(compstate->diffed)
     43    return loadSnapshot(decode(reference, *compstate));
    4444  else
    45     return loadSnapshot(decode(compstate));
     45    return loadSnapshot(decode(*compstate));
    4646}
    4747
     
    6565{
    6666  unsigned char *data=state.data;
     67  std::cout << "loadSnapshot: loading gs: " << state.id << std::endl;
    6768  // get the start of the Synchronisable list
    6869  orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::start();
     
    7172  while(data < state.data+state.size){
    7273    // prepare the syncData struct
    73     sync.length = *(int *)data;
     74    sync.length = (int)*data;
    7475    data+=sizeof(int);
    75     sync.objectID = *(int *)data;
     76    sync.objectID = (int)*data;
    7677    data+=sizeof(int);
    77     sync.classID = *(int *)data;
     78    sync.classID = (int)*data;
    7879    data+=sizeof(int);
    7980    sync.data = data;
     
    150151
    151152  switch ( retval ) {
    152     case Z_OK: std::cout << "successfully compressed" << std::endl; break;
     153    case Z_OK: std::cout << "successfully decompressed" << std::endl; break;
    153154    case Z_MEM_ERROR: std::cout << "not enough memory available" << std::endl; break;
    154155    case Z_BUF_ERROR: std::cout << "not enough memory available in the buffer" << std::endl; break;
  • code/branches/FICN/src/network/GameStateClient.h

    r505 r620  
    2828  GameStateClient();
    2929  ~GameStateClient();
    30   bool pushGameState(GameStateCompressed compstate);
     30  bool pushGameState(GameStateCompressed *compstate);
    3131private:
    3232  bool loadSnapshot(GameState state);
  • code/branches/FICN/src/network/GameStateManager.cc

    r599 r620  
    6161GameStateCompressed GameStateManager::popGameState(int clientID){
    6262  int gID = head_->findClient(clientID)->getGamestateID();
     63  std::cout << "popgamestate: sending gstate id: " << gID << std::endl;
    6364  if(gID!=GAMESTATEID_INITIAL){
    6465    GameState *client = gameStateMap[gID];
    6566    GameState *server = reference;
    6667    return encode(client, server);
    67   }
    68   GameState *server = reference;
    69   return encode(server);
    70   // return an undiffed gamestate and set appropriate flags
     68  } else {
     69    GameState *server = reference;
     70    head_->findClient(clientID)->setGamestateID(id);
     71    return encode(server);
     72    // return an undiffed gamestate and set appropriate flags
     73  }
    7174}
    7275
     
    101104  // go through all Synchronisables
    102105  for(it = orxonox::ObjectList<Synchronisable>::start(); it != 0; ++it){
     106    //std::cout << "gamestatemanager: in for loop" << std::endl;
    103107    //get size of the synchronisable
    104108    tempsize=it->getSize();
     
    127131
    128132GameStateCompressed GameStateManager::encode(GameState *a, GameState *b){
    129     GameState r = diff(a,b);
    130   r.diffed = true;
     133  //GameState r = diff(a,b);
     134  //r.diffed = true;
     135  GameState r = *b;
     136  r.diffed = false;
    131137  return compress_(&r);
    132138}
     
    170176
    171177GameStateCompressed GameStateManager::compress_(GameState *a) {
    172   COUT(2) << "compressing gamestate" << std::endl;
     178  //COUT(2) << "compressing gamestate" << std::endl;
    173179  int size = a->size;
    174180  uLongf buffer = (uLongf)((a->size + 12)*1.01)+1;
     
    181187  case Z_MEM_ERROR: std::cout << "not enough memory available" << std::endl; break;
    182188  case Z_BUF_ERROR: std::cout << "not enough memory available in the buffer" << std::endl; break;
    183   case Z_DATA_ERROR: std::cout << "data corrupted" << std::endl; break;
     189  case Z_DATA_ERROR: std::cout << "decompress: data corrupted" << std::endl; break;
    184190  }
    185191
  • code/branches/FICN/src/network/PacketDecoder.cc

    r531 r620  
    8888        *a = *(ack*)packet->data; //press pattern of ack on new data
    8989
    90         //clean memory
    91         enet_packet_destroy( packet );
    92 
    93         printAck( a ); //debug info
     90
     91  processAck( a, clientId ); //debug info
     92 
     93  //clean memory
     94  enet_packet_destroy( packet );
    9495}
    9596
     
    143144        unsigned char* data = (unsigned char*)packet->data;
    144145        //copy the GameStateCompressed id into the struct, which is located at second place data+sizeof( int )
    145         memcpy( (void*)&(currentState->id), (const void*)(data+sizeof( int )), sizeof( int ) );
     146  //memcpy( (void*)&(currentState->id), (const void*)(data+sizeof( int )), sizeof( int ) );
     147  currentState->id = (int)*(data+sizeof(int));
    146148        //copy the size of the GameStateCompressed compressed data into the new GameStateCompressed struct, located at 3th
    147149        //position of the data stream, data+2*sizeof( int )
    148         memcpy( (void*)&(currentState->compsize), (const void*)(data+2*sizeof( int )), sizeof( int) );
     150//      memcpy( (void*)&(currentState->compsize), (const void*)(data+2*sizeof( int )), sizeof( int) );
     151  currentState->compsize = (int)*(data+2*sizeof(int));
    149152        //size of uncompressed data
    150         memcpy( (void*)&(currentState->normsize), (const void*)(data+3*sizeof( int )), sizeof( int ) );
     153//      memcpy( (void*)&(currentState->normsize), (const void*)(data+3*sizeof( int )), sizeof( int ) );
     154  currentState->normsize = (int)*(data+3*sizeof(int));
    151155        //since the packetgenerator was changed, due to a new parameter, change this function too
    152         memcpy( (void*)&(currentState->diffed), (const void*)(data+4*sizeof(int)), sizeof(bool));
     156//      memcpy( (void*)&(currentState->diffed), (const void*)(data+4*sizeof(int)), sizeof(bool));
     157  currentState->diffed = (bool)*(data+4*sizeof(int));
    153158        //since data is not allocated, because it's just a pointer, allocate it with size of gamestatedatastream
    154159        currentState->data = (unsigned char*)(malloc( currentState->compsize ));
     160  if(currentState->data==NULL)
     161    std::cout << "memory leak" << std::endl;
    155162        //copy the GameStateCompressed data
     163  //std::cout << "packet size (enet): " << packet->dataLength << std::endl;
     164  //std::cout << "totallen: " << 4*sizeof(int)+sizeof(bool)+currentState->compsize << std::endl;
    156165        memcpy( (void*)(currentState->data), (const void*)(data+4*sizeof( int ) + sizeof(bool)), currentState->compsize );
    157166
     
    160169  //run processGameStateCompressed
    161170  //TODO: not yet implemented!
    162   //processGamestate(currentState);
     171  processGamestate(currentState);
    163172}
    164173
     
    181190}
    182191
     192void PacketDecoder::processGamestate( GameStateCompressed *state ){
     193 
     194}
     195
    183196void PacketDecoder::processClassid( classid *cid){
    184197  printClassid(cid);
     
    186199}
    187200
     201void PacketDecoder::processAck( ack *data, int clientID){
     202  printAck(data);
     203  return;
     204}
    188205
    189206
  • code/branches/FICN/src/network/PacketGenerator.cc

    r514 r620  
    9898ENetPacket* PacketGenerator::gstate( GameStateCompressed* states, int reliable )
    9999{
    100         int* gid = new int;
    101         *gid = GAMESTATE; //first assign the correct enet id
     100        int gid = GAMESTATE; //first assign the correct enet id
    102101        int totalLen = 4*sizeof( int ) + sizeof(bool) + states->compsize; //calculate the total size of the datastream memory
    103         unsigned char* data = (unsigned char*)malloc( totalLen ); //allocate the memory for datastream
    104         memcpy( (void*)(data), (const void*)gid, sizeof( int ) ); //this is the enet id
    105         memcpy( (void*)(data+sizeof(int)), (const void*)&(states->id), sizeof(int) ); //the GameStateCompressed id
    106         //this is the compressed size of the GameStateCompressed data, place at 3th position of the enet datastream
    107         memcpy( (void*)(data+2*sizeof(int)), (const void*)&(states->compsize), sizeof(int));
     102        unsigned char *data = (unsigned char*)malloc( totalLen ); //allocate the memory for datastream
     103  memcpy( (void*)(data), (const void*)&gid, sizeof( int ) ); //this is the enet id
     104  memcpy( (void*)(data+sizeof(int)), (const void*)&(states->id), sizeof(int) ); //the GameStateCompressed id
     105  memcpy( (void*)(data+2*sizeof(int)), (const void*)&(states->compsize), sizeof(int));
     106  memcpy( (void*)(data+3*sizeof(int)), (const void*)&(states->normsize), sizeof(int));
     107  memcpy( (void*)(data+4*sizeof(int)), (const void*)&(states->diffed), sizeof(bool));
     108  /*(int)*(data) = gid;
     109        (int)*(data+sizeof(int)) = states->id;
     110  //this is the compressed size of the GameStateCompressed data, place at 3th position of the enet datastream
     111  (int)*(data+2*sizeof(int)) = states->compsize;
    108112        //this is the uncompressed size of GameStateCompressed data
    109         memcpy( (void*)(data+3*sizeof(int)), (const void*)&(states->normsize), sizeof(int));
     113  (int)*(data+3*sizeof(int)) = states->normsize;
    110114        //since there is a new parameter inside GameStateCompressed, change this function to create packet
    111         memcpy( (void*)(data+4*sizeof(int)), (const void*)states->diffed, sizeof(bool));
     115  (bool)*(data+4*sizeof(int)) = states->diffed;*/
    112116        //place the GameStateCompressed data at the end of the enet datastream
    113117        memcpy( (void*)(data+4*sizeof( int ) + sizeof(bool)), (const void*)states->data, states->compsize );
    114118        //create an enet packet with the generated bytestream
    115119        ENetPacket *packet = enet_packet_create( data , totalLen, reliable );
    116 
     120  //delete data;
    117121        return packet;
    118122}
  • code/branches/FICN/src/network/PacketManager.h

    r531 r620  
    6666  //process data
    6767  //two functions are note yet implemented!
    68   //virtual void processGamestate(GameState *state);
     68  virtual void processGamestate(GameStateCompressed *state);
     69  virtual void processAck( ack *data, int clientID);
    6970  void processClassid( classid *cid);
    7071  //virtual void processAck( ack *data);
  • code/branches/FICN/src/network/Server.cc

    r607 r620  
    144144      std::cout << "doing gamestate" << std::endl;
    145145      int id = temp->getID();
     146      std::cout << "server, got ID: " << id << std::endl;
    146147      GameStateCompressed *gs = &(gamestates->popGameState(id));
    147148      std::cout << "adding gamestate" << std::endl;
     
    157158  }
    158159 
     160  void Server::processAck( ack *data, int clientID){
     161    clients->findClient(clientID)->setGamestateID(data->id);
     162  }
    159163 
    160164}
  • code/branches/FICN/src/network/Server.h

    r477 r620  
    1818#include "ConnectionManager.h"
    1919#include "PacketManager.h"
     20#include "PacketTypes.h"
    2021#include "GameStateManager.h"
    2122#include "ClientInformation.h"
     
    4647    private:
    4748    bool sendGameState();
     49    void processAck( ack *data, int clientID);
    4850    ConnectionManager *connection;
    4951    GameStateManager *gamestates;
Note: See TracChangeset for help on using the changeset viewer.