Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 14, 2009, 10:17:35 PM (16 years ago)
Author:
rgrieder
Message:

Merged presentation branch back to trunk.

Location:
code/trunk
Files:
1 edited
10 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/network/synchronisable/NetworkCallback.h

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • code/trunk/src/network/synchronisable/Synchronisable.cc

    r2653 r2662  
    2828 */
    2929
    30 //
    31 // C++ Implementation: synchronisable
    32 //
    33 // Description:
    34 //
    35 //
    36 // Author:  Dumeni, Oliver Scheuss, (C) 2007
    37 //
    38 // Copyright: See COPYING file that comes with this distribution
    39 //
    4030
    4131#include "Synchronisable.h"
     
    155145  Synchronisable *Synchronisable::fabricate(uint8_t*& mem, uint8_t mode)
    156146  {
    157     synchronisableHeader *header = (synchronisableHeader *)mem;
    158 
    159     if(!header->dataAvailable)
    160     {
    161       mem += header->size;
     147    SynchronisableHeader header(mem);
     148
     149    if(!header.isDataAvailable())
     150    {
     151      mem += header.getDataSize();
    162152      return 0;
    163153    }
    164154
    165     COUT(4) << "fabricating object with id: " << header->objectID << std::endl;
    166 
    167     Identifier* id = ClassByID(header->classID);
     155    COUT(4) << "fabricating object with id: " << header.getObjectID() << std::endl;
     156
     157    Identifier* id = ClassByID(header.getClassID());
    168158    if (!id)
    169159    {
     
    174164    assert(id);
    175165    BaseObject* creator = 0;
    176     if (header->creatorID != OBJECTID_UNKNOWN)
    177     {
    178       Synchronisable* synchronisable_creator = Synchronisable::getSynchronisable(header->creatorID);
     166    if (header.getCreatorID() != OBJECTID_UNKNOWN)
     167    {
     168      Synchronisable* synchronisable_creator = Synchronisable::getSynchronisable(header.getCreatorID());
    179169      if (!synchronisable_creator)
    180170      {
    181         mem += header->size; //.TODO: this suckz.... remove size from header
    182 //         assert(0); // TODO: uncomment this if we have a clean objecthierarchy (with destruction of children of objects) ^^
     171        mem += header.getDataSize(); //.TODO: this suckz.... remove size from header
     172        assert(0); // TODO: uncomment this if we have a clean objecthierarchy (with destruction of children of objects) ^^
    183173        return 0;
    184174      }
     
    186176        creator = dynamic_cast<BaseObject*>(synchronisable_creator);
    187177    }
    188     assert(getSynchronisable(header->objectID)==0);   //make sure no object with this id exists
     178    assert(getSynchronisable(header.getObjectID())==0);   //make sure no object with this id exists
    189179    BaseObject *bo = id->fabricate(creator);
    190180    assert(bo);
    191181    Synchronisable *no = dynamic_cast<Synchronisable *>(bo);
    192182    assert(no);
    193     no->objectID=header->objectID;
    194     no->creatorID=header->creatorID; //TODO: remove this
    195     no->classID=header->classID;
     183    no->objectID=header.getObjectID();
     184    no->creatorID=header.getCreatorID(); //TODO: remove this
     185    no->classID=header.getClassID();
    196186    COUT(4) << "fabricate objectID: " << no->objectID << " classID: " << no->classID << std::endl;
    197187          // update data and create object/entity...
     
    329319
    330320    // start copy header
    331     synchronisableHeader *header = (synchronisableHeader *)mem;
    332     header->size = size;
    333     header->objectID = this->objectID;
    334     header->creatorID = this->creatorID;
    335     header->classID = this->classID;
    336     header->dataAvailable = true;
    337     tempsize += sizeof(synchronisableHeader);
    338     mem += sizeof(synchronisableHeader);
     321    SynchronisableHeader header(mem);
     322    header.setDataSize( size );
     323    header.setObjectID( this->objectID );
     324    header.setCreatorID( this->creatorID );
     325    header.setClassID( this->classID );
     326    header.setDataAvailable( true );
     327    tempsize += SynchronisableHeader::getSize();
     328    mem += SynchronisableHeader::getSize();
    339329    // end copy header
    340330
     
    371361    uint8_t* data=mem;
    372362    // start extract header
    373     synchronisableHeader *syncHeader = (synchronisableHeader *)mem;
    374     assert(syncHeader->objectID==this->objectID);
    375     assert(syncHeader->creatorID==this->creatorID);
    376     assert(this->classID==syncHeader->classID); //TODO: fix this!!! maybe a problem with the identifier ?
    377     if(syncHeader->dataAvailable==false){
    378       mem += syncHeader->size;
     363    SynchronisableHeader syncHeader(mem);
     364    assert(syncHeader.getObjectID()==this->objectID);
     365    assert(syncHeader.getCreatorID()==this->creatorID);
     366    assert(syncHeader.getClassID()==this->classID);
     367    if(syncHeader.isDataAvailable()==false){
     368      mem += syncHeader.getDataSize();
    379369      return true;
    380370    }
    381371
    382     mem += sizeof(synchronisableHeader);
     372    mem += SynchronisableHeader::getSize();
    383373    // stop extract header
    384374
    385     COUT(5) << "Synchronisable: objectID " << syncHeader->objectID << ", classID " << syncHeader->classID << " size: " << syncHeader->size << " synchronising data" << std::endl;
    386     for(i=syncList.begin(); i!=syncList.end() && mem <= data+syncHeader->size; i++)
    387     {
     375    //COUT(5) << "Synchronisable: objectID " << syncHeader.getObjectID() << ", classID " << syncHeader.getClassID() << " size: " << syncHeader.getDataSize() << " synchronising data" << std::endl;
     376    for(i=syncList.begin(); i!=syncList.end(); i++)
     377    {
     378      assert( mem <= data+syncHeader.getDataSize() ); // always make sure we don't exceed the datasize in our stream
    388379      (*i)->putData( mem, mode, forceCallback );
    389380    }
    390     assert(mem == data+syncHeader->size);
     381    assert(mem == data+syncHeader.getDataSize());
    391382    return true;
    392383  }
     
    399390  */
    400391  uint32_t Synchronisable::getSize(int32_t id, uint8_t mode){
    401     int tsize=sizeof(synchronisableHeader);
     392    int tsize=SynchronisableHeader::getSize();
    402393    if(mode==0x0)
    403394      mode=state_;
     
    428419  bool Synchronisable::isMyData(uint8_t* mem)
    429420  {
    430     synchronisableHeader *header = (synchronisableHeader *)mem;
    431     assert(header->objectID==this->objectID);
    432     return header->dataAvailable;
     421    SynchronisableHeader header(mem);
     422    assert(header.getObjectID()==this->objectID);
     423    return header.isDataAvailable();
    433424  }
    434425
  • code/trunk/src/network/synchronisable/Synchronisable.h

    r2653 r2662  
    7272  }
    7373
    74   struct _NetworkExport synchronisableHeader{
    75     uint32_t size:31;
    76     bool dataAvailable:1;
    77     uint32_t objectID;
    78     uint32_t creatorID;
    79     uint32_t classID;
     74  /**
     75   * @brief: stores information about a Synchronisable
     76   *
     77   * This class stores the information about a Synchronisable (objectID, classID, creatorID, dataSize)
     78   * in an emulated bitset.
     79   * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream
     80   * Bit 32 is a bool and defines whether the data is actually stored or is just filled up with 0
     81   * Byte 5 to 8: objectID
     82   * Byte 9 to 12: classID
     83   * Byte 13 to 16: creatorID
     84   */
     85  class _NetworkExport SynchronisableHeader{
     86    private:
     87      uint8_t *data_;
     88    public:
     89      SynchronisableHeader(uint8_t* data)
     90        { data_ = data; }
     91      inline static uint32_t getSize()
     92        { return 16; }
     93      inline uint32_t getDataSize() const
     94        { return (*(uint32_t*)data_) & 0x7FFFFFFF; } //only use the first 31 bits
     95      inline void setDataSize(uint32_t size)
     96        { *(uint32_t*)(data_) = (size & 0x7FFFFFFF) | (*(uint32_t*)(data_) & 0x80000000 ); }
     97      inline bool isDataAvailable() const
     98        { return ( (*(uint32_t*)data_) & 0x80000000 ) == 0x80000000; }
     99      inline void setDataAvailable( bool b)
     100        { *(uint32_t*)(data_) = (b << 31) | (*(uint32_t*)(data_) & 0x7FFFFFFF ); }
     101      inline uint32_t getObjectID() const
     102        { return *(uint32_t*)(data_+4); }
     103      inline void setObjectID(uint32_t objectID)
     104        { *(uint32_t*)(data_+4) = objectID; }
     105      inline uint32_t getClassID() const
     106        { return *(uint32_t*)(data_+8); }
     107      inline void setClassID(uint32_t classID)
     108        { *(uint32_t*)(data_+8) = classID; }
     109      inline uint32_t getCreatorID() const
     110        { return *(uint32_t*)(data_+12); }
     111      inline void setCreatorID(uint32_t creatorID)
     112        { *(uint32_t*)(data_+12) = creatorID; }
     113      inline void operator=(SynchronisableHeader& h)
     114        { memcpy(data_, h.data_, getSize()); }
    80115  };
    81116
     
    83118  /**
    84119  * This class is the base class of all the Objects in the universe that need to be synchronised over the network
    85    * Every class, that inherits from this class has to link the DATA THAT NEEDS TO BE SYNCHRONISED into the linked list.
     120  * Every class, that inherits from this class has to link the DATA THAT NEEDS TO BE SYNCHRONISED into the linked list.
    86121  * @author Oliver Scheuss
    87122  */
Note: See TracChangeset for help on using the changeset viewer.