- Timestamp:
- Mar 23, 2009, 10:28:25 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/netp/src/network/synchronisable/Synchronisable.h
r2773 r2822 36 36 #include <queue> 37 37 #include <cassert> 38 #include <string> 38 39 #include "util/Math.h" 39 40 #include "util/mbool.h" … … 139 140 Synchronisable(BaseObject* creator); 140 141 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); 142 143 void setObjectMode(uint8_t mode); 143 144 void setPriority(unsigned int freq){ objectFrequency_ = freq; } … … 156 157 157 158 std::list<SynchronisableVariableBase*> syncList; 159 std::list<SynchronisableVariableBase*> stringList; 160 uint32_t dataSize_; //size of all variables except strings 158 161 static uint8_t state_; // detemines wheter we are server (default) or client 159 162 bool backsync_; // if true the variables with mode > 1 will be synchronised to server (client -> server) … … 164 167 }; 165 168 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 169 // ================= 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); 191 173 template <> _NetworkExport void Synchronisable::registerVariable( const ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional); 192 174 template <> _NetworkExport void Synchronisable::registerVariable( ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional); … … 200 182 template <> _NetworkExport void Synchronisable::registerVariable( const Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional); 201 183 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 syncList.push_back(new SynchronisableVariableBidirectional<const T>(variable, mode, cb)); 189 else 190 syncList.push_back(new SynchronisableVariable<const T>(variable, mode, cb)); 191 if ( this->state_ == mode ) 192 this->dataSize_ += syncList.back()->getSize(state_); 193 } 194 195 196 197 // template <class T> void Synchronisable::unregisterVariable(T& var){ 198 // std::list<SynchronisableVariableBase*>::iterator it = syncList.begin(); 199 // while(it!=syncList.end()){ 200 // if( ((*it)->getReference()) == &var ){ 201 // delete (*it); 202 // syncList.erase(it); 203 // return; 204 // } 205 // else 206 // it++; 207 // } 208 // bool unregistered_nonexistent_variable = false; 209 // assert(unregistered_nonexistent_variable); //if we reach this point something went wrong: 210 // // the variable has not been registered before 211 // } 212 213 202 214 } 203 215
Note: See TracChangeset
for help on using the changeset viewer.