Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 23, 2008, 11:09:55 PM (16 years ago)
Author:
rgrieder
Message:

Merged revision 2371 to bugger branch.

Location:
code/branches/bugger
Files:
3 deleted
13 edited
12 copied

Legend:

Unmodified
Added
Removed
  • code/branches/bugger

  • code/branches/bugger/src/network/CMakeLists.txt

    r2131 r2531  
    1111  PacketBuffer.cc
    1212  Server.cc
    13   Synchronisable.cc
     13  TrafficControl.cc
    1414  Host.cc
    1515)
    1616
    1717ADD_SOURCE_DIRECTORY(NETWORK_SRC_FILES packet)
     18ADD_SOURCE_DIRECTORY(NETWORK_SRC_FILES synchronisable)
     19
    1820
    1921IF(WIN32)
  • code/branches/bugger/src/network/Client.cc

    r2171 r2531  
    4343#include "Client.h"
    4444#include "Host.h"
    45 #include "Synchronisable.h"
     45#include "synchronisable/Synchronisable.h"
    4646#include "core/CoreIncludes.h"
    4747#include "packet/Packet.h"
  • code/branches/bugger/src/network/ClientInformation.cc

    r2171 r2531  
    4545namespace orxonox
    4646{
     47 
    4748
    4849  ClientInformation *ClientInformation::head_=0;
  • code/branches/bugger/src/network/ClientInformation.h

    r2171 r2531  
    4646#include <boost/thread/recursive_mutex.hpp>
    4747
     48
    4849// WATCH OUT: THE CLIENTINFORMATION LIST IS NOT THREADSAFE ANYMORE
    4950
    5051namespace orxonox
    5152{
    52   static const unsigned int GAMESTATEID_INITIAL = (unsigned int)-1;
    53   static const unsigned int CLIENTID_UNKNOWN = (unsigned int)-2;
    5453
    5554  /**
  • code/branches/bugger/src/network/ConnectionManager.cc

    r2171 r2531  
    5252#include "util/Sleep.h"
    5353#include "ClientInformation.h"
    54 #include "Synchronisable.h"
     54#include "synchronisable/Synchronisable.h"
    5555#include "packet/ClassID.h"
    5656
  • code/branches/bugger/src/network/GamestateClient.cc

    r2176 r2531  
    3535#include "core/BaseObject.h"
    3636#include "core/Iterator.h"
    37 #include "Synchronisable.h"
     37#include "synchronisable/Synchronisable.h"
     38#include "synchronisable/NetworkCallbackManager.h"
    3839#include "packet/Acknowledgement.h"
    3940
     
    7778    packet::Gamestate *processed = processGamestate(tempGamestate_);
    7879//    assert(processed);
     80   
     81    //now call the queued callbacks
     82    NetworkCallbackManager::callCallbacks();
     83   
    7984    if (!processed){
    8085      sendAck(0);
  • code/branches/bugger/src/network/GamestateManager.cc

    r2176 r2531  
    4949#include "core/BaseObject.h"
    5050#include "ClientInformation.h"
    51 #include "Synchronisable.h"
     51#include "synchronisable/Synchronisable.h"
     52#include "synchronisable/NetworkCallbackManager.h"
    5253#include "packet/Acknowledgement.h"
    5354
     
    8788    // now clear the queue
    8889    gamestateQueue.clear();
     90    //and call all queued callbacks
     91    NetworkCallbackManager::callCallbacks();
    8992    return true;
    9093  }
     
    135138    if(!reference)
    136139      return 0;
    137     gs = reference->doSelection(clientID);
    138 //     gs = new packet::Gamestate(*reference);
     140    gs = reference->doSelection(clientID, 10000);
    139141//     gs = new packet::Gamestate(*reference);
    140142    // save the (undiffed) gamestate in the clients gamestate map
  • code/branches/bugger/src/network/NetworkPrereqs.h

    r2171 r2531  
    5757
    5858//-----------------------------------------------------------------------
     59// Includes
     60//-----------------------------------------------------------------------
     61#include "util/Integers.h"
     62
     63
     64//-----------------------------------------------------------------------
    5965// Forward declarations
    6066//-----------------------------------------------------------------------
    6167namespace orxonox
    6268{
     69
     70// Constants definition
     71
     72  static const unsigned int GAMESTATEID_INITIAL = (unsigned int)-1;
     73  static const unsigned int CLIENTID_UNKNOWN = (unsigned int)-2;
     74  static const uint32_t OBJECTID_UNKNOWN = static_cast<uint32_t>(-1);
     75  static const unsigned int SCHED_PRIORITY_OFFSET = -5;
     76
     77 
     78
     79 
    6380  class Client;
    6481  class ClientConnection;
     
    7087  class GamestateManager;
    7188  class GamestateHandler;
     89  class NetworkCallbackBase;
     90  template <class T> class NetworkCallback;
     91  class NetworkCallbackManager;
    7292  class PacketBuffer;
    7393  class Server;
    7494  class ServerFrameListener;
    7595  class Synchronisable;
     96  class SynchronisableVariableBase;
     97  template <class T> class SynchronisableVariable;
     98  template <class T> class SynchronisableVariableBidirectional;
    7699  struct ClientList;
    77100  struct PacketEnvelope;
    78101  struct QueueItem;
    79102  struct syncData;
    80   struct synchronisableVariable;
     103  class obj;
     104  class objInfo;
    81105  namespace packet{
    82106    class Gamestate;
  • code/branches/bugger/src/network/packet/DeleteObjects.cc

    r2171 r2531  
    3030#include "DeleteObjects.h"
    3131#include <enet/enet.h>
    32 #include "network/Synchronisable.h"
     32#include "network/synchronisable/Synchronisable.h"
    3333#include "core/CoreIncludes.h"
    3434#include <assert.h>
  • code/branches/bugger/src/network/packet/Gamestate.cc

    r2450 r2531  
    2828
    2929#include "Gamestate.h"
    30 #include "network/ClientInformation.h"
    31 #include "network/GamestateHandler.h"
     30#include "../GamestateHandler.h"
     31#include "../synchronisable/Synchronisable.h"
     32#include "../TrafficControl.h"
    3233#include "core/Core.h"
    3334#include "core/CoreIncludes.h"
     
    4950
    5051#define PACKET_FLAG_GAMESTATE  ENET_PACKET_FLAG_RELIABLE
     52 
     53TrafficControl Gamestate::trafficControl_;
    5154
    5255Gamestate::Gamestate()
     
    7477bool Gamestate::collectData(int id, uint8_t mode)
    7578{
    76   unsigned int tempsize=0, currentsize=0;
     79  uint32_t tempsize=0, currentsize=0;
    7780  assert(data_==0);
    78   unsigned int size = calcGamestateSize(id, mode);
     81  uint32_t size = calcGamestateSize(id, mode);
    7982
    8083  COUT(4) << "G.ST.Man: producing gamestate with id: " << id << std::endl;
     
    110113
    111114    //if(it->doSelection(id))
    112     dataMap_[mem-data_]=(*it);  // save the mem location of the synchronisable data
     115    if(tempsize!=0)
     116      dataMap_.push_back( obj(it->getObjectID(), it->getCreatorID(), tempsize, mem-data_) );
     117//     dataMap_[mem-data_]=(*it);  // save the mem location of the synchronisable data
    113118    if(!it->getData(mem, id, mode))
    114119      return false; // mem pointer gets automatically increased because of call by reference
     
    150155    {
    151156      if (!Core::isMaster())
    152         Synchronisable::fabricate(mem, mode);
     157        s = Synchronisable::fabricate(mem, mode);
    153158      else
    154159        mem += objectheader->size;
     160      assert(s);
    155161    }
    156162    else
     
    170176}
    171177
    172 unsigned int Gamestate::getSize() const
     178uint32_t Gamestate::getSize() const
    173179{
    174180  assert(data_);
     
    255261  assert(HEADER->compressed);
    256262  COUT(4) << "GameStateClient: uncompressing gamestate. id: " << HEADER->id << ", baseid: " << HEADER->base_id << ", datasize: " << HEADER->datasize << ", compsize: " << HEADER->compsize << std::endl;
    257   unsigned int datasize = HEADER->datasize;
    258   unsigned int compsize = HEADER->compsize;
    259   unsigned int bufsize;
     263  uint32_t datasize = HEADER->datasize;
     264  uint32_t compsize = HEADER->compsize;
     265  uint32_t bufsize;
    260266//  assert(compsize<=datasize);
    261267  bufsize = datasize;
     
    306312  //unsigned char *basep = base->getGs()/*, *gs = getGs()*/;
    307313  uint8_t *basep = GAMESTATE_START(base->data_), *gs = GAMESTATE_START(this->data_);
    308   unsigned int of=0; // pointers offset
    309   unsigned int dest_length=0;
     314  uint32_t of=0; // pointers offset
     315  uint32_t dest_length=0;
    310316  dest_length=HEADER->datasize;
    311317  if(dest_length==0)
     
    336342}
    337343
    338 Gamestate* Gamestate::doSelection(unsigned int clientID){
     344Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){
    339345  assert(data_);
    340   std::map<unsigned int, Synchronisable *>::iterator it;
     346  std::list<obj>::iterator it;
    341347
    342348  // allocate memory for new data
     
    345351  Gamestate *gs = new Gamestate(gdata);
    346352  uint8_t *newdata = gdata + sizeof(GamestateHeader);
    347   uint8_t *origdata = GAMESTATE_START(data_);
     353//   uint8_t *origdata = GAMESTATE_START(data_);
    348354
    349355  //copy the GamestateHeader
     
    351357
    352358  synchronisableHeader *oldobjectheader, *newobjectheader;
    353   unsigned int objectOffset;
    354 
     359  uint32_t objectOffset;
     360  unsigned int objectsize, destsize=0;
     361  Synchronisable *object;
     362
     363  //call TrafficControl
     364  trafficControl_.processObjectList( clientID, HEADER->id, &dataMap_ );
     365 
    355366  //copy in the zeros
    356367  for(it=dataMap_.begin(); it!=dataMap_.end(); it++){
    357     if(it->second->getSize(HEADER->id)==0)
     368    if((*it).objSize==0)
    358369      continue;
    359     oldobjectheader = (synchronisableHeader*)origdata;
     370    oldobjectheader = (synchronisableHeader*)(data_ + (*it).objDataOffset);
    360371    newobjectheader = (synchronisableHeader*)newdata;
    361     unsigned int objectsize = oldobjectheader->size;
    362     assert(it->second->objectID==oldobjectheader->objectID);
     372    object = Synchronisable::getSynchronisable( (*it).objID );
     373    assert(object->objectID == oldobjectheader->objectID);
     374    objectsize = oldobjectheader->size;
    363375    *newobjectheader = *oldobjectheader;
    364376    objectOffset=sizeof(synchronisableHeader); //skip the size and the availableData variables in the objectheader
    365     if(it->second->doSelection(HEADER->id)){
     377    if ( /*object->doSelection(HEADER->id)*/true ){
    366378      assert(newobjectheader->dataAvailable==true);
    367       memcpy(newdata+objectOffset, origdata+objectOffset, objectsize-objectOffset);
     379      memcpy(newdata+objectOffset, data_ + (*it).objDataOffset + objectOffset, objectsize-objectOffset);
    368380    }else{
    369381      newobjectheader->dataAvailable=false;
     
    372384    }
    373385    newdata += objectsize;
    374     origdata += objectsize;
    375   }
     386    destsize += objectsize;
     387//     origdata += objectsize;
     388  }
     389  ((GamestateHeader*)gdata)->datasize = destsize;
     390  assert(destsize!=0);
    376391  return gs;
    377392}
     
    388403
    389404  //preparations
    390   std::map<unsigned int, Synchronisable *>::iterator it;
     405  std::list<obj>::iterator it;
    391406  uint8_t *origdata, *basedata, *destdata, *ndata;
    392   unsigned int objectOffset, streamOffset=0;    //data offset
    393   unsigned int minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize;
     407  uint32_t objectOffset, streamOffset=0;    //data offset
     408  uint32_t minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize;
    394409  synchronisableHeader *origheader;
    395410  synchronisableHeader *destheader;
     411  Synchronisable *object;
    396412
    397413  origdata = GAMESTATE_START(this->data_);
     
    403419  for(it=dataMap_.begin(); it!=dataMap_.end(); it++){
    404420    assert(streamOffset<HEADER->datasize);
    405     bool sendData = it->second->doSelection(HEADER->id);
    406421    origheader = (synchronisableHeader *)(origdata+streamOffset);
    407422    destheader = (synchronisableHeader *)(destdata+streamOffset);
     423    object = Synchronisable::getSynchronisable(origheader->objectID);
     424    bool sendData = object->doSelection(HEADER->id);
    408425
    409426    //copy and partially diff the object header
    410     assert(sizeof(synchronisableHeader)==3*sizeof(unsigned int)+sizeof(bool));
     427    assert(sizeof(synchronisableHeader)==3*sizeof(uint32_t)+sizeof(bool));
    411428    *(uint32_t*)destdata = *(uint32_t*)origdata; //size (do not diff)
    412429    *(bool*)(destdata+sizeof(uint32_t)) = sendData;
     
    456473
    457474  //preparations
    458   std::map<unsigned int, Synchronisable *>::iterator it;
     475  std::list<obj>::iterator it;
    459476  uint8_t *origdata, *basedata, *destdata, *ndata;
    460   unsigned int objectOffset, streamOffset=0;    //data offset
    461   unsigned int minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize;
     477  uint32_t objectOffset, streamOffset=0;    //data offset
     478  uint32_t minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize;
    462479  synchronisableHeader *origheader;
    463480  synchronisableHeader *destheader;
     481  Synchronisable *object;
    464482
    465483  origdata = GAMESTATE_START(this->data_);
     
    473491    origheader = (synchronisableHeader *)(origdata+streamOffset);
    474492    destheader = (synchronisableHeader *)(destdata+streamOffset);
     493    object = Synchronisable::getSynchronisable( origheader->objectID );
    475494    bool sendData;
    476495
    477496    //copy and partially diff the object header
    478     assert(sizeof(synchronisableHeader)==3*sizeof(unsigned int)+sizeof(bool));
    479     *(unsigned int*)destdata = *(unsigned int*)origdata; //size (do not diff)
    480     *(bool*)(destdata+sizeof(unsigned int)) = *(bool*)(origdata+sizeof(unsigned int));
    481     sendData = *(bool*)(origdata+sizeof(unsigned int));
     497    assert(sizeof(synchronisableHeader)==3*sizeof(uint32_t)+sizeof(bool));
     498    *(uint32_t*)destdata = *(uint32_t*)origdata; //size (do not diff)
     499    *(bool*)(destdata+sizeof(uint32_t)) = *(bool*)(origdata+sizeof(uint32_t));
     500    sendData = *(bool*)(origdata+sizeof(uint32_t));
    482501    if(sendData){
    483       *(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)
    484       *(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)
     502      *(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)
     503      *(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)
    485504    }else{
    486       *(unsigned int*)(destdata+sizeof(unsigned int)+sizeof(bool)) = 0;
    487       *(unsigned int*)(destdata+2*sizeof(unsigned int)+sizeof(bool)) = 0;
     505      *(uint32_t*)(destdata+sizeof(uint32_t)+sizeof(bool)) = 0;
     506      *(uint32_t*)(destdata+2*sizeof(uint32_t)+sizeof(bool)) = 0;
    488507    }
    489508    objectOffset=sizeof(synchronisableHeader);
     
    523542  uint8_t *basep = GAMESTATE_START(base->data_);
    524543  uint8_t *gs = GAMESTATE_START(this->data_);
    525   unsigned int of=0; // pointers offset
    526   unsigned int dest_length=0;
     544  uint32_t of=0; // pointers offset
     545  uint32_t dest_length=0;
    527546  dest_length=HEADER->datasize;
    528547  if(dest_length==0)
     
    554573
    555574
    556 unsigned int Gamestate::calcGamestateSize(unsigned int id, uint8_t mode)
    557 {
    558   unsigned int size=0;
     575uint32_t Gamestate::calcGamestateSize(int32_t id, uint8_t mode)
     576{
     577  uint32_t size=0;
    559578    // get the start of the Synchronisable list
    560579  ObjectList<Synchronisable>::iterator it;
  • code/branches/bugger/src/network/packet/Gamestate.h

    r2171 r2531  
    3131#define NETWORK_PACKETGAMESTATE_H
    3232
    33 #include "../NetworkPrereqs.h"
     33#include "network/NetworkPrereqs.h"
    3434
    3535#include "Packet.h"
    36 #include "network/Synchronisable.h"
     36#include "network/TrafficControl.h"
     37#include "core/CoreIncludes.h"
    3738#include <map>
     39#include <list>
    3840#ifndef NDEBUG
    3941#include "util/CRC32.h"
     
    7981    Gamestate *undiff(Gamestate *base);
    8082    Gamestate* intelligentUnDiff(Gamestate *base);
    81     Gamestate* doSelection(unsigned int clientID);
     83    Gamestate* doSelection(unsigned int clientID, unsigned int targetSize);
    8284    bool compressData();
    8385    bool decompressData();
     
    8587    // Packet functions
    8688  private:
    87     virtual unsigned int getSize() const;
     89    virtual uint32_t getSize() const;
    8890    virtual bool process();
    8991
    9092    bool operator ==(packet::Gamestate gs);
    9193  private:
    92     unsigned int calcGamestateSize(unsigned int id, uint8_t mode=0x0);
     94    uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0);
    9395    void removeObject(ObjectListIterator<Synchronisable> &it);
    94     std::map<unsigned int, Synchronisable*> dataMap_;
     96    std::list<obj> dataMap_;
     97    static TrafficControl trafficControl_;
    9598};
    9699
  • code/branches/bugger/src/network/packet/Welcome.cc

    r2171 r2531  
    3232#include "Welcome.h"
    3333#include "network/Host.h"
    34 #include "network/Synchronisable.h"
     34#include "network/synchronisable/Synchronisable.h"
    3535#include "core/CoreIncludes.h"
    3636#include <assert.h>
     
    4343#define _CLIENTID             _PACKETID + sizeof(ENUM::Type)
    4444#define _SHIPID               _CLIENTID + sizeof(uint32_t)
     45#define _ENDIANTEST           _SHIPID + sizeof(uint32_t)
    4546 
    4647  Welcome::Welcome( unsigned int clientID, unsigned int shipID )
     
    5253  assert(data_);
    5354  *(packet::ENUM::Type *)(data_ + _PACKETID ) = packet::ENUM::Welcome;
    54   *(uint32_t *)&data_[ _CLIENTID ] = clientID;
    55   *(uint32_t *)&data_[ _SHIPID ] = shipID;
     55  *(uint32_t *)(data_ + _CLIENTID ) = clientID;
     56  *(uint32_t *)(data_ + _SHIPID ) = shipID;
     57  *(uint32_t *)(data_ + _ENDIANTEST ) = 0xFEDC4321;
    5658}
    5759
     
    7072
    7173unsigned int Welcome::getSize() const{
    72   return sizeof(packet::ENUM::Type) + 2*sizeof(uint32_t);
     74  return sizeof(packet::ENUM::Type) + 3*sizeof(uint32_t);
    7375}
    7476
     
    7779  clientID = *(uint32_t *)&data_[ _CLIENTID ];
    7880  shipID = *(uint32_t *)&data_[ _SHIPID ];
     81  assert(*(uint32_t *)(data_ + _ENDIANTEST ) == 0xFEDC4321);
    7982  Host::setClientID(clientID);
    8083  Host::setShipID(shipID);
  • code/branches/bugger/src/network/synchronisable/Synchronisable.cc

    r2371 r2531  
    7979
    8080
    81 #ifndef NDEBUG
    82     ObjectList<Synchronisable>::iterator it;
    83     for(it = ObjectList<Synchronisable>::begin(); it!=ObjectList<Synchronisable>::end(); ++it){
    84       if( it->getObjectID()==this->objectID )
    85         assert(*it==this || (it->objectID==OBJECTID_UNKNOWN && it->objectMode_==0x0));
    86     }
    87 #endif
     81//#ifndef NDEBUG
     82//    ObjectList<Synchronisable>::iterator it;
     83//    for(it = ObjectList<Synchronisable>::begin(); it!=ObjectList<Synchronisable>::end(); ++it){
     84//        if(!(*it==this || (it->objectID==OBJECTID_UNKNOWN && it->objectMode_==0x0)))
     85//        {
     86//            COUT(1) << "Assertion failed: *it==this || (it->objectID==OBJECTID_UNKNOWN && it->objectMode_==0x0)" << std::endl;
     87//            COUT(1) << "Possible reason for this error: Client created a synchronized object without the Server's approval." << std::endl;
     88//            abort();
     89//        }
     90//    }
     91//#endif
    8892
    8993    this->creatorID = OBJECTID_UNKNOWN;
     
    159163
    160164    Identifier* id = ClassByID(header->classID);
     165    if (!id)
     166    {
     167        COUT(1) << "Assertion failed: id" << std::endl;
     168        COUT(1) << "Possible reason for this error: Client received a synchronizable object whose class has no factory." << std::endl;
     169        abort();
     170    }
    161171    assert(id);
    162172    BaseObject* creator = 0;
  • code/branches/bugger/src/network/synchronisable/Synchronisable.h

    r2371 r2531  
    9090    static uint32_t popDeletedObject(){ uint32_t i = deletedObjects_.front(); deletedObjects_.pop(); return i; }
    9191
    92     inline uint32_t getObjectID(){return objectID;}
    93     inline unsigned int getCreatorID(){return creatorID;}
    94     inline uint32_t getClassID(){return classID;}
    95     inline unsigned int getPriority(){ return objectFrequency_;}
     92    inline uint32_t getObjectID() const {return objectID;}
     93    inline unsigned int getCreatorID() const {return creatorID;}
     94    inline uint32_t getClassID() const {return classID;}
     95    inline unsigned int getPriority() const { return objectFrequency_;}
    9696
    9797  protected:
Note: See TracChangeset for help on using the changeset viewer.