Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

merged back that script-branch

Location:
code/trunk/src/network
Files:
16 edited

Legend:

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

    r790 r1021  
    184184    while(!(client_connection.queueEmpty())){
    185185      packet = client_connection.getPacket();
    186       //std::cout << "tick packet size " << packet->dataLength << std::endl;
     186      COUT(5) << "tick packet size " << packet->dataLength << std::endl;
    187187      elaborate(packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server)
    188188    }
     
    191191
    192192  void Client::processGamestate( GameStateCompressed *data){
     193    int id = data->id;
     194    COUT(5) << "received gamestate id: " << data->id << std::endl;
    193195    gamestate.pushGameState(data);
    194     std::cout << "received gamestate id: " << data->id << std::endl;
    195     client_connection.addPacket(pck_gen.acknowledgement(data->id));
     196    client_connection.addPacket(pck_gen.acknowledgement(id));
    196197    client_connection.sendPackets();
    197198    return;
     
    203204    if(id!=NULL)
    204205      id->setNetworkID(clid->clid);
     206    COUT(4) << "received and set network id: " << clid->clid << "; classname: " << clid->message << std::endl;
    205207    return;
    206208  }
    207209
    208210  void Client::processChat( chat *data){
    209     std::cout << "Server: " << data->message << std::endl;
     211    COUT(0) << "Server: " << data->message << std::endl;
    210212  }
    211213
  • code/trunk/src/network/Client.h

    r790 r1021  
    1717
    1818#include "NetworkPrereqs.h"
     19
     20#include "core/Tickable.h"
    1921#include "ClientConnection.h"
    2022#include "PacketManager.h"
    2123#include "GameStateClient.h"
    2224//#include "NetworkFrameListener.h"
     25
    2326
    2427
     
    3235  *
    3336  */
    34   class _NetworkExport Client : PacketDecoder{
     37  class _NetworkExport Client : PacketDecoder, public orxonox::Tickable{
    3538  public:
    3639    Client();
  • code/trunk/src/network/ClientConnection.cc

    r790 r1021  
    4343
    4444#include "util/Sleep.h"
     45#include "orxonox/core/Debug.h"
    4546#include "ClientConnection.h"
    4647
     
    159160      case ENET_EVENT_TYPE_CONNECT:
    160161      case ENET_EVENT_TYPE_RECEIVE:
    161         //std::cout << "got packet" << std::endl;
     162        COUT(5) << "receiver-Thread: got new packet" << std::endl;
    162163        processData(&event);
    163164        break;
     
    215216
    216217  bool ClientConnection::processData(ENetEvent *event) {
    217     //std::cout << "got packet, pushing to queue" << std::endl;
     218    COUT(5) << "got packet, pushing to queue" << std::endl;
    218219    // just add packet to the buffer
    219220    // this can be extended with some preprocessing
  • code/trunk/src/network/ConnectionManager.cc

    r790 r1021  
    257257
    258258  void ConnectionManager::syncClassid(int clientID) {
    259     int i=0;
     259    unsigned int network_id=0;
    260260    std::string classname;
    261     bool abort=false;
    262261    orxonox::Identifier *id;
    263     while(!abort){
    264       id = ID(i);
    265       std::cout << "syncid: " << i << ", ID(id): " << id << std::endl;
    266       if(id == NULL){
    267         if(i!=0)
    268           abort=true;
    269         else{
    270           ++i;
    271           continue;
    272         }
    273       }
    274       else{
    275         classname = id->getName();
    276         addPacket(packet_gen.clid( i, classname ),clientID);
    277       }
    278       ++i;
     262    std::map<std::string, orxonox::Identifier*>::const_iterator it = orxonox::Factory::getFactoryBegin();
     263    while(it != orxonox::Factory::getFactoryEnd()){
     264      id = (*it).second;
     265      if(id == NULL)
     266        continue;
     267      classname = id->getName();
     268      network_id = id->getNetworkID();
     269      COUT(4) << "network_id: " << network_id << ", classname: " << classname << std::endl;
     270     
     271      addPacket(packet_gen.clid( (int)network_id, classname ), clientID);
     272     
     273      ++it;
    279274    }
    280275    sendPackets();
    281276  }
    282277
     278 
     279 
     280  void ConnectionManager::addClientsObjectID( int clientID, int objectID ) {
     281    COUT(4) << "ship of client: " << clientID << ": " << objectID << " mapped" << std::endl;
     282    clientsShip.insert( std::make_pair( clientID, objectID ) );
     283  }
     284
     285  int ConnectionManager::getClientsShipID( int clientID ) {
     286    return clientsShip[clientID];
     287  }
     288
     289  int ConnectionManager::getObjectsClientID( int objectID ) {
     290    std::map<int, int>::iterator iter = clientsShip.begin();
     291    while( iter != clientsShip.end() ) {
     292      if( iter->second == objectID ) return iter->first;
     293    }
     294    return -99;
     295  }
     296
     297  void ConnectionManager::deleteClientIDReg( int clientID ) {
     298    clientsShip.erase( clientID );
     299  }
     300
     301  void ConnectionManager::deleteObjectIDReg( int objectID ) {
     302    std::map<int, int>::iterator iter = clientsShip.begin();
     303    while( iter != clientsShip.end() ) {
     304      if( iter->second == objectID ) break;
     305    }
     306    clientsShip.erase( iter->first );
     307  }
     308 
    283309}
  • code/trunk/src/network/ConnectionManager.h

    r790 r1021  
    1414
    1515#include <string>
     16#include <map>
    1617// enet library for networking support
    1718#include <enet/enet.h>
     
    7374    bool quit; // quit-variable (communication with threads)
    7475    ClientInformation *head_;
     76   
     77    //functions to map what object every clients uses
     78    std::map<int, int> clientsShip;
     79    void addClientsObjectID( int clientID, int objectID );
     80    int getClientsShipID( int clientID );
     81    int getObjectsClientID( int objectID );
     82    void deleteClientIDReg( int clientID );
     83    void deleteObjectIDReg( int objectID );
    7584  };
    7685
  • code/trunk/src/network/GameStateClient.cc

    r871 r1021  
    4040
    4141  bool GameStateClient::pushGameState(GameStateCompressed *compstate) {
     42    GameState *gs;
    4243    if(compstate->diffed)
    43       return loadSnapshot(decode(reference, *compstate));
     44      gs = decode(reference, compstate);
    4445    else
    45       return loadSnapshot(decode(*compstate));
     46      gs = decode(compstate);
     47    if(gs)
     48      return loadSnapshot(gs);
     49    COUT(4) << "could not use gamestate sent by server" << std::endl;
     50    return false;
    4651  }
    4752
     
    6166  * @param state a GameState struct containing the size of the gamestate and a pointer linking to a flat list (returned by getSnapshot)
    6267  */
    63   bool GameStateClient::loadSnapshot(GameState state) {
    64     unsigned char *data=state.data;
    65     std::cout << "loadSnapshot: loading gs: " << state.id << std::endl;
     68  bool GameStateClient::loadSnapshot(GameState *state) {
     69    unsigned char *data=state->data;
     70    COUT(4) << "loadSnapshot: loading gs: " << state->id << std::endl;
    6671    // get the start of the Synchronisable list
    6772    orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::start();
    6873    syncData sync;
    6974    // loop as long as we have some data ;)
    70     while(data < state.data+state.size){
     75    while(data < state->data+state->size){
    7176      // prepare the syncData struct
    7277      sync.length = (int)*data;
     
    8287        // bad luck ;)
    8388        // delete the synchronisable (obviously seems to be deleted on the server)
    84         while(it && it->objectID!=sync.objectID){
     89        while(it && it->objectID!=sync.objectID)
    8590          removeObject(it);
    86         }
    87         if(it==0){
    88           std::cout << "classid: " << sync.classID << ", name: " << ID(sync.classID)->getName() << std::endl;
    89           Synchronisable *no = (Synchronisable*)(ID(sync.classID)->fabricate());
     91       
     92       
     93        if(!it){
     94          COUT(5) << "classid: " << sync.classID << ", name: " << ID((unsigned int) sync.classID)->getName() << std::endl;
     95          Synchronisable *no = (Synchronisable*)(ID((unsigned int) sync.classID)->fabricate());
    9096          no->objectID=sync.objectID;
    9197          no->classID=sync.classID;
     
    9399          // update data and create object/entity...
    94100          if( !no->updateData(sync) && !no->create() )
    95             COUT(0) << "We couldn't create/update the object: " << sync.objectID << std::endl;
     101            COUT(1) << "We couldn't create/update the object: " << sync.objectID << std::endl;
    96102          ++it;
    97103        }
     
    99105        // we have our object
    100106        if(! it->updateData(sync))
    101           std::cout << "We couldn't update objectID: " \
     107          COUT(1) << "We couldn't update objectID: " \
    102108          << sync.objectID << "; classID: " << sync.classID << std::endl;
    103109      }
     
    108114  }
    109115
    110   GameState GameStateClient::diff(GameState a, GameState b) {
    111     unsigned char *ap = a.data, *bp = b.data;
     116  GameState *GameStateClient::undiff(GameState *a, GameState *b) {
     117    unsigned char *ap = a->data, *bp = b->data;
    112118    int of=0; // pointers offset
    113119    int dest_length=0;
    114     if(a.size>=b.size)
    115       dest_length=a.size;
     120    if(a->size>=b->size)
     121      dest_length=a->size;
    116122    else
    117       dest_length=b.size;
     123      dest_length=b->size;
    118124    unsigned char *dp = (unsigned char *)malloc(dest_length*sizeof(unsigned char));
    119     while(of<a.size && of<b.size){
     125    while(of<a->size && of<b->size){
    120126      *(dp+of)=*(ap+of)^*(bp+of); // do the xor
    121127      ++of;
    122128    }
    123     if(a.size!=b.size){ // do we have to fill up ?
     129    if(a->size!=b->size){ // do we have to fill up ?
    124130      unsigned char n=0;
    125       if(a.size<b.size){
     131      if(a->size<b->size){
    126132        while(of<dest_length){
    127133          *(dp+of)=n^*(bp+of);
     
    137143    // should be finished now
    138144    // FIXME: is it true or false now? (struct has changed, producing warnings)
    139     GameState r = {b.id, dest_length, true, dp};
     145    GameState *r = new GameState;
     146    r->id = b->id;
     147    r->size = dest_length;
     148    r->diffed = false;
     149    r->data = dp;
    140150    return r;
    141151  }
    142152
    143   GameState GameStateClient::decompress(GameStateCompressed a) {
    144     int normsize = a.normsize;
    145     int compsize = a.compsize;
     153  GameState *GameStateClient::decompress(GameStateCompressed *a) {
     154    int normsize = a->normsize;
     155    int compsize = a->compsize;
    146156    int bufsize;
    147157    if(normsize < compsize)
     
    154164    //std::cout << "gamestateclient" << std::endl;
    155165    //std::cout << "normsize " << a.normsize << " compsize " << a.compsize << " " << bufsize << std::endl;
    156     retval = uncompress( dest, &length, a.data, (uLong)compsize );
     166    retval = uncompress( dest, &length, a->data, (uLong)compsize );
    157167    //std::cout << "length " << length << std::endl;
    158168    switch ( retval ) {
    159       case Z_OK: std::cout << "successfully decompressed" << std::endl; break;
    160       case Z_MEM_ERROR: std::cout << "not enough memory available" << std::endl; break;
    161       case Z_BUF_ERROR: std::cout << "not enough memory available in the buffer" << std::endl; break;
    162       case Z_DATA_ERROR: std::cout << "data corrupted" << std::endl; break;
     169      case Z_OK: COUT(4) << "successfully decompressed" << std::endl; break;
     170      case Z_MEM_ERROR: COUT(1) << "not enough memory available" << std::endl; return NULL;
     171      case Z_BUF_ERROR: COUT(2) << "not enough memory available in the buffer" << std::endl; return NULL;
     172      case Z_DATA_ERROR: COUT(2) << "data corrupted" << std::endl; return NULL;
    163173    }
    164174
    165     GameState gamestate;
    166     gamestate.id = a.id;
    167     gamestate.size = normsize;
    168     gamestate.data = dest;
    169     gamestate.diffed = a.diffed;
     175    GameState *gamestate = new GameState;
     176    gamestate->id = a->id;
     177    gamestate->size = normsize;
     178    gamestate->data = dest;
     179    gamestate->diffed = a->diffed;
     180   
     181    delete a->data; //delete compressed data
     182    delete a; //we do not need the old (struct) gamestate anymore
    170183
    171184    return gamestate;
    172185  }
    173186
    174   GameState GameStateClient::decode(GameState a, GameStateCompressed x) {
    175     GameState t = decompress(x);
    176     return diff(a, t);
     187  GameState *GameStateClient::decode(GameState *a, GameStateCompressed *x) {
     188    GameState *t = decompress(x);
     189    return undiff(a, t);
    177190  }
    178191
    179   GameState GameStateClient::decode(GameStateCompressed x) {
    180     GameState t = decompress(x);
     192  GameState *GameStateClient::decode(GameStateCompressed *x) {
     193    GameState *t = decompress(x);
    181194    return t;
    182195  }
  • code/trunk/src/network/GameStateClient.h

    r790 r1021  
    2525    bool pushGameState(GameStateCompressed *compstate);
    2626  private:
    27     bool loadSnapshot(GameState state);
    28     GameState diff(GameState a, GameState b);
    29     GameState decompress(GameStateCompressed a);
    30     GameState decode(GameState a, GameStateCompressed x);
    31     GameState decode(GameStateCompressed x);
     27    bool loadSnapshot(GameState *state);
     28    GameState *undiff(GameState *a, GameState *b);
     29    GameState *decompress(GameStateCompressed *a);
     30    GameState *decode(GameState *a, GameStateCompressed *x);
     31    GameState *decode(GameStateCompressed *x);
    3232    void removeObject(orxonox::Iterator<Synchronisable> &it);
    3333
    34     GameState reference;
     34    GameState *reference;
    3535  };
    3636
  • 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;
  • code/trunk/src/network/GameStateManager.h

    r790 r1021  
    4343    ~GameStateManager();
    4444    void update();
    45     GameStateCompressed popGameState(int clientID);
     45    GameStateCompressed *popGameState(int clientID);
    4646    void ackGameState(int clientID, int gamestateID);
    4747    int id;
    4848  private:
    4949    GameState *getSnapshot(int id);
    50     GameStateCompressed encode(GameState *a, GameState *b);
    51     GameStateCompressed encode(GameState *a);
    52     GameState diff(GameState *a, GameState *b);
    53     GameStateCompressed compress_(GameState *a);
     50    GameStateCompressed *encode(GameState *a, GameState *b);
     51    GameStateCompressed *encode(GameState *a);
     52    GameState *diff(GameState *a, GameState *b);
     53    GameStateCompressed *compress_(GameState *a);
    5454    bool deleteUnusedGameState(int gamestateID);
    5555
  • code/trunk/src/network/PacketDecoder.cc

    r790 r1021  
    3838#include "PacketTypes.h"
    3939#include "PacketManager.h"
     40#include "orxonox/core/Debug.h"
    4041
    4142namespace network
    4243{
    43   using namespace std;
    4444
    4545  PacketDecoder::PacketDecoder(){}
     
    5252  {
    5353    int client = clientId;
    54     cout << "clientId: " << client << endl; //control cout, not important, just debugging info
     54    COUT(5) << "clientId: " << client << std::endl; //control cout, not important, just debugging info
    5555    int id = (int)*packet->data; //the first 4 bytes are always the enet packet id
    56     std::cout << "packet id: " << id << std::endl;
    57     std::cout << "packet size inside packetdecoder: " << packet->dataLength << std::endl;
     56    COUT(5) << "packet id: " << id << std::endl;
     57//     COUT(5) << "packet size inside packetdecoder: " << packet->dataLength << std::endl;
    5858    switch( id ) {
    5959  case ACK:
     
    9393
    9494
    95     std::cout << "got ack id: " << a->id << std::endl;
     95    COUT(5) << "got ack id: " << a->id << std::endl;
    9696    processAck( a, clientId ); //debug info
    9797
     
    144144  void PacketDecoder::gstate( ENetPacket* packet )
    145145  {
    146     GameStateCompressed* currentState = new GameStateCompressed;
     146    GameStateCompressed* currentState = NULL;
     147    currentState = new GameStateCompressed;
     148    if(currentState == NULL){
     149      COUT(3) << "could not generate new GameStateCompressed" << std::endl;
     150      return;
     151    }
    147152    //since it's not alowed to use void* for pointer arithmetic
    148     unsigned char* data = (unsigned char*)packet->data;
     153    unsigned char* data = (unsigned char *)(packet->data);
    149154    //copy the GameStateCompressed id into the struct, which is located at second place data+sizeof( int )
    150155    //memcpy( (void*)&(currentState->id), (const void*)(data+sizeof( int )), sizeof( int ) );
    151     currentState->id = (int)*(data+sizeof(int));
    152     std::cout << "id: " << currentState->id << std::endl;
     156    //currentState->id = *((int *)packet->data+sizeof(int));
     157    memcpy( (void*)&(currentState->id), (const void*)(packet->data+1*sizeof( int )), sizeof( int) );
     158    COUT(5) << "decoder: received gs id: " << currentState->id << std::endl;
     159//     std::cout << "id: " << currentState->id << std::endl;
    153160    //copy the size of the GameStateCompressed compressed data into the new GameStateCompressed struct, located at 3th
    154161    //position of the data stream, data+2*sizeof( int )
    155     memcpy( (void*)&(currentState->compsize), (const void*)(data+2*sizeof( int )), sizeof( int) );
     162    memcpy( (void*)&(currentState->compsize), (const void*)(packet->data+2*sizeof( int )), sizeof( int) );
    156163    //currentState->compsize = (int)*(data+2*sizeof(int));
    157     std::cout << "compsize: " << currentState->compsize << std::endl;
     164//     std::cout << "compsize: " << currentState->compsize << std::endl;
    158165    //size of uncompressed data
    159     memcpy( (void*)&(currentState->normsize), (const void*)(data+3*sizeof( int )), sizeof( int ) );
     166    memcpy( (void*)&(currentState->normsize), (const void*)(packet->data+3*sizeof( int )), sizeof( int ) );
    160167    //currentState->normsize = (int)*(data+3*sizeof(int));
    161     std::cout << "normsize. " << currentState->normsize << std::endl;
     168//     std::cout << "normsize. " << currentState->normsize << std::endl;
    162169    //since the packetgenerator was changed, due to a new parameter, change this function too
    163     memcpy( (void*)&(currentState->diffed), (const void*)(data+4*sizeof(int)), sizeof(bool));
     170    memcpy( (void*)&(currentState->diffed), (const void*)(packet->data+4*sizeof(int)), sizeof(bool));
    164171    //currentState->diffed = (bool)*(data+4*sizeof(int));
    165     std::cout << "diffed: " << currentState->diffed << std::endl;
     172//     std::cout << "diffed: " << currentState->diffed << std::endl;
    166173    //since data is not allocated, because it's just a pointer, allocate it with size of gamestatedatastream
     174    if(currentState->compsize==0)
     175      COUT(2) << "compsize is 0" << std::endl;
    167176    currentState->data = (unsigned char*)(malloc( currentState->compsize ));
    168177    if(currentState->data==NULL)
    169       std::cout << "memory leak" << std::endl;
     178      COUT(2) << "Gamestatepacket-decoder: memory leak" << std::endl;
    170179    //copy the GameStateCompressed data
    171180    //std::cout << "packet size (enet): " << packet->dataLength << std::endl;
    172181    //std::cout << "totallen: " << 4*sizeof(int)+sizeof(bool)+currentState->compsize << std::endl;
    173     memcpy( (void*)(currentState->data), (const void*)(data+4*sizeof( int ) + sizeof(bool)), currentState->compsize );
    174 
    175     //clean memory
    176     enet_packet_destroy( packet );
    177     //run processGameStateCompressed
    178     //TODO: not yet implemented!
     182    memcpy( (void*)(currentState->data), (const void*)(packet->data+4*sizeof( int ) + sizeof(bool)), currentState->compsize );
     183
     184    //clean memory
     185    enet_packet_destroy( packet );
    179186    processGamestate(currentState);
    180187  }
     
    189196    void *data  = (void *)cid->message;
    190197    memcpy(data, (const void*)(packet->data+3*sizeof(int)), cid->length);
    191     std::cout << "classid: " << cid->clid << ", name: " << cid->message << std::endl;
     198    COUT(4) << "classid: " << cid->clid << ", name: " << cid->message << std::endl;
    192199    enet_packet_destroy( packet );
    193200    processClassid(cid);
     
    223230  void PacketDecoder::printAck( ack* data )
    224231  {
    225     cout << "data id: " << data->id << endl;
    226     cout << "data:    " << data->a << endl;
     232    COUT(5) << "data id: " << data->id << std::endl;
     233    COUT(5) << "data:    " << data->a << std::endl;
    227234  }
    228235
    229236  void PacketDecoder::printMouse( mouse* data )
    230237  {
    231     cout << "data id: " << data->id << endl;
    232     cout << "data:    " << data->x << " " << data->y << endl;
     238    COUT(5) << "data id: " << data->id << std::endl;
     239    COUT(5) << "data:    " << data->x << " " << data->y << std::endl;
    233240  }
    234241
    235242  void PacketDecoder::printKey( keyboard* data )
    236243  {
    237     cout << "data id: " << data->id << endl;
    238     cout << "data:    " << (char)data->press << endl;
     244    COUT(5) << "data id: " << data->id << std::endl;
     245    COUT(5) << "data:    " << (char)data->press << std::endl;
    239246  }
    240247
     
    242249  {
    243250    if(clientId!=CLIENTID_CLIENT)
    244       cout << "client: " << clientId << endl;
    245     cout << "data id: " << data->id << endl;
    246     cout << "data:    " << data->message << endl;
     251      COUT(5) << "client: " << clientId << std::endl;
     252    COUT(5) << "data id: " << data->id << std::endl;
     253    COUT(5) << "data:    " << data->message << std::endl;
    247254  }
    248255
    249256  void PacketDecoder::printGamestate( GameStateCompressed* data )
    250257  {
    251     cout << "id of GameStateCompressed:   " << data->id << endl;
    252     cout << "size of GameStateCompressed: " << data->compsize << endl;
     258    COUT(5) << "id of GameStateCompressed:   " << data->id << std::endl;
     259    COUT(5) << "size of GameStateCompressed: " << data->compsize << std::endl;
    253260  }
    254261
    255262  void PacketDecoder::printClassid( classid *cid)
    256263  {
    257     cout << "id of classid:    " << cid->id << endl;
    258     cout << "size of classid:  " << cid->length << endl;
    259     cout << "ID of classid:    " << cid->clid <<endl;
    260     cout << "data of classid:  " << cid->message <<endl;
     264    COUT(5) << "id of classid:    " << cid->id << std::endl;
     265    COUT(5) << "size of classid:  " << cid->length << std::endl;
     266    COUT(5) << "ID of classid:    " << cid->clid << std::endl;
     267    COUT(5) << "data of classid:  " << cid->message << std::endl;
    261268  }
    262269
  • code/trunk/src/network/PacketGenerator.cc

    r790 r1021  
    5050  ENetPacket* PacketGenerator::acknowledgement( int state, int reliable )
    5151  {
    52     std::cout << "generating new acknowledgement, id: " << state << std::endl;
     52    COUT(4) << "generating new acknowledgement, id: " << state << std::endl;
    5353    ack* ackreq = new ack;
    5454    ackreq->id = ACK;
     
    6363  ENetPacket* PacketGenerator::mousem( double x, double y, int reliable )
    6464  {
    65     std::cout << "generating new mouse" << std::endl;
     65    COUT(4) << "generating new mouse" << std::endl;
    6666    mouse* mousemove = new mouse;
    6767    mousemove->id = MOUSE;
     
    7777  ENetPacket* PacketGenerator::keystrike( char press, int reliable )
    7878  {
    79     std::cout << "generating new keyboard" << std::endl;
     79    COUT(4) << "generating new keyboard" << std::endl;
    8080    keyboard* key = new keyboard;
    8181    key->id = KEYBOARD;
  • code/trunk/src/network/PacketManager.h

    r790 r1021  
    44#include <string>
    55#include <enet/enet.h>
     6
     7#include "core/CoreIncludes.h"
    68
    79#include "NetworkPrereqs.h"
     
    6567    virtual void processGamestate(GameStateCompressed *state);
    6668    virtual void processAck( ack *data, int clientID);
    67     void processClassid( classid *cid);
     69    virtual void processClassid( classid *cid);
    6870    //virtual void processAck( ack *data);
    6971
  • code/trunk/src/network/Server.cc

    r790 r1021  
    1818#include "ClientInformation.h"
    1919//#include "NetworkFrameListener.h"
     20#include "util/Sleep.h"
    2021#include "Server.h"
    2122
     
    112113    processQueue();
    113114    updateGamestate();
     115
     116    sleep(1); // TODO remove
    114117    return;
    115118  }
     
    134137    gamestates->update();
    135138    //std::cout << "updated gamestate, sending it" << std::endl;
    136     sendGameState();
     139    //if(clients->getGamestateID()!=GAMESTATEID_INITIAL)
     140      sendGameState();
    137141    //std::cout << "sent gamestate" << std::endl;
    138142  }
     
    142146  */
    143147  bool Server::sendGameState() {
    144     std::cout << "starting gamestate" << std::endl;
     148    COUT(5) << "starting sendGameState" << std::endl;
    145149    ClientInformation *temp = clients;
    146150    bool added=false;
     
    151155      }
    152156      if( !(temp->getSynched()) ){
    153         std::cout << "not sending gamestate" << std::endl;
     157        COUT(5) << "not sending gamestate" << std::endl;
    154158        temp=temp->next();
    155159        continue;
    156160      }
    157       std::cout << "doing gamestate" << std::endl;
     161      COUT(5) << "doing gamestate gamestate preparation" << std::endl;
    158162      int gid = temp->getGamestateID();
    159163      int cid = temp->getID();
    160       std::cout << "server, got acked ID: " << gid << std::endl;
    161       GameStateCompressed *gs = &(gamestates->popGameState(cid)); // FIXME: taking address of temporary, check if correct
     164      COUT(5) << "server, got acked (gamestate) ID: " << gid << std::endl;
     165      GameStateCompressed *gs = gamestates->popGameState(cid);
     166      if(gs==NULL){
     167        COUT(2) << "could not generate gamestate" << std::endl;
     168        return false;
     169      }
    162170      //std::cout << "adding gamestate" << std::endl;
    163171      connection->addPacket(packet_gen.gstate(gs), cid);
     
    168176    if(added)
    169177      return connection->sendPackets();
    170     else
    171       return false;
     178    COUT(5) << "had no gamestates to send" << std::endl;
     179    return false;
    172180  }
    173181
    174182  void Server::processAck( ack *data, int clientID) {
     183    COUT(5) << "processing ack from client: " << clientID << "; ack-id: " << data->id << std::endl;
    175184    clients->findClient(clientID)->setGamestateID(data->a);
    176185  }
  • code/trunk/src/network/Server.h

    r790 r1021  
    1616#include <string>
    1717
     18#include "NetworkPrereqs.h"
     19
     20#include "core/Tickable.h"
    1821#include "PacketManager.h"
    19 #include "NetworkPrereqs.h"
     22
     23
    2024
    2125namespace network
     
    2529  * It implements all functions necessary for a Server
    2630  */
    27   class _NetworkExport Server : public PacketDecoder{
     31  class _NetworkExport Server : public PacketDecoder, public orxonox::Tickable{
    2832  public:
    2933    Server();
  • code/trunk/src/network/Synchronisable.h

    r871 r1021  
    5656    int getSize();
    5757    bool updateData(syncData vars);
    58     void registerAllVariables();
     58    virtual void registerAllVariables()=0;
    5959    virtual bool create()=0;
    6060  protected:
  • code/trunk/src/network/dummyclient3.cc

    r790 r1021  
    1313  network::PacketGenerator pck;
    1414  const int PORT = 55556;
    15   std::cout << "Enter address of the server xxx.xxx.xxx.xxx (enter for localhost)" << std::endl;
     15  COUT(0) << "Enter address of the server xxx.xxx.xxx.xxx (enter for localhost)" << std::endl;
    1616  std::string str;
    1717  std::getline(std::cin, str);
    18   std::cout << "You entered: " << str << std::endl;
     18  COUT(3) << "You entered: " << str << std::endl;
    1919  if(str.compare("")==0)
    2020    str="127.0.0.1";
     
    2222  Client client( str, PORT );
    2323  if ( client.establishConnection() )
    24     std::cout << "connection established" << std::endl;
    25   else std::cout << "problems establishing connection" << std::endl;
     24    COUT(3) << "connection established" << std::endl;
     25  else COUT(0) << "problems establishing connection" << std::endl;
    2626  char message[10000];
    2727  char signs[] = "abcdefghijklmnopqrstuvwxy";
Note: See TracChangeset for help on using the changeset viewer.