- Timestamp:
- Mar 23, 2009, 5:00:54 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/netp2/src/network/synchronisable/Synchronisable.h
r2826 r2836 33 33 34 34 #include <list> 35 #include <vector> 35 36 #include <map> 36 37 #include <queue> 37 38 #include <cassert> 39 #include <string> 38 40 #include "util/Math.h" 39 41 #include "util/mbool.h" … … 139 141 Synchronisable(BaseObject* creator); 140 142 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); 142 144 void setObjectMode(uint8_t mode); 143 145 void setPriority(unsigned int freq){ objectFrequency_ = freq; } … … 145 147 146 148 private: 147 boolgetData(uint8_t*& men, int32_t id, uint8_t mode=0x0);149 uint32_t getData(uint8_t*& men, int32_t id, uint8_t mode=0x0); 148 150 uint32_t getSize(int32_t id, uint8_t mode=0x0); 149 151 bool updateData(uint8_t*& mem, uint8_t mode=0x0, bool forceCallback=false); … … 155 157 uint32_t classID; 156 158 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 158 162 static uint8_t state_; // detemines wheter we are server (default) or client 159 163 bool backsync_; // if true the variables with mode > 1 will be synchronised to server (client -> server) … … 164 168 }; 165 169 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 else171 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 else183 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 before188 }189 190 170 // ================= 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); 191 174 template <> _NetworkExport void Synchronisable::registerVariable( const ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional); 192 175 template <> _NetworkExport void Synchronisable::registerVariable( ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional); … … 200 183 template <> _NetworkExport void Synchronisable::registerVariable( const Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional); 201 184 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 202 215 } 203 216
Note: See TracChangeset
for help on using the changeset viewer.