Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 26, 2009, 9:20:57 PM (15 years ago)
Author:
landauf
Message:

merged netp3 branch back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

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

    r3068 r3084  
    3333
    3434#include <list>
     35#include <vector>
    3536#include <map>
    3637#include <queue>
    3738#include <cassert>
     39#include <string>
    3840#include "util/Math.h"
    3941#include "util/mbool.h"
     
    120122  public:
    121123    friend class packet::Gamestate;
    122 //     friend class Server;
    123124    virtual ~Synchronisable();
    124125
     
    139140    Synchronisable(BaseObject* creator);
    140141    template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false);
    141     template <class T> void unregisterVariable(T& var);
     142    //template <class T> void unregisterVariable(T& var);
    142143    void setObjectMode(uint8_t mode);
    143144    void setPriority(unsigned int freq){ objectFrequency_ = freq; }
     
    145146
    146147  private:
    147     bool getData(uint8_t*& men, int32_t id, uint8_t mode=0x0);
     148    uint32_t getData(uint8_t*& men, int32_t id, uint8_t mode=0x0);
    148149    uint32_t getSize(int32_t id, uint8_t mode=0x0);
    149150    bool updateData(uint8_t*& mem, uint8_t mode=0x0, bool forceCallback=false);
     
    155156    uint32_t classID;
    156157
    157     std::list<SynchronisableVariableBase*> syncList;
     158    std::vector<SynchronisableVariableBase*> syncList;
     159    std::vector<SynchronisableVariableBase*> stringList;
     160    uint32_t dataSize_; //size of all variables except strings
    158161    static uint8_t state_; // detemines wheter we are server (default) or client
    159162    bool backsync_; // if true the variables with mode > 1 will be synchronised to server (client -> server)
     
    164167  };
    165168
    166   template <class T> void Synchronisable::registerVariable(T& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
    167   {
    168     if (bidirectional)
    169       syncList.push_back(new SynchronisableVariableBidirectional<const T>(variable, mode, cb));
    170     else
    171       syncList.push_back(new SynchronisableVariable<const T>(variable, mode, cb));
    172   }
    173 
    174   template <class T> void Synchronisable::unregisterVariable(T& var){
    175     std::list<SynchronisableVariableBase*>::iterator it = syncList.begin();
    176     while(it!=syncList.end()){
    177       if( ((*it)->getReference()) == &var ){
    178         delete (*it);
    179         syncList.erase(it);
    180         return;
    181       }
    182       else
    183         it++;
    184     }
    185     bool unregistered_nonexistent_variable = false;
    186     assert(unregistered_nonexistent_variable); //if we reach this point something went wrong:
    187     // the variable has not been registered before
    188   }
    189 
    190169  // ================= Specialisation declarations
     170 
     171//   template <> _NetworkExport void Synchronisable::registerVariable( const std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional);
     172  template <> _NetworkExport void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional);
    191173  template <> _NetworkExport void Synchronisable::registerVariable( const ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    192174  template <> _NetworkExport void Synchronisable::registerVariable( ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
     
    200182  template <> _NetworkExport void Synchronisable::registerVariable( const Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    201183  template <> _NetworkExport void Synchronisable::registerVariable( Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
     184 
     185  template <class T> void Synchronisable::registerVariable(T& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
     186  {
     187    if (bidirectional)
     188    {
     189      syncList.push_back(new SynchronisableVariableBidirectional<const T>(variable, mode, cb));
     190      this->dataSize_ += syncList.back()->getSize(state_);
     191    }
     192    else
     193    {
     194      syncList.push_back(new SynchronisableVariable<const T>(variable, mode, cb));
     195      if ( this->state_ == mode )
     196        this->dataSize_ += syncList.back()->getSize(state_);
     197    }
     198  }
     199 
     200
     201
     202//   template <class T> void Synchronisable::unregisterVariable(T& var){
     203//     std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin();
     204//     while(it!=syncList.end()){
     205//       if( ((*it)->getReference()) == &var ){
     206//         delete (*it);
     207//         syncList.erase(it);
     208//         return;
     209//       }
     210//       else
     211//         it++;
     212//     }
     213//     bool unregistered_nonexistent_variable = false;
     214//     assert(unregistered_nonexistent_variable); //if we reach this point something went wrong:
     215//     // the variable has not been registered before
     216//   }
     217
     218 
    202219}
    203220
Note: See TracChangeset for help on using the changeset viewer.