Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 23, 2009, 5:00:54 PM (16 years ago)
Author:
scheusso
Message:

merge old netp branch to netp2 (still because of multiplayer pong…)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/netp2/src/network/synchronisable/Synchronisable.h

    r2826 r2836  
    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"
     
    139141    Synchronisable(BaseObject* creator);
    140142    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);
     143    //template <class T> void unregisterVariable(T& var);
    142144    void setObjectMode(uint8_t mode);
    143145    void setPriority(unsigned int freq){ objectFrequency_ = freq; }
     
    145147
    146148  private:
    147     bool getData(uint8_t*& men, int32_t id, uint8_t mode=0x0);
     149    uint32_t getData(uint8_t*& men, int32_t id, uint8_t mode=0x0);
    148150    uint32_t getSize(int32_t id, uint8_t mode=0x0);
    149151    bool updateData(uint8_t*& mem, uint8_t mode=0x0, bool forceCallback=false);
     
    155157    uint32_t classID;
    156158
    157     std::list<SynchronisableVariableBase*> syncList;
     159    std::vector<SynchronisableVariableBase*> syncList;
     160    std::vector<SynchronisableVariableBase*> stringList;
     161    uint32_t dataSize_; //size of all variables except strings
    158162    static uint8_t state_; // detemines wheter we are server (default) or client
    159163    bool backsync_; // if true the variables with mode > 1 will be synchronised to server (client -> server)
     
    164168  };
    165169
    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 
    190170  // ================= Specialisation declarations
     171 
     172//   template <> _NetworkExport void Synchronisable::registerVariable( const std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional);
     173  template <> _NetworkExport void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional);
    191174  template <> _NetworkExport void Synchronisable::registerVariable( const ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    192175  template <> _NetworkExport void Synchronisable::registerVariable( ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
     
    200183  template <> _NetworkExport void Synchronisable::registerVariable( const Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    201184  template <> _NetworkExport void Synchronisable::registerVariable( Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
     185 
     186  template <class T> void Synchronisable::registerVariable(T& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
     187  {
     188    if (bidirectional)
     189      syncList.push_back(new SynchronisableVariableBidirectional<const T>(variable, mode, cb));
     190    else
     191      syncList.push_back(new SynchronisableVariable<const T>(variable, mode, cb));
     192    if ( this->state_ == mode )
     193      this->dataSize_ += syncList.back()->getSize(state_);
     194  }
     195 
     196
     197
     198//   template <class T> void Synchronisable::unregisterVariable(T& var){
     199//     std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin();
     200//     while(it!=syncList.end()){
     201//       if( ((*it)->getReference()) == &var ){
     202//         delete (*it);
     203//         syncList.erase(it);
     204//         return;
     205//       }
     206//       else
     207//         it++;
     208//     }
     209//     bool unregistered_nonexistent_variable = false;
     210//     assert(unregistered_nonexistent_variable); //if we reach this point something went wrong:
     211//     // the variable has not been registered before
     212//   }
     213
     214 
    202215}
    203216
Note: See TracChangeset for help on using the changeset viewer.