Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 12, 2008, 7:40:47 PM (16 years ago)
Author:
scheusso
Message:

merged network branch back to trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/network/Synchronisable.h

    r1841 r1907  
    3333
    3434#include <list>
     35#include <map>
     36#include <queue>
    3537#include "core/OrxonoxClass.h"
    3638#include "core/XMLIncludes.h"
    3739#include "NetworkCallback.h"
    3840
     41#define REGISTERDATA(varname) registerVar(&varname, sizeof(varname), network::DATA)
     42#define REGISTERDATA_WITHDIR(varname, mode) registerVar(&varname, sizeof(varname), network::DATA, mode)
     43#define REGISTERSTRING(stringname) registerVar(&stringname, stringname.length()+1, network::STRING)
     44#define REGISTERSTRING_WITHDIR(stringname, mode) registerVar(&stringname, stringname.length()+1, network::STRING, mode)
     45
     46//TODO: this is only a very ugly hack ...
     47namespace orxonox{
     48class SpaceShip;
     49}
     50
    3951namespace network
    4052{
     53  namespace direction{
     54    enum syncdirection{
     55      toclient=0x1,
     56      toserver=0x2,
     57      bidirectional=0x3
     58    };
     59  }
     60 
     61  namespace syncmode{
     62    enum mode{
     63      one=0,
     64      always=1
     65    };
     66  }
     67 
    4168  enum variableType{
    4269    DATA,
     
    4572
    4673  struct synchronisableHeader{
    47     unsigned int size;
    48     unsigned int objectID;
    49     unsigned int classID;
     74    uint32_t size:31;
     75    bool dataAvailable:1;
     76    uint32_t objectID;
     77    uint32_t classID;
    5078  };
    5179
     
    5886  }SYNCVAR;
    5987
    60 
    6188  /**
    6289  * This class is the base class of all the Objects in the universe that need to be synchronised over the network
    63    * Every class, t
    64   int mode;hat inherits from this class has to link the DATA THAT NEEDS TO BE SYNCHRONISED into the linked list. Additionally it also has to provide a Constructor, that takes exactly the variables in this linked list.
     90   * Every class, that inherits from this class has to link the DATA THAT NEEDS TO BE SYNCHRONISED into the linked list.
    6591  * @author Oliver Scheuss
    6692  */
    6793  class _NetworkExport Synchronisable : virtual public orxonox::OrxonoxClass{
    6894  public:
     95    friend class packet::Gamestate;
     96    friend class GamestateClient;
     97    friend class Server;
     98    friend class orxonox::SpaceShip;
     99    virtual ~Synchronisable();
     100
    69101   
    70     virtual ~Synchronisable();
    71     unsigned int objectID;
    72     unsigned int classID;
    73 
    74     void registerVar(void *var, int size, variableType t, int mode=1, NetworkCallbackBase *cb=0);
    75     bool getData(unsigned char*& men, unsigned int id, int mode=0x0);
    76     int getSize2(unsigned int id, int mode=0x0);
    77     bool updateData(unsigned char*& mem, int mode=0x0);
    78     bool isMyData(unsigned char* mem);
    79     void setObjectMode(int mode);
    80     void setObjectFrequency(unsigned int freq){ objectFrequency_ = freq; }
    81    
    82     virtual void registerAllVariables()=0;
    83102    virtual bool create();
    84103    static void setClient(bool b);
    85104   
    86     static bool fabricate(unsigned char*& mem, int mode=0x0);
     105    static Synchronisable *fabricate(uint8_t*& mem, int mode=0x0);
     106    static bool deleteObject(unsigned int objectID);
     107    static Synchronisable *getSynchronisable(unsigned int objectID);
     108    static unsigned int getNumberOfDeletedObject(){ return deletedObjects_.size(); }
     109    static unsigned int popDeletedObject(){ unsigned int i = deletedObjects_.front(); deletedObjects_.pop(); return i; }
     110   
     111    inline unsigned int getObjectID(){return objectID;}
     112    inline unsigned int getClassID(){return classID;}
    87113  protected:
    88114    Synchronisable();
     115    void registerVar(void *var, int size, variableType t, int mode=1, NetworkCallbackBase *cb=0);
     116    void setObjectMode(int mode);
     117    void setObjectFrequency(unsigned int freq){ objectFrequency_ = freq; }
     118    virtual void registerAllVariables()=0;
     119   
     120   
    89121  private:
    90     int getSize(unsigned int id, int mode=0x0);
     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);
     126    bool doSelection(unsigned int id);
    91127    bool isMyTick(unsigned int id);
     128   
     129    unsigned int objectID;
     130    unsigned int classID;
     131   
    92132    std::list<synchronisableVariable *> *syncList;
    93     int datasize;
    94133    static int state_; // detemines wheter we are server (default) or client
    95134    bool backsync_; // if true the variables with mode > 1 will be synchronised to server (client -> server)
    96135    unsigned int objectFrequency_;
    97136    int objectMode_;
     137    static std::map<unsigned int, Synchronisable *> objectMap_;
     138    static std::queue<unsigned int> deletedObjects_;
    98139  };
    99140}
Note: See TracChangeset for help on using the changeset viewer.