Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1699


Ignore:
Timestamp:
Sep 4, 2008, 9:47:34 AM (16 years ago)
Author:
scheusso
Message:

some missing files

Location:
code/branches/network/src/network
Files:
1 deleted
12 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/network/CMakeLists.txt

    r1666 r1699  
    3838  ##### test for gamestate stuff #####
    3939  SET( TEST_SRC_FILES
    40     ConnectionManager.cc
    41     GameStateManager.cc
    42     PacketBuffer.cc
    43     PacketDecoder.cc
    44     PacketGenerator.cc
    45     ClientConnection.cc
    46     ClientInformation.cc
    47     diffTest.cc
    48     GameStateClient.cc
    49     Server.cc
    50     Client.cc 
    51     Synchronisable.cc 
     40    ${NETWORK_SRC_FILES}
    5241  )
    53 
    5442  ADD_EXECUTABLE(networktest ${TEST_SRC_FILES})
    5543  TARGET_LINK_LIBRARIES( networktest
     
    6250  ##### end test for gamestate stuff #####
    6351ENDIF(NETWORK_TESTING_ENABLED)
    64 # build this if you want dummyserver4 and dummyclient4
    65 IF(NETWORKTRAFFIC_TESTING_ENABLED)
    66   ##### test network traffic #####
    67   SET( DUMMYSERVER4_SRC_FILES
    68     ConnectionManager.cc
    69     GameStateManager.cc
    70     PacketBuffer.cc
    71     PacketDecoder.cc
    72     PacketGenerator.cc
    73     ClientConnection.cc
    74     ClientInformation.cc
    75     GameStateClient.cc
    76     Server.cc
    77     Client.cc 
    78     Synchronisable.cc
    79     dummyserver4.cc
    80   )
    81 
    82   SET( DUMMYCLIENT4_SRC_FILES
    83     ConnectionManager.cc
    84     GameStateManager.cc
    85     PacketBuffer.cc
    86     PacketDecoder.cc
    87     PacketGenerator.cc
    88     ClientConnection.cc
    89     ClientInformation.cc
    90     GameStateClient.cc
    91     Server.cc
    92     Client.cc 
    93     Synchronisable.cc
    94     dummyclient4.cc
    95   )
    96 
    97   ADD_EXECUTABLE(dummyserver4 ${DUMMYSERVER4_SRC_FILES})
    98   TARGET_LINK_LIBRARIES( dummyserver4
    99     network
    100     ${ENet_LIBRARY}
    101     ${ZLIB_LIBRARY}
    102     ${WINDOWS_ENET_DEPENDENCIES}
    103     ${Boost_thread_LIBRARIES}
    104     core
    105     orxonoxs
    106     audio
    107   )
    108 
    109   ADD_EXECUTABLE(dummyclient4 ${DUMMYCLIENT4_SRC_FILES})
    110   TARGET_LINK_LIBRARIES( dummyclient4
    111     network
    112     ${ENet_LIBRARY}
    113     ${ZLIB_LIBRARY}
    114     ${WINDOWS_ENET_DEPENDENCIES}
    115     ${Boost_thread_LIBRARIES}
    116     core
    117     orxonoxs
    118     audio
    119   )
    120 ENDIF(NETWORKTRAFFIC_TESTING_ENABLED)
    121 
    122 IF(BLABLA)
    123   SET( CHATCLIENT_SRC_FILES
    124     ClientConnection.cc
    125     Client.cc
    126     PacketBuffer.cc
    127     PacketDecoder.cc
    128     PacketGenerator.cc
    129     dummyclient3.cc
    130   )
    131 
    132   SET( CHATSERVER_SRC_FILES
    133     ConnectionManager.cc
    134     GameStateManager.cc
    135     PacketBuffer.cc
    136     PacketDecoder.cc
    137     PacketGenerator.cc
    138     dummyserver3.cc
    139   )
    140 
    141   # chatserver for testing purposes
    142   ADD_EXECUTABLE(chatserver ${CHATSERVER_SRC_FILES})
    143   TARGET_LINK_LIBRARIES( chatserver
    144     ${OGRE_LIBRARIES}
    145     network
    146     core
    147     #objects
    148     ${ENet_LIBRARY}
    149     ${ZLIB_LIBRARY}
    150     ${WINDOWS_ENET_DEPENDENCIES}
    151   )
    152 
    153   # chatclient for testing purpose
    154   ADD_EXECUTABLE(chatclient ${CHATCLIENT_SRC_FILES})
    155   TARGET_LINK_LIBRARIES( chatclient
    156     ${OGRE_LIBRARIES}
    157     network
    158     core
    159     #objects
    160     ${ENet_LIBRARY}
    161     ${ZLIB_LIBRARY}
    162     ${WINDOWS_ENET_DEPENDENCIES}
    163   )
    164 
    165   # client for testing purpose
    166   ADD_EXECUTABLE(client dummyclient2.cc)
    167   TARGET_LINK_LIBRARIES( client
    168     ${OGRE_LIBRARIES}
    169     network
    170     core
    171     #objects
    172     ${ENet_LIBRARY}
    173     ${ZLIB_LIBRARY}
    174     ${WINDOWS_ENET_DEPENDENCIES}
    175   )
    176 
    177   # server for testing purpose
    178   ADD_EXECUTABLE(server dummyserver.cc)
    179   TARGET_LINK_LIBRARIES( server
    180     ${OGRE_LIBRARIES}
    181     network
    182     core
    183     #objects
    184     ${ENet_LIBRARY}
    185     ${ZLIB_LIBRARY}
    186     ${WINDOWS_ENET_DEPENDENCIES}
    187   )
    188 ENDIF(BLABLA)
    189 
  • code/branches/network/src/network/Client.cc

    r1666 r1699  
    207207    return;
    208208  }
     209 
     210  bool Client::ackGamestateID(int gamestateID, int clientID){
     211    return true;
     212    //TODO: maybe change this (not needed at the moment)
     213  }
    209214
    210215//   void Client::processChat( chat *data, int clientId){
  • code/branches/network/src/network/Client.h

    r1666 r1699  
    7979//    static void Chat( std::string message );
    8080   
    81     int shipID(){return shipID_;}
     81    unsigned int shipID(){return shipID_;}
    8282    int playerID(){return clientID_;}
    8383
     
    9797    void processGamestate( GameStateCompressed *data, int clientID);
    9898    void processClassid(classid *clid);
     99    bool ackGamestateID(int gamestateID, int clientID);
    99100//     void processChat( chat *data, int clientId );
    100101    bool processWelcome( welcome *w );
  • code/branches/network/src/network/ClientInformation.h

    r1666 r1699  
    7272    bool setGameStateID(int id);
    7373    bool setPartialGamestateID(int id);
    74     inline void setShipID(int id){ShipID_=id;}
     74    inline void setShipID(unsigned int id){ShipID_=id;}
    7575   
    7676    // get functions
    77     inline int getShipID(){return ShipID_;}
     77    inline unsigned int getShipID(){return ShipID_;}
    7878    int getID();
    7979    int getGamestateID();
     
    112112    int gamestateID_;
    113113    int partialGamestateID_;
    114     int ShipID_;   // this is the unique objectID
     114    unsigned int ShipID_;   // this is the unique objectID
    115115    bool synched_;
    116116    unsigned short failures_;
  • code/branches/network/src/network/ConnectionManager.cc

    r1666 r1699  
    360360 
    361361  bool ConnectionManager::removeShip(ClientInformation *client){
    362     int id=client->getShipID();
     362    unsigned int id=client->getShipID();
    363363    orxonox::Iterator<orxonox::SpaceShip> it;
    364364    for(it = orxonox::ObjectList<orxonox::SpaceShip>::start(); it; ++it){
  • code/branches/network/src/network/GameStateClient.cc

    r1534 r1699  
    3434#include "core/BaseObject.h"
    3535#include "Synchronisable.h"
    36 
     36#include "packet/Gamestate.h"
    3737
    3838namespace network
     
    125125      if(b)
    126126        loadShipCache();
     127      packet::Gamestate *g = new packet::Gamestate();
     128      if(!g->collectData(1, 0x1))
     129        COUT(3) << "problem testing data collecting" << std::endl;
     130      else
     131      {
     132        if(!g->spreadData(0x1))
     133          COUT(3) << "problem testing data spreading" << std::endl;
     134        delete g;
     135      }
    127136      return id;
    128137    }
  • code/branches/network/src/network/Host.cc

    r1675 r1699  
    3131  if(!instance_)
    3232    return false;
    33   packet::Chat *c = new packet::Chat(message);
     33  packet::Chat *c = new packet::Chat(message, getPlayerID());
    3434  return instance_->sendChat(c);
    3535}
     
    4848}
    4949
    50 int Host::getShipID(){
     50unsigned int Host::getShipID(){
    5151  if(!instance_)
    5252    return 0;
     
    5454}
    5555
     56bool Host::ackGamestate(int gamestateID, int clientID){
     57  return instance_->ackGamestateID(gamestateID, clientID);
     58}
     59
    5660}//namespace network
  • code/branches/network/src/network/Host.h

    r1675 r1699  
    4444    virtual bool sendChat(packet::Chat *chat)=0;
    4545    virtual bool queuePacket(ENetPacket *packet, int clientID)=0;
    46     virtual int shipID()=0;
     46    virtual bool ackGamestateID(int gamestateID, int clientID)=0;
     47    virtual unsigned int shipID()=0;
    4748    virtual int playerID()=0;
    4849   
     
    6061    static bool receiveChat(packet::Chat *message, unsigned int clientID);
    6162    static int getPlayerID();
    62     static int getShipID();
     63    static unsigned int getShipID();
     64    static bool ackGamestate(int gamestateID, int clientID);
    6365};
    6466
  • code/branches/network/src/network/Server.cc

    r1666 r1699  
    302302  }
    303303 
     304  bool Server::ackGamestateID(int gamestateID, int clientID){
     305    gamestates->ackGameState(clientID, gamestateID);
     306    return true;
     307  }
     308 
    304309  void Server::processGamestate( GameStateCompressed *data, int clientID){
    305310    COUT(4) << "processing partial gamestate from client " << clientID << std::endl;
  • code/branches/network/src/network/Server.h

    r1666 r1699  
    7676    void updateGamestate();
    7777  private:
    78     int shipID(){return 0;}
     78    unsigned int shipID(){return 0;}
    7979    int playerID(){return 0;}
    8080   
     
    8989    bool processConnectRequest( connectRequest *con, int clientID );
    9090    void processGamestate( GameStateCompressed *data, int clientID);
     91   
     92    bool ackGamestateID(int gamestateID, int clientID);
     93   
    9194    //void processChat( chat *data, int clientId);
    9295    ConnectionManager *connection;
  • code/branches/network/src/network/Synchronisable.cc

    r1534 r1699  
    4343#include <string>
    4444#include <iostream>
     45#include <assert.h>
    4546
    4647#include "core/CoreIncludes.h"
     48#include "core/BaseObject.h"
    4749// #include "core/Identifier.h"
    4850
     
    8486    else  // server
    8587      state_=0x1;
     88  }
     89 
     90  bool Synchronisable::fabricate(unsigned char*& mem, int mode)
     91  {
     92    int size, objectID, classID;
     93    size = *(int *)mem;
     94    objectID = *(int*)(mem+sizeof(int));
     95    classID = *(int*)(mem+2*sizeof(int));
     96   
     97    orxonox::Identifier* id = ID((unsigned int)classID);
     98    if(!id){
     99      COUT(3) << "We could not identify a new object; classid: " << classID << " uint: " << (unsigned int)classID << " objectID: " << objectID << " size: " << size << std::endl;
     100      return false; // most probably the gamestate is corrupted
     101    }
     102    Synchronisable *no = dynamic_cast<Synchronisable *>(id->fabricate());
     103    if(!no){
     104      COUT(2) << "coudl not frabricate classid: " << classID << " objectID: " << objectID << " identifier: " << id << std::endl;
     105      return false;
     106    }
     107    no->objectID=objectID;
     108    no->classID=classID;
     109          // update data and create object/entity...
     110    if( !no->updateData(mem, mode) ){
     111      COUT(1) << "We couldn't update the object: " << objectID << std::endl;
     112      return false;
     113    }
     114    if( !no->create() )
     115    {
     116      COUT(1) << "We couldn't manifest (create() ) the object: " << objectID << std::endl;
     117      return false;
     118    }
     119    return true;
    86120  }
    87121
     
    108142  }
    109143
    110   /**
    111   * note: only use this function for debug use, because it's inefficient (in order to produce a gamestate, you have to copy the whole data again to another memory location after this process)
    112   * This function takes all SynchronisableVariables out of the Synchronisable and saves it into a syncData struct
    113   * structure of the bitstream:
    114   * (var1_size,var1,var2_size,var2,...)
    115   * varx_size: size = sizeof(int)
    116   * varx: size = varx_size
    117   * @return data containing all variables and their sizes
    118   */
    119   // syncData Synchronisable::getData(){
    120   //   std::list<synchronisableVariable>::iterator i;
    121   //   int totalsize=0;
    122   //   //figure out size of data to be allocated
    123   //   for(i=syncList->begin(); i!=syncList->end(); i++){
    124   //     // increase size (size of variable and size of size of variable ;)
    125   //     if(i->type == STRING)
    126   //       totalsize+=sizeof(int)+((std::string *)i->var)->length()+1;
    127   //     else
    128   //       totalsize+=sizeof(int)+i->size;
    129   //   }
    130   //   syncData retVal;
    131   //   retVal.objectID=this->objectID;
    132   //   retVal.classID=this->classID;
    133   //   retVal.length=totalsize;
    134   //   // allocate memory
    135   //   retVal.data = (unsigned char *)malloc(totalsize);
    136   //   // copy to location
    137   //   //CHANGED: REMOVED DECLARATION int n=0 FROM LOOP
    138   //   int n=0;
    139   //   for(i=syncList->begin(); n<totalsize && i!=syncList->end(); i++){
    140   //     std::memcpy(retVal.data+n, (const void*)(i->size), sizeof(int));
    141   //     n+=sizeof(int);
    142   //     switch(i->type){
    143   //     case STRING:
    144   //       std::memcpy(retVal.data+n, (const void *)(((std::string *)i->var)->c_str()), ((std::string *)i->var)->length()+1);
    145   //       n+=((std::string *)i->var)->length()+1;
    146   //       break;
    147   //     case DATA:
    148   //       std::memcpy(retVal.data+n, ((const void*)i->var), i->size);
    149   //       n+=i->size;
    150   //       break;
    151   //     }
    152   //   }
    153   //   return retVal;
    154   // }
     144
    155145  /**
    156146  * This function takes all SynchronisableVariables out of the Synchronisable and saves it into a syncData struct
     
    202192    return retVal;
    203193  }
    204 
     194 
     195  /**
     196   * This function takes all SynchronisableVariables out of the Synchronisable and saves it into a syncData struct
     197  * Difference to the above function:
     198   * takes a pointer to already allocated memory (must have at least getSize bytes length)
     199  * structure of the bitstream:
     200   * (var1_size,var1,var2_size,var2,...)
     201   * varx_size: size = sizeof(int)
     202   * varx: size = varx_size
     203   * @return data containing all variables and their sizes
     204   */
     205  bool Synchronisable::getData2(unsigned char*& mem, int mode){
     206    //std::cout << "inside getData" << std::endl;
     207    unsigned int tempsize = 0;
     208    if(mode==0x0)
     209      mode=state_;
     210    if(classID==0)
     211      COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl;
     212    this->classID=this->getIdentifier()->getNetworkID();
     213    std::list<synchronisableVariable *>::iterator i;
     214    unsigned int size;
     215    size=getSize2(mode);
     216   
     217    // start copy header
     218    memcpy(mem, &size, sizeof(unsigned int));
     219    mem+=sizeof(unsigned int);
     220    memcpy(mem, &(this->objectID), sizeof(unsigned int));
     221    mem+=sizeof(unsigned int);
     222    memcpy(mem, &(this->classID), sizeof(unsigned int));
     223    mem+=sizeof(unsigned int);
     224    tempsize+=12;
     225    // end copy header
     226   
     227   
     228    COUT(5) << "Synchronisable getting data from objectID: " << objectID << " classID: " << classID << " length: " << size << std::endl;
     229    // copy to location
     230    for(i=syncList->begin(); i!=syncList->end(); ++i){
     231      //(std::memcpy(retVal.data+n, (const void*)(&(i->size)), sizeof(int));
     232      if( ((*i)->mode & mode) == 0 ){
     233        COUT(5) << "not getting data: " << std::endl;
     234        continue;  // this variable should only be received
     235      }
     236      switch((*i)->type){
     237        case DATA:
     238          memcpy( (void *)(mem), (void*)((*i)->var), (*i)->size);
     239          mem+=(*i)->size;
     240          tempsize+=(*i)->size;
     241          break;
     242        case STRING:
     243          memcpy( (void *)(mem), (void *)&((*i)->size), sizeof(int) );
     244          mem+=sizeof(int);
     245          const char *data = ( ( *(std::string *) (*i)->var).c_str());
     246          memcpy( mem, (void*)data, (*i)->size);
     247          COUT(5) << "synchronisable: char: " << (const char *)(mem) << " data: " << data << " string: " << *(std::string *)((*i)->var) << std::endl;
     248          mem+=(*i)->size;
     249          tempsize+=(*i)->size + 4;
     250          break;
     251      }
     252    }
     253    assert(tempsize==size);
     254    return true;
     255  }
     256
     257  /*bool Synchronisable::getData(Bytestream& bs, int mode)
     258  {
     259    //std::cout << "inside getData" << std::endl;
     260    if(mode==0x0)
     261      mode=state_;
     262    if(classID==0)
     263      COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl;
     264    this->classID=this->getIdentifier()->getNetworkID();
     265    std::list<synchronisableVariable *>::iterator i;
     266    bs << this->getSize();
     267    bs << this->objectID;
     268    bs << this->classID;
     269    // copy to location
     270    for(i=syncList->begin(); i!=syncList->end(); ++i){
     271      if( ((*i)->mode & mode) == 0 ){
     272        COUT(5) << "not getting data: " << std::endl;
     273        continue;  // this variable should only be received
     274      }
     275      switch((*i)->type){
     276        case DATA:
     277          bs << *(*i)->var;
     278          //std::memcpy( (void *)(retVal.data+n), (void*)((*i)->var), (*i)->size);
     279          //n+=(*i)->size;
     280          break;
     281        case STRING:
     282          bs << *(String *)((*i)->var);
     283          //memcpy( (void *)(retVal.data+n), (void *)&((*i)->size), sizeof(int) );
     284          //n+=sizeof(int);
     285          //const char *data = ( ( *(std::string *) (*i)->var).c_str());
     286          //std::memcpy( retVal.data+n, (void*)data, (*i)->size);
     287          //COUT(5) << "synchronisable: char: " << (const char *)(retVal.data+n) << " data: " << data << " string: " << *(std::string *)((*i)->var) << std::endl;
     288          //n+=(*i)->size;
     289          break;
     290      }
     291    }
     292    return true;
     293  }*/
     294
     295 
    205296  /**
    206297  * This function takes a syncData struct and takes it to update the variables
     
    246337      }
    247338      // call the callback function, if defined
    248       if(callback)
     339      if(callback && (*i)->callback)
     340        (*i)->callback->call();
     341    }
     342    return true;
     343  }
     344 
     345  /**
     346   * This function takes a syncData struct and takes it to update the variables
     347   * @param vars data of the variables
     348   * @return true/false
     349   */
     350  bool Synchronisable::updateData(unsigned char*& mem, int mode){
     351    unsigned char *data = mem;
     352    if(mode==0x0)
     353      mode=state_;
     354    std::list<synchronisableVariable *>::iterator i;
     355    if(syncList->empty()){
     356      COUT(4) << "Synchronisable::updateData syncList is empty" << std::endl;
     357      return false;
     358    }
     359   
     360    // start extract header
     361    unsigned int objectID, classID, size;
     362    size = *(int *)mem;
     363    mem+=sizeof(size);
     364    objectID = *(int *)mem;
     365    mem+=sizeof(objectID);
     366    classID = *(int *)mem;
     367    mem+=sizeof(classID);
     368    // stop extract header
     369    assert(this->objectID==objectID);
     370    assert(this->classID==classID);
     371   
     372    COUT(5) << "Synchronisable: objectID " << objectID << ", classID " << classID << " size: " << size << " synchronising data" << std::endl;
     373    for(i=syncList->begin(); i!=syncList->end() && mem <= data+size; i++){
     374      if( ((*i)->mode ^ mode) == 0 ){
     375        COUT(5) << "synchronisable: not updating variable " << std::endl;
     376        continue;  // this variable should only be set
     377      }
     378      COUT(5) << "Synchronisable: element size: " << (*i)->size << " type: " << (*i)->type << std::endl;
     379      bool callback=false;
     380      switch((*i)->type){
     381        case DATA:
     382          if((*i)->callback) // check whether this variable changed (but only if callback was set)
     383            if(strncmp((char *)(*i)->var, (char *)mem, (*i)->size)!=0)
     384              callback=true;
     385          memcpy((void*)(*i)->var, mem, (*i)->size);
     386          mem+=(*i)->size;
     387          break;
     388        case STRING:
     389          (*i)->size = *(int *)mem;
     390          COUT(5) << "string size: " << (*i)->size << std::endl;
     391          mem+=sizeof(int);
     392          if((*i)->callback) // check whether this string changed
     393            if( *(std::string *)((*i)->var) != std::string((char *)mem) )
     394              callback=true;
     395          *((std::string *)((*i)->var)) = std::string((const char*)mem);
     396          COUT(5) << "synchronisable: char: " << (const char*)mem << " string: " << std::string((const char*)mem) << std::endl;
     397          mem += (*i)->size;
     398          break;
     399      }
     400      // call the callback function, if defined
     401      if(callback && (*i)->callback)
    249402        (*i)->callback->call();
    250403    }
     
    279432  }
    280433 
     434  /**
     435   * This function returns the total amount of bytes needed by getData to save the whole content of the variables
     436   * @return amount of bytes
     437   */
     438  int Synchronisable::getSize2(int mode){
     439    return 3*sizeof(unsigned int) + getSize( mode );
     440  }
     441 
     442  bool Synchronisable::isMyData(unsigned char* mem)
     443  {
     444    unsigned int objectID, classID, size;
     445    size = *(int *)mem;
     446    mem+=sizeof(size);
     447    objectID = *(int *)mem;
     448    mem+=sizeof(objectID);
     449    classID = *(int *)mem;
     450    mem+=sizeof(classID);
     451   
     452    assert(classID == this->classID);
     453    return (objectID == this->objectID);
     454  }
     455 
    281456  void Synchronisable::setBacksync(bool sync){
    282457    backsync_=sync;
  • code/branches/network/src/network/Synchronisable.h

    r1534 r1699  
    3535#include "core/OrxonoxClass.h"
    3636#include "NetworkCallback.h"
     37#include "util/Bytestream.h"
    3738
    3839namespace network
     
    4445
    4546  struct syncData{
    46     int length;
    47     int objectID;
    48     int classID;
     47    unsigned int length;
     48    unsigned int objectID;
     49    unsigned int classID;
    4950    unsigned char *data;
    5051  };
    5152
    5253  typedef struct synchronisableVariable{
    53     int size;
     54    unsigned int size;
    5455    int mode; // this determines in which direction the variable gets synchronised
    5556    void *var;
     
    6970
    7071    virtual ~Synchronisable();
    71     int objectID;
    72     int classID;
     72    unsigned int objectID;
     73    unsigned int classID;
    7374
    7475    void registerVar(void *var, int size, variableType t, int mode=1, NetworkCallbackBase *cb=0);
    7576    //  syncData getData();
    7677    syncData getData(unsigned char *mem, int mode=0x0);
     78    bool getData2(unsigned char*& men, int mode=0x0);
     79    //bool getData(Bytestream& bs, int mode=0x0);
    7780    int getSize(int mode=0x0);
     81    int getSize2(int mode=0x0);
    7882    bool updateData(syncData vars, int mode=0x0);
     83    bool updateData(unsigned char*& mem, int mode=0x0);
     84    bool isMyData(unsigned char* mem);
    7985    void setBacksync(bool sync);
    8086    bool getBacksync();
     
    8288    virtual bool create();
    8389    static void setClient(bool b);
     90   
     91    static bool fabricate(unsigned char*& mem, int mode=0x0);
    8492  protected:
    8593    Synchronisable();
Note: See TracChangeset for help on using the changeset viewer.