Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1901


Ignore:
Timestamp:
Oct 12, 2008, 12:15:30 PM (16 years ago)
Author:
scheusso
Message:

Lots of changes:
Some fixes/hacks in objects
Changes in Gamestates and bugfixes
Removed some asserts

Location:
code/branches/network
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/TODO

    r1834 r1901  
    22        !!! check that enet does not cause a packet traffic jam when a reliable packet gets missed !!!
    33        [implemented] new gamestate concept
    4         check Projectiles
    5         check that we dont have to much registervar because of virtual function calls
     4
     5        !!! ensure that objects get synched, when newly created, even if not their tick
    66
    77        setvariable mode
    88        objectmode
    9         friend classes
    10         priorities
    11         static (sync once)
    12         triggerSync
     9        priorities (put into gamestatehandler)
     10                manage delete object handling (only send deletes of acked objects)
     11        static (sync once) & triggerSync
     12
     13REMARKS:
     14        try to allocate sort the bytestream before copy (putt all 0's in one place)
  • code/branches/network/src/network/Client.cc

    r1793 r1901  
    6060    isSynched_=false;
    6161    gameStateFailure_=false;
    62     isServer_ = false;
    6362  }
    6463
     
    7271    isSynched_=false;
    7372    gameStateFailure_=false;
    74     isServer_ = false;
    7573  }
    7674
     
    8482    isSynched_=false;
    8583    gameStateFailure_=false;
    86     isServer_ = false;
    8784  }
    8885
     
    155152      COUT(5) << "tick packet size " << event->packet->dataLength << std::endl;
    156153      packet::Packet *packet = packet::Packet::createPacket(event->packet, event->peer);
    157       assert(packet->process());
     154      bool b = packet->process();
     155      assert(b);
    158156    }
    159157    if(gamestate.processGamestates())
  • code/branches/network/src/network/Client.h

    r1793 r1901  
    8585
    8686  private:
     87    virtual bool isServer_(){return false;}
    8788   
    8889    ClientConnection client_connection;
  • code/branches/network/src/network/ClientConnection.cc

    r1755 r1901  
    7777  }
    7878
    79 
    80   /*ENetPacket *ClientConnection::getPacket(ENetAddress &address) {
    81     if(!buffer.isEmpty()) {
    82       //std::cout << "###BUFFER IS NOT EMPTY###" << std::endl;
    83       return buffer.pop(address);
    84     }
    85     else{
    86       return NULL;
    87     }
    88   }
    89 
    90   ENetPacket *ClientConnection::getPacket() {
    91     ENetAddress address; //sems that address is not needed
    92     return getPacket(address);
    93   }*/
     79  ClientConnection::~ClientConnection(){
     80    if(established)
     81      closeConnection();
     82  }
    9483
    9584  ENetEvent *ClientConnection::getEvent(){
  • code/branches/network/src/network/ClientConnection.h

    r1755 r1901  
    6464    ClientConnection(int port, std::string address);
    6565    ClientConnection(int port, const char* address);
    66     //ENetPacket *getPacket(ENetAddress &address); // thread1
    67     //ENetPacket *getPacket(); // thread1
     66    ~ClientConnection();
    6867    ENetEvent *getEvent();
    6968    // check wheter the packet queue is empty
  • code/branches/network/src/network/ConnectionManager.cc

    r1834 r1901  
    8080  boost::recursive_mutex ConnectionManager::enet_mutex;
    8181
    82 //   ConnectionManager::ConnectionManager(ClientInformation *head) : receiverThread_(0) {
    83 //     assert(instance_==0);
    84 //     instance_=this;
    85 //     quit=false;
    86 //     bindAddress.host = ENET_HOST_ANY;
    87 //     bindAddress.port = NETWORK_PORT;
    88 //   }
    89 
    9082  ConnectionManager::ConnectionManager(int port){
    9183    assert(instance_==0);
     
    113105
    114106  ConnectionManager::~ConnectionManager(){
    115     instance_=0;
    116107    if(!quit)
    117108      quitListener();
    118   }
    119 
    120   /*ENetPacket *ConnectionManager::getPacket(ENetAddress &address) {
    121     if(!buffer.isEmpty())
    122       return buffer.pop(address);
    123     else
    124       return NULL;
    125   }*/
    126 /**
    127 This function only pops the first element in PacketBuffer (first in first out)
    128 used by processQueue in Server.cc
    129 */
    130   /*ENetPacket *ConnectionManager::getPacket(int &clientID) {
    131     ENetAddress address;
    132     ENetPacket *packet=getPacket(address);
    133     ClientInformation *temp =head_->findClient(&address);
    134     if(!temp)
    135       return NULL;
    136     clientID=temp->getID();
    137     return packet;
    138   }*/
     109    instance_=0;
     110  }
     111
    139112
    140113  ENetEvent *ConnectionManager::getEvent(){
     
    163136  }
    164137
    165 //   bool ConnectionManager::addPacket(Packet::Packet *packet){
    166 //     ClientInformation *temp = instance_->head_->findClient(packet->getClientID());
    167 //     if(!temp){
    168 //       COUT(3) << "C.Man: addPacket findClient failed" << std::endl;
    169 //       return false;
    170 //     }
    171 //     ENetPacket *packet = new ENetPacket;
    172 //     //  TODO: finish implementation
    173 //   }
    174 //
    175138
    176139  bool ConnectionManager::addPacket(ENetPacket *packet, ENetPeer *peer) {
  • code/branches/network/src/network/GamestateClient.cc

    r1827 r1901  
    182182  packet::Gamestate *GamestateClient::processGamestate(packet::Gamestate *gs){
    183183    if(gs->isCompressed())
    184       assert(gs->decompressData());
     184    {
     185      bool b = gs->decompressData();
     186      assert(b);
     187    }
    185188    if(gs->isDiffed()){
    186189      packet::Gamestate *base = gamestateMap_[gs->getBaseID()];
  • code/branches/network/src/network/GamestateManager.cc

    r1827 r1901  
    154154      gs = new packet::Gamestate(*gs);
    155155    }
    156     assert(gs->compressData());
     156    bool b = gs->compressData();
     157    assert(b);
    157158    return gs;
    158159  }
     
    194195  bool GamestateManager::processGamestate(packet::Gamestate *gs){
    195196    if(gs->isCompressed())
    196        assert(gs->decompressData());
     197    {
     198       bool b = gs->decompressData();
     199       assert(b);
     200    }
    197201    assert(!gs->isDiffed());
    198202    return gs->spreadData();
  • code/branches/network/src/network/Host.h

    r1793 r1901  
    5252    virtual bool chat(std::string message)=0;
    5353    virtual bool processChat(std::string message, unsigned int playerID)=0;
     54    virtual bool isServer_()=0;
    5455
    5556
     
    5960    virtual ~Host();
    6061    static Host *instance_;
    61     bool isServer_;     
    6262    unsigned int clientID_;
    6363    unsigned int shipID_;
     
    7272    static void setClientID(unsigned int id){ instance_->clientID_ = id; }
    7373    static void setShipID(unsigned int id){ instance_->shipID_ = id; }
    74     static bool isServer(){ return instance_->isServer_; }             
     74    static bool isServer(){ return instance_->isServer_(); }           
    7575    static bool Chat(std::string message);
    7676    static bool incomingChat(std::string message, unsigned int playerID);
  • code/branches/network/src/network/Server.cc

    r1834 r1901  
    7272    connection = new ConnectionManager();
    7373    gamestates_ = new GamestateManager();
    74     isServer_ = true;
    7574  }
    7675
     
    7978    connection = new ConnectionManager(port);
    8079    gamestates_ = new GamestateManager();
    81     isServer_ = true;
    8280  }
    8381
     
    9189    connection = new ConnectionManager(port, bindAddress);
    9290    gamestates_ = new GamestateManager();
    93     isServer_ = true;
    9491  }
    9592
     
    103100    connection = new ConnectionManager(port, bindAddress);
    104101    gamestates_ = new GamestateManager();
    105     isServer_ = true;
     102  }
     103 
     104  /**
     105  * @brief Destructor
     106  */
     107  Server::~Server(){
     108    if(connection)
     109      delete connection;
     110    if(gamestates_)
     111      delete gamestates_;
    106112  }
    107113
     
    198204    //std::cout << "updated gamestate, sending it" << std::endl;
    199205    //if(clients->getGamestateID()!=GAMESTATEID_INITIAL)
     206    sendGameState();
    200207    sendObjectDeletes();
    201     sendGameState();
    202208    COUT(5) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl;
    203209    //std::cout << "sent gamestate" << std::endl;
     
    254260    if(!del->fetchIDs())
    255261      return true;  //everything ok (no deletes this tick)
     262//     COUT(3) << "sending DeleteObjects" << std::endl;
    256263    while(temp != NULL){
    257264      if( !(temp->getSynched()) ){
     
    307314    packet::Welcome *w = new packet::Welcome(temp->getID(), temp->getShipID());
    308315    w->setClientID(temp->getID());
    309     assert(w->send());
     316    bool b = w->send();
     317    assert(b);
    310318    packet::Gamestate *g = new packet::Gamestate();
    311319    g->setClientID(temp->getID());
    312     assert(g->collectData(0));
    313     assert(g->compressData());
    314     assert(g->send());
     320    b = g->collectData(0);
     321    assert(b);
     322    b = g->compressData();
     323    assert(b);
     324    b = g->send();
     325    assert(b);
    315326    return true;
    316327  }
  • code/branches/network/src/network/Server.h

    r1793 r1901  
    6363    Server(int port, std::string bindAddress);
    6464    Server(int port, const char *bindAddress);
     65    ~Server();
    6566   
    6667    void open();
     
    7374    void updateGamestate();
    7475  private:
     76    virtual bool isServer_(){return true;}
    7577    unsigned int shipID(){return 0;}
    7678    unsigned int playerID(){return 0;}
  • code/branches/network/src/network/Synchronisable.cc

    r1834 r1901  
    6464  Synchronisable::Synchronisable(){
    6565    RegisterRootObject(Synchronisable);
    66     static unsigned int idCounter=0;
     66    static uint32_t idCounter=0;
    6767    objectFrequency_=1;
    6868    objectMode_=0x1; // by default do not send data to server
    6969    objectID=idCounter++;
    70 //     COUT(3) << " bump +++" << objectID << " | " << &objectMap_ << std::endl;
    7170    syncList = new std::list<synchronisableVariable *>;
    7271  }
     
    8180      for(std::list<synchronisableVariable *>::iterator it = syncList->begin(); it!=syncList->end(); it++)
    8281        delete (*it)->callback;
     82      deletedObjects_.push(objectID);
     83//       COUT(3) << "destruct synchronisable +++" << objectID << " | " << classID << std::endl;
    8384//       COUT(3) << " bump ---" << objectID << " | " << &objectMap_ << std::endl;
    8485//       assert(objectMap_[objectID]->objectID==objectID);
     
    9495  bool Synchronisable::create(){
    9596    this->classID = this->getIdentifier()->getNetworkID();
    96     COUT(4) << "creating synchronisable: setting classid from " << this->getIdentifier()->getName() << " to: " << classID << std::endl;
    97    
     97//     COUT(4) << "creating synchronisable: setting classid from " << this->getIdentifier()->getName() << " to: " << classID << std::endl;
     98   
     99//     COUT(3) << "construct synchronisable +++" << objectID << " | " << classID << std::endl;
    98100//     objectMap_[objectID]=this;
    99101//     assert(objectMap_[objectID]==this);
     
    121123   * @return pointer to the newly created synchronisable
    122124   */
    123   Synchronisable *Synchronisable::fabricate(unsigned char*& mem, int mode)
     125  Synchronisable *Synchronisable::fabricate(uint8_t*& mem, int mode)
    124126  {
    125127    synchronisableHeader *header = (synchronisableHeader *)mem;
     128   
     129    COUT(3) << "fabricating object with id: " << header->objectID << std::endl;
    126130   
    127131    orxonox::Identifier* id = GetIdentifier(header->classID);
     
    134138    COUT(3) << "fabricate objectID: " << no->objectID << " classID: " << no->classID << std::endl;
    135139          // update data and create object/entity...
    136     assert(no->updateData(mem, mode));
    137     assert( no->create() );
     140    bool b = no->updateData(mem, mode);
     141    assert(b);
     142    b = no->create();
     143    assert(b);
    138144    return no;
    139145  }
     
    146152   */
    147153  bool Synchronisable::deleteObject(unsigned int objectID){
    148     assert(getSynchronisable(objectID));
     154//     assert(getSynchronisable(objectID));
     155    if(!getSynchronisable(objectID))
     156      return false;
    149157    assert(getSynchronisable(objectID)->objectID==objectID);
    150158//     delete objectMap_[objectID];
     
    222230   * @return true: if !isMyTick or if everything was successfully saved
    223231   */
    224   bool Synchronisable::getData(unsigned char*& mem, unsigned int id, int mode){
     232  bool Synchronisable::getData(uint8_t*& mem, unsigned int id, int mode){
    225233    //if this tick is we dont synchronise, then abort now
    226234    if(!isMyTick(id))
     
    232240    if(classID==0)
    233241      COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl;
    234     this->classID=this->getIdentifier()->getNetworkID(); // TODO: correct this
     242    assert(this->classID==this->getIdentifier()->getNetworkID());
     243//     this->classID=this->getIdentifier()->getNetworkID(); // TODO: correct this
    235244    std::list<synchronisableVariable *>::iterator i;
    236245    unsigned int size;
     
    283292   * @return true/false
    284293   */
    285   bool Synchronisable::updateData(unsigned char*& mem, int mode){
     294  bool Synchronisable::updateData(uint8_t*& mem, int mode){
    286295    if(mode==0x0)
    287296      mode=state_;
     
    291300      return false;
    292301    }
    293     unsigned char *data=mem;
     302    uint8_t *data=mem;
    294303    // start extract header
    295304    synchronisableHeader *syncHeader = (synchronisableHeader *)mem;
     
    322331          break;
    323332        case STRING:
    324           (*i)->size = *(int *)mem;
     333          (*i)->size = *(uint32_t *)mem;
    325334          COUT(5) << "string size: " << (*i)->size << std::endl;
    326335          mem+=sizeof(int);
     
    346355  * @return amount of bytes
    347356  */
    348   int Synchronisable::getSize(unsigned int id, int mode){
     357  uint32_t Synchronisable::getSize(unsigned int id, int mode){
    349358    if(!isMyTick(id))
    350359      return 0;
     
    388397   * @param mem pointer to the bytestream
    389398   */
    390   bool Synchronisable::isMyData(unsigned char* mem)
     399  bool Synchronisable::isMyData(uint8_t* mem)
    391400  {
    392401    synchronisableHeader *header = (synchronisableHeader *)mem;
  • code/branches/network/src/network/Synchronisable.h

    r1834 r1901  
    5757      bidirectional=0x3
    5858    };
    59    
     59  }
     60 
     61  namespace syncmode{
     62    enum mode{
     63      one=0,
     64      always=1
     65    };
    6066  }
    6167 
     
    6672
    6773  struct synchronisableHeader{
    68     unsigned int size;
    69     bool dataAvailable;
    70     unsigned int objectID;
    71     unsigned int classID;
     74    uint32_t size:31;
     75    bool dataAvailable:1;
     76    uint32_t objectID;
     77    uint32_t classID;
    7278  };
    7379
     
    97103    static void setClient(bool b);
    98104   
    99     static Synchronisable *fabricate(unsigned char*& mem, int mode=0x0);
     105    static Synchronisable *fabricate(uint8_t*& mem, int mode=0x0);
    100106    static bool deleteObject(unsigned int objectID);
    101107    static Synchronisable *getSynchronisable(unsigned int objectID);
     
    114120   
    115121  private:
    116     bool getData(unsigned char*& men, unsigned int id, int mode=0x0);
    117     int getSize(unsigned int id, int mode=0x0);
    118     bool updateData(unsigned char*& mem, int mode=0x0);
    119     bool isMyData(unsigned char* mem);
     122    bool getData(uint8_t*& men, unsigned int id, int mode=0x0);
     123    uint32_t getSize(unsigned int id, int mode=0x0);
     124    bool updateData(uint8_t*& mem, int mode=0x0);
     125    bool isMyData(uint8_t* mem);
    120126    bool doSelection(unsigned int id);
    121127    bool isMyTick(unsigned int id);
  • code/branches/network/src/network/packet/DeleteObjects.cc

    r1890 r1901  
    3737namespace packet {
    3838
    39 #define PACKET_FLAGS_DELETE    ENET_PACKET_FLAG_RELIABLE
     39#define PACKET_FLAG_DELETE  ENET_PACKET_FLAG_RELIABLE
    4040#define _PACKETID           0
    4141#define _QUANTITY           _PACKETID + sizeof(ENUM::Type)
     
    4545 : Packet()
    4646{
    47   flags_ = flags_ | PACKET_FLAGS_DELETE;
     47  flags_ = flags_ | PACKET_FLAG_DELETE;
    4848}
    4949
     
    6161  if(number==0)
    6262    return false;
     63  COUT(3) << "sending DeleteObjects: ";
    6364  unsigned int size = sizeof(ENUM::Type) + sizeof(uint32_t)*(number+1);
    6465  data_ = new uint8_t[size];
    65   *(ENUM::Type *)(data_ + _PACKETID ) = ENUM::DeleteObjects;
    66   *(uint32_t *)(data_ + _QUANTITY) = number;
     66  uint8_t *tdata = data_;
     67  *(ENUM::Type *)(tdata) = ENUM::DeleteObjects;
     68  tdata += sizeof(ENUM::Type);
     69  *(uint32_t *)tdata = number;
     70  tdata += sizeof(uint32_t);
    6771  for(unsigned int i=0; i<number; i++){
    68     *(uint32_t *)(data_ + sizeof(ENUM::Type) + (i+1)*sizeof(uint32_t)) = Synchronisable::popDeletedObject();
     72    unsigned int temp = Synchronisable::popDeletedObject();
     73//     assert(temp<10000); //ugly hack
     74    *(uint32_t *)(tdata) = temp;
     75    COUT(3) << temp << " ";
     76    tdata += sizeof(uint32_t);
    6977  }
     78  COUT(3) << std::endl;
    7079  return true;
    7180}
  • code/branches/network/src/network/packet/Gamestate.cc

    r1834 r1901  
    4747
    4848 
     49#define PACKET_FLAG_GAMESTATE  ENET_PACKET_FLAG_RELIABLE
     50 
    4951Gamestate::Gamestate()
    5052{
    51 }
    52 
    53 Gamestate::Gamestate(unsigned char *data, int clientID):
     53  flags_ = flags_ | PACKET_FLAG_GAMESTATE;
     54}
     55
     56Gamestate::Gamestate(uint8_t *data, unsigned int clientID):
    5457    Packet(data, clientID)
    5558{
    56 }
    57 
    58 Gamestate::Gamestate(unsigned char *data)
    59 {
     59  flags_ = flags_ | PACKET_FLAG_GAMESTATE;
     60}
     61
     62Gamestate::Gamestate(uint8_t *data)
     63{
     64  flags_ = flags_ | PACKET_FLAG_GAMESTATE;
    6065  data_=data;
    6166}
     
    8691#endif
    8792  //start collect data synchronisable by synchronisable
    88   unsigned char *mem=data_;
     93  uint8_t *mem=data_;
    8994  mem+=sizeof(GamestateHeader);
    9095  orxonox::ObjectList<Synchronisable>::iterator it;
     
    99104      while(++temp)
    100105        addsize+=temp->getSize(id, mode);
    101       data_ = (unsigned char *)realloc(data_, sizeof(GamestateHeader) + currentsize + addsize);
     106      data_ = (uint8_t *)realloc(data_, sizeof(GamestateHeader) + currentsize + addsize);
    102107      if(!data_)
    103108        return false;
     
    140145  assert(!HEADER->compressed);
    141146  assert(!HEADER->diffed);
    142   unsigned char *mem=data_+sizeof(GamestateHeader);
     147  uint8_t *mem=data_+sizeof(GamestateHeader);
    143148    // get the start of the Synchronisable list
    144149  //orxonox::ObjectList<Synchronisable>::iterator it=orxonox::ObjectList<Synchronisable>::begin();
     
    159164    else
    160165    {
    161       assert(s->updateData(mem, mode));
     166      bool b = s->updateData(mem, mode);
     167      assert(b);
    162168      //if(!s->updateData(mem, mode))
    163169        //return false;
     
    186192
    187193bool Gamestate::operator==(packet::Gamestate gs){
    188   unsigned char *d1 = data_+sizeof(GamestateHeader);
    189   unsigned char *d2 = gs.data_+sizeof(GamestateHeader);
     194  uint8_t *d1 = data_+sizeof(GamestateHeader);
     195  uint8_t *d2 = gs.data_+sizeof(GamestateHeader);
    190196  assert(!isCompressed());
    191197  assert(!gs.isCompressed());
     
    215221    return false;
    216222
    217   unsigned char *ndata = new unsigned char[buffer+sizeof(GamestateHeader)];
    218   unsigned char *dest = GAMESTATE_START(ndata);
     223  uint8_t *ndata = new uint8_t[buffer+sizeof(GamestateHeader)];
     224  uint8_t *dest = GAMESTATE_START(ndata);
    219225  //unsigned char *dest = new unsigned char[buffer];
    220   unsigned char *source = GAMESTATE_START(data_);
     226  uint8_t *source = GAMESTATE_START(data_);
    221227  int retval;
    222228  retval = compress( dest, &buffer, source, (uLong)(HEADER->datasize) );
     
    229235#ifndef NDEBUG
    230236  //decompress and compare the start and the decompressed data
    231   unsigned char *rdata = new unsigned char[HEADER->datasize+sizeof(GamestateHeader)];
    232   unsigned char *d2 = GAMESTATE_START(rdata);
     237  uint8_t *rdata = new uint8_t[HEADER->datasize+sizeof(GamestateHeader)];
     238  uint8_t *d2 = GAMESTATE_START(rdata);
    233239  uLongf length2 = HEADER->datasize;
    234240  uncompress(d2, &length2, dest, buffer);
     
    265271  bufsize = datasize;
    266272  assert(bufsize!=0);
    267   unsigned char *ndata = new unsigned char[bufsize + sizeof(GamestateHeader)];
    268   unsigned char *dest = ndata + sizeof(GamestateHeader);
    269   unsigned char *source = data_ + sizeof(GamestateHeader);
     273  uint8_t *ndata = new uint8_t[bufsize + sizeof(GamestateHeader)];
     274  uint8_t *dest = ndata + sizeof(GamestateHeader);
     275  uint8_t *source = data_ + sizeof(GamestateHeader);
    270276  int retval;
    271277  uLongf length=bufsize;
     
    299305  assert(!HEADER->diffed);
    300306  //unsigned char *basep = base->getGs()/*, *gs = getGs()*/;
    301   unsigned char *basep = GAMESTATE_START(base->data_), *gs = GAMESTATE_START(this->data_);
     307  uint8_t *basep = GAMESTATE_START(base->data_), *gs = GAMESTATE_START(this->data_);
    302308  unsigned int of=0; // pointers offset
    303309  unsigned int dest_length=0;
     
    305311  if(dest_length==0)
    306312    return NULL;
    307   unsigned char *ndata = new unsigned char[dest_length*sizeof(unsigned char)+sizeof(GamestateHeader)];
    308   unsigned char *dest = ndata + sizeof(GamestateHeader);
     313  uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+sizeof(GamestateHeader)];
     314  uint8_t *dest = ndata + sizeof(GamestateHeader);
    309315  while(of < GAMESTATE_HEADER(base->data_)->datasize && of < HEADER->datasize){
    310316    *(dest+of)=*(basep+of)^*(gs+of); // do the xor
     
    312318  }
    313319  if(GAMESTATE_HEADER(base->data_)->datasize!=HEADER->datasize){
    314     unsigned char n=0;
     320    uint8_t n=0;
    315321    if(GAMESTATE_HEADER(base->data_)->datasize < HEADER->datasize){
    316322      while(of<dest_length){
     
    335341 
    336342  Gamestate *gs = new Gamestate(*this);
    337   unsigned char *ndata = gs->data_ + sizeof(GamestateHeader);
     343  uint8_t *ndata = gs->data_ + sizeof(GamestateHeader);
    338344  synchronisableHeader *objectheader;
    339345  unsigned int objectOffset;
     
    344350    unsigned int objectsize = objectheader->size;
    345351    assert(it->second->objectID==objectheader->objectID);
    346     objectOffset=sizeof(unsigned int)+sizeof(bool); //skip the size and the availableDate variables in the objectheader
     352    objectOffset=sizeof(uint8_t)+sizeof(bool); //skip the size and the availableDate variables in the objectheader
    347353    if(!it->second->doSelection(HEADER->id)){
    348354      while(objectOffset<objectsize){
     
    370376  //preparations
    371377  std::map<unsigned int, Synchronisable *>::iterator it;
    372   unsigned char *origdata, *basedata, *destdata, *ndata;
     378  uint8_t *origdata, *basedata, *destdata, *ndata;
    373379  unsigned int objectOffset, streamOffset=0;    //data offset
    374380  unsigned int minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize;
     
    378384  origdata = GAMESTATE_START(this->data_);
    379385  basedata = GAMESTATE_START(base->data_);
    380   ndata = new unsigned char[HEADER->datasize + sizeof(GamestateHeader)];
     386  ndata = new uint8_t[HEADER->datasize + sizeof(GamestateHeader)];
    381387  destdata = ndata + sizeof(GamestateHeader);
    382388 
     
    390396    //copy and partially diff the object header
    391397    assert(sizeof(synchronisableHeader)==3*sizeof(unsigned int)+sizeof(bool));
    392     *(unsigned int*)destdata = *(unsigned int*)origdata; //size (do not diff)
    393     *(bool*)(destdata+sizeof(unsigned int)) = sendData;
     398    *(uint32_t*)destdata = *(uint32_t*)origdata; //size (do not diff)
     399    *(bool*)(destdata+sizeof(uint32_t)) = sendData;
    394400    if(sendData){
    395       *(unsigned int*)(destdata+sizeof(unsigned int)+sizeof(bool)) = *(unsigned int*)(basedata+sizeof(unsigned int)+sizeof(bool)) ^ *(unsigned int*)(origdata+sizeof(unsigned int)+sizeof(bool)); //objectid (diff it)
    396       *(unsigned int*)(destdata+2*sizeof(unsigned int)+sizeof(bool)) = *(unsigned int*)(basedata+2*sizeof(unsigned int)+sizeof(bool)) ^ *(unsigned int*)(origdata+2*sizeof(unsigned int)+sizeof(bool)); //classid (diff it)
     401      *(uint32_t*)(destdata+sizeof(uint32_t)+sizeof(bool)) = *(uint32_t*)(basedata+sizeof(uint32_t)+sizeof(bool)) ^ *(uint32_t*)(origdata+sizeof(uint32_t)+sizeof(bool)); //objectid (diff it)
     402      *(uint32_t*)(destdata+2*sizeof(uint32_t)+sizeof(bool)) = *(uint32_t*)(basedata+2*sizeof(uint32_t)+sizeof(bool)) ^ *(uint32_t*)(origdata+2*sizeof(uint32_t)+sizeof(bool)); //classid (diff it)
    397403    }else{
    398       *(unsigned int*)(destdata+sizeof(unsigned int)+sizeof(bool)) = 0;
    399       *(unsigned int*)(destdata+2*sizeof(unsigned int)+sizeof(bool)) = 0;
     404      *(uint32_t*)(destdata+sizeof(uint32_t)+sizeof(bool)) = 0;
     405      *(uint32_t*)(destdata+2*sizeof(uint32_t)+sizeof(bool)) = 0;
    400406    }
    401407    objectOffset=sizeof(synchronisableHeader);
     
    408414        *(destdata+objectOffset)=*(basedata+objectOffset)^*(origdata+objectOffset); // do the xor
    409415      else if(sendData)
    410         *(destdata+objectOffset)=((unsigned char)0)^*(origdata+objectOffset); // xor with 0 (basestream is too short)
     416        *(destdata+objectOffset)=((uint8_t)0)^*(origdata+objectOffset); // xor with 0 (basestream is too short)
    411417      else
    412418        *(destdata+objectOffset)=0; // set to 0 because this object should not be transfered
     
    438444  //preparations
    439445  std::map<unsigned int, Synchronisable *>::iterator it;
    440   unsigned char *origdata, *basedata, *destdata, *ndata;
     446  uint8_t *origdata, *basedata, *destdata, *ndata;
    441447  unsigned int objectOffset, streamOffset=0;    //data offset
    442448  unsigned int minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize;
     
    446452  origdata = GAMESTATE_START(this->data_);
    447453  basedata = GAMESTATE_START(base->data_);
    448   ndata = new unsigned char[HEADER->datasize + sizeof(GamestateHeader)];
     454  ndata = new uint8_t[HEADER->datasize + sizeof(GamestateHeader)];
    449455  destdata = ndata + sizeof(GamestateHeader);
    450456 
     
    502508  assert(!HEADER->compressed && !GAMESTATE_HEADER(base->data_)->compressed);
    503509  //unsigned char *basep = base->getGs()/*, *gs = getGs()*/;
    504   unsigned char *basep = GAMESTATE_START(base->data_);
    505   unsigned char *gs = GAMESTATE_START(this->data_);
     510  uint8_t *basep = GAMESTATE_START(base->data_);
     511  uint8_t *gs = GAMESTATE_START(this->data_);
    506512  unsigned int of=0; // pointers offset
    507513  unsigned int dest_length=0;
     
    509515  if(dest_length==0)
    510516    return NULL;
    511   unsigned char *ndata = new unsigned char[dest_length*sizeof(unsigned char)+sizeof(GamestateHeader)];
    512   unsigned char *dest = ndata + sizeof(GamestateHeader);
     517  uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+sizeof(GamestateHeader)];
     518  uint8_t *dest = ndata + sizeof(GamestateHeader);
    513519  while(of < GAMESTATE_HEADER(base->data_)->datasize && of < HEADER->datasize){
    514520    *(dest+of)=*(basep+of)^*(gs+of); // do the xor
     
    516522  }
    517523  if(GAMESTATE_HEADER(base->data_)->datasize!=HEADER->datasize){
    518     unsigned char n=0;
     524    uint8_t n=0;
    519525    if(GAMESTATE_HEADER(base->data_)->datasize < HEADER->datasize){
    520526      while(of < dest_length){
  • code/branches/network/src/network/packet/Gamestate.h

    r1827 r1901  
    4444struct GamestateHeader{
    4545  ENUM::Type packetType;
    46   int id; // id of the gamestate
    47   unsigned int compsize;
    48   unsigned int datasize;
    49   int base_id; // id of the base-gamestate diffed from
    50   bool diffed; // wheter diffed or not
    51   bool complete; // wheter it is a complete gamestate or only partial
    52   bool compressed;
     46  int32_t id; // id of the gamestate
     47  uint32_t compsize;
     48  uint32_t datasize;
     49  int32_t base_id; // id of the base-gamestate diffed from
     50  bool diffed:1; // wheter diffed or not
     51  bool complete:1; // wheter it is a complete gamestate or only partial
     52  bool compressed:1;
    5353#ifndef NDEBUG
    5454  uint32_t crc32;
     
    6262  public:
    6363    Gamestate();
    64     Gamestate(unsigned char *data, int clientID);
    65     Gamestate(unsigned char *data);
     64    Gamestate(uint8_t *data, unsigned int clientID);
     65    Gamestate(uint8_t *data);
    6666
    6767    ~Gamestate();
  • code/branches/network/src/network/packet/Packet.cc

    r1890 r1901  
    120120    case ENUM::Gamestate:
    121121    case ENUM::Welcome:
     122    case ENUM::DeleteObjects:
    122123      break;
    123124    default:
  • code/branches/network/src/orxonox/Settings.h

    r1892 r1901  
    5353        friend class GSGraphics;
    5454        friend class GSServer;
     55        friend class GSClient;
    5556        friend class GSDedicated;
    56         friend class GSClient;
    5757
    5858    public:
  • code/branches/network/src/orxonox/gamestates/GSServer.cc

    r1755 r1901  
    7878
    7979        // TODO: Remove and destroy console command
     80        Settings::_getInstance().bHasServer_ = false;
    8081
    8182        this->unloadLevel();
  • code/branches/network/src/orxonox/objects/Backlight.cc

    r1755 r1901  
    5353        this->traillength_ = 1;
    5454
    55         this->getNode()->setInheritScale(false);
     55        this->configure(maxspeed, brakingtime, scale);
     56    }
     57   
     58    bool Backlight::create(){
     59      if(!WorldEntity::create())
     60        return false;
     61     
     62      this->getNode()->setInheritScale(false);
    5663
    57         this->billboard_.setBillboardSet("Flares/backlightflare");
    58         this->attachObject(this->billboard_.getBillboardSet());
     64      this->billboard_.setBillboardSet("Flares/backlightflare");
     65      this->attachObject(this->billboard_.getBillboardSet());
    5966
    60         this->ribbonTrail_ = GraphicsEngine::getInstance().getLevelSceneManager()->createRibbonTrail(this->getName() + "RibbonTrail");
    61         this->ribbonTrailNode_ = GraphicsEngine::getInstance().getLevelSceneManager()->getRootSceneNode()->createChildSceneNode(this->getName() + "RibbonTrailNode");
    62         this->ribbonTrailNode_->attachObject(this->ribbonTrail_);
    63         this->ribbonTrail_->addNode(this->getNode());
     67      this->ribbonTrail_ = GraphicsEngine::getInstance().getLevelSceneManager()->createRibbonTrail(this->getName() + "RibbonTrail");
     68      this->ribbonTrailNode_ = GraphicsEngine::getInstance().getLevelSceneManager()->getRootSceneNode()->createChildSceneNode(this->getName() + "RibbonTrailNode");
     69      this->ribbonTrailNode_->attachObject(this->ribbonTrail_);
     70      this->ribbonTrail_->addNode(this->getNode());
    6471
    65         this->configure(maxspeed, brakingtime, scale);
    6672
    67         this->ribbonTrail_->setTrailLength(this->maxTraillength_);
    68         this->ribbonTrail_->setMaterialName("Trail/backlighttrail");
     73      this->ribbonTrail_->setTrailLength(this->maxTraillength_);
     74      this->ribbonTrail_->setMaterialName("Trail/backlighttrail");
    6975
    7076        //this->setTimeFactor(Orxonox::getInstance().getTimeFactor());
    71         this->setTimeFactor(1.0f);
     77      this->setTimeFactor(1.0f);
     78     
     79      this->ribbonTrail_->setMaxChainElements(this->maxTrailsegments_);
     80      this->ribbonTrail_->setTrailLength(this->traillength_ = 2 * this->maxTrailsegments_);
     81      this->ribbonTrail_->setInitialWidth(0, this->width_ * this->getScale());
     82      this->ribbonTrail_->setWidthChange(0, this->width_ * this->getScale() / this->maxLifeTime_ * Backlight::timeFactor_s);
     83      return true;
    7284    }
    7385
     
    100112    {
    101113        this->ribbonTrail_->setColourChange(0, ColourValue(0, 0, 0, this->maxTraillength_ / this->traillength_ / this->maxLifeTime_ * Backlight::timeFactor_s));
     114    }
     115   
     116   
     117    void Backlight::XMLPort(Element& xmlelement, XMLPort::Mode mode){
     118      SUPER(Backlight, XMLPort, xmlelement, mode);
     119     
     120      Backlight::create();
    102121    }
    103122
     
    136155        this->maxTraillength_ = this->maxLifeTime_ * maxspeed;
    137156        this->maxTrailsegments_ = (size_t)(this->maxTraillength_ / this->trailSegmentLength_);
    138         this->ribbonTrail_->setMaxChainElements(this->maxTrailsegments_);
    139         this->ribbonTrail_->setTrailLength(this->traillength_ = 2 * this->maxTrailsegments_);
    140157
    141158        this->brakefactor_ = this->maxLifeTime_ / brakingtime;
    142159
    143160        this->scale(scale);
    144         this->ribbonTrail_->setInitialWidth(0, this->width_ * scale);
    145         this->ribbonTrail_->setWidthChange(0, this->width_ * scale / this->maxLifeTime_ * Backlight::timeFactor_s);
    146161    }
    147162
  • code/branches/network/src/orxonox/objects/Backlight.h

    r1608 r1901  
    4545
    4646            void setConfigValues();
     47            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4748            virtual void tick(float dt);
    4849            virtual void changedVisibility();
     50            virtual bool create();
    4951
    5052            void setColour(const ColourValue& colour);
  • code/branches/network/src/orxonox/objects/Model.cc

    r1793 r1901  
    4646
    4747    /**
    48      *
     48     * @brief Constructor
    4949     */
    5050    Model::Model()
     
    5454    }
    5555
     56    /**
     57     * @brief Destructor
     58     */
    5659    Model::~Model()
    5760    {
  • code/branches/network/src/orxonox/objects/Projectile.cc

    r1834 r1901  
    4141#include "ParticleSpawner.h"
    4242#include "Model.h"
     43#include "Settings.h"
    4344
    4445namespace orxonox
     
    6465        }
    6566
    66         this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject)));
     67        if(!orxonox::Settings::isClient()) //only if not on client
     68          this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject)));
    6769    }
    6870
  • code/branches/network/src/orxonox/objects/SpaceShip.cc

    r1834 r1901  
    181181          this->setRadarObjectColour(this->getProjectileColour());
    182182      }
    183       assert(Model::create());
     183      Model::create();
    184184      this->init();
    185185      return true;
     
    255255
    256256            // START CREATING ADDITIONAL EFFECTS
    257             /*this->backlight_ = new Backlight(this->maxSpeed_, 0.8);
    258             this->attachObject(this->backlight_);
    259             this->backlight_->setPosition(-2.35, 0, 0.2);
    260             this->backlight_->setColour(this->getProjectileColour());
    261 
    262             this->smoke_ = new ParticleSpawner();
    263             this->smoke_->setParticle("Orxonox/smoke5", LODParticle::normal, 0, 0, 3);
    264             this->attachObject(this->smoke_);
    265 
    266             this->fire_ = new ParticleSpawner();
    267             this->fire_->setParticle("Orxonox/fire3", LODParticle::normal, 0, 0, 1);
    268             this->attachObject(this->fire_);
    269             */
     257            if(!network::Host::running()){
     258              this->backlight_ = new Backlight(this->maxSpeed_, 0.8);
     259              this->backlight_->create();
     260              this->attachObject(this->backlight_);
     261              this->backlight_->setPosition(-2.35, 0, 0.2);
     262              this->backlight_->setColour(this->getProjectileColour());
     263 
     264              this->smoke_ = new ParticleSpawner();
     265              this->smoke_->setParticle("Orxonox/smoke5", LODParticle::normal, 0, 0, 3);
     266              this->attachObject(this->smoke_);
     267 
     268              this->fire_ = new ParticleSpawner();
     269              this->fire_->setParticle("Orxonox/fire3", LODParticle::normal, 0, 0, 1);
     270              this->attachObject(this->fire_);
     271            }
     272           
    270273            // END CREATING ADDITIONAL EFFECTS
    271274
Note: See TracChangeset for help on using the changeset viewer.