[Orxonox-commit 2390] r7105 - in code/branches/presentation3/src: libraries/core libraries/network/synchronisable libraries/util orxonox
scheusso at orxonox.net
scheusso at orxonox.net
Thu Jun 3 02:24:14 CEST 2010
Author: scheusso
Date: 2010-06-03 02:24:14 +0200 (Thu, 03 Jun 2010)
New Revision: 7105
Modified:
code/branches/presentation3/src/libraries/core/BaseObject.cc
code/branches/presentation3/src/libraries/core/BaseObject.h
code/branches/presentation3/src/libraries/core/Template.h
code/branches/presentation3/src/libraries/network/synchronisable/Synchronisable.h
code/branches/presentation3/src/libraries/util/Serialise.h
code/branches/presentation3/src/orxonox/Level.cc
code/branches/presentation3/src/orxonox/Level.h
code/branches/presentation3/src/orxonox/Test.cc
code/branches/presentation3/src/orxonox/Test.h
Log:
std::set<T> is now synchronisable
this was neccessary to synchronise templates (now used in the Level class)
this was neccessary to synchronise lod templates and configuration
Modified: code/branches/presentation3/src/libraries/core/BaseObject.cc
===================================================================
--- code/branches/presentation3/src/libraries/core/BaseObject.cc 2010-06-03 00:21:26 UTC (rev 7104)
+++ code/branches/presentation3/src/libraries/core/BaseObject.cc 2010-06-03 00:24:14 UTC (rev 7105)
@@ -195,6 +195,13 @@
void BaseObject::addTemplate(Template* temp)
{
this->templates_.insert(temp);
+ if( temp->isLink() )
+ {
+ this->networkTemplateNames_.insert(temp->getLink());
+ assert( !Template::getTemplate(temp->getLink())->isLink() );
+ }
+ else
+ this->networkTemplateNames_.insert(temp->getName());
temp->applyOn(this);
}
Modified: code/branches/presentation3/src/libraries/core/BaseObject.h
===================================================================
--- code/branches/presentation3/src/libraries/core/BaseObject.h 2010-06-03 00:21:26 UTC (rev 7104)
+++ code/branches/presentation3/src/libraries/core/BaseObject.h 2010-06-03 00:24:14 UTC (rev 7105)
@@ -190,12 +190,13 @@
void addEventState(const std::string& name, EventState* container);
EventState* getEventState(const std::string& name) const;
- std::string name_; //!< The name of the object
- std::string oldName_; //!< The old name of the object
- mbool bActive_; //!< True = the object is active
- mbool bVisible_; //!< True = the object is visible
- std::string mainStateName_;
- Functor* mainStateFunctor_;
+ std::string name_; //!< The name of the object
+ std::string oldName_; //!< The old name of the object
+ mbool bActive_; //!< True = the object is active
+ mbool bVisible_; //!< True = the object is visible
+ std::string mainStateName_;
+ Functor* mainStateFunctor_;
+ std::set<std::string> networkTemplateNames_;
private:
/** @brief Adds an object which listens to the events of this object. */
Modified: code/branches/presentation3/src/libraries/core/Template.h
===================================================================
--- code/branches/presentation3/src/libraries/core/Template.h 2010-06-03 00:21:26 UTC (rev 7104)
+++ code/branches/presentation3/src/libraries/core/Template.h 2010-06-03 00:24:14 UTC (rev 7105)
@@ -50,6 +50,8 @@
{ this->link_ = link; this->bIsLink_ = !link.empty(); }
inline const std::string& getLink() const
{ return this->link_; }
+ inline bool isLink() const
+ { return this->bIsLink_; }
inline void setLoadDefaults(bool bLoadDefaults)
{ this->bLoadDefaults_ = bLoadDefaults; }
Modified: code/branches/presentation3/src/libraries/network/synchronisable/Synchronisable.h
===================================================================
--- code/branches/presentation3/src/libraries/network/synchronisable/Synchronisable.h 2010-06-03 00:21:26 UTC (rev 7104)
+++ code/branches/presentation3/src/libraries/network/synchronisable/Synchronisable.h 2010-06-03 00:24:14 UTC (rev 7105)
@@ -36,6 +36,7 @@
#include <vector>
#include <map>
#include <queue>
+#include <set>
#include "util/mbool.h"
#include "core/OrxonoxClass.h"
@@ -137,6 +138,7 @@
protected:
Synchronisable(BaseObject* creator);
template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false);
+ template <class T> void registerVariable(std::set<T>& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false);
void setPriority(unsigned int freq){ objectFrequency_ = freq; }
@@ -180,8 +182,20 @@
this->dataSize_ += syncList.back()->getSize(state_);
}
}
+
+ template <class T> void Synchronisable::registerVariable( std::set<T>& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
+ {
+ SynchronisableVariableBase* sv;
+ if (bidirectional)
+ sv = new SynchronisableVariableBidirectional<std::set<T> >(variable, mode, cb);
+ else
+ sv = new SynchronisableVariable<std::set<T> >(variable, mode, cb);
+ syncList.push_back(sv);
+ stringList.push_back(sv);
+ }
template <> _NetworkExport void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional);
+// template <class T> _NetworkExport void Synchronisable::registerVariable<std::set<T> >( std::set<T>& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional);
}
Modified: code/branches/presentation3/src/libraries/util/Serialise.h
===================================================================
--- code/branches/presentation3/src/libraries/util/Serialise.h 2010-06-03 00:21:26 UTC (rev 7104)
+++ code/branches/presentation3/src/libraries/util/Serialise.h 2010-06-03 00:24:14 UTC (rev 7105)
@@ -37,6 +37,7 @@
#include "UtilPrereqs.h"
#include <cstring>
+#include <set>
#include "Math.h"
#include "mbool.h"
@@ -634,6 +635,71 @@
{
return checkEquality( (unsigned char&)((mbool&)variable).getMemory(), mem );
}
+
+ // =========== std::set
+
+ template <class T> inline uint32_t returnSize( const std::set<T>& variable )
+ {
+ uint32_t tempsize = sizeof(uint32_t); // for the number of entries
+ for( typename std::set<T>::iterator it=((std::set<T>*)(&variable))->begin(); it!=((std::set<T>*)(&variable))->end(); ++it)
+ tempsize += returnSize( *it );
+ return tempsize;
+ }
+
+ template <class T> inline void saveAndIncrease( const std::set<T>& variable, uint8_t*& mem )
+ {
+ typename std::set<T>::const_iterator it = variable.begin();
+ saveAndIncrease( (uint32_t)variable.size(), mem );
+ for( ; it!=variable.end(); ++it )
+ saveAndIncrease( *it, mem );
+ }
+
+ template <class T> inline void loadAndIncrease( const std::set<T>& variable, uint8_t*& mem )
+ {
+ uint32_t nrOfElements = 0;
+ loadAndIncrease( nrOfElements, mem );
+ typename std::set<T>::const_iterator it = variable.begin();
+ for( uint32_t i = 0; i<nrOfElements; ++i )
+ {
+ T temp;
+ loadAndIncrease(temp, mem);
+ while( it!=variable.end() && *it!=temp )
+ {
+ ((std::set<T>*)(&variable))->erase(it++);
+ ++it;
+ }
+ if( it==variable.end() )
+ {
+ ((std::set<T>*)(&variable))->insert(temp);
+ }
+ }
+ }
+
+ template <class T> inline bool checkEquality( const std::set<T>& variable, uint8_t* mem )
+ {
+ uint8_t* temp = mem;
+ uint32_t nrOfElements;
+ loadAndIncrease(nrOfElements, mem);
+ if( variable.size() == nrOfElements )
+ {
+ T tempT;
+ for( uint32_t i=0; i<nrOfElements; ++i )
+ {
+ loadAndIncrease(tempT, mem);
+ if( variable.find(tempT) == variable.end() )
+ {
+ mem = temp;
+ return false;
+ }
+ }
+ }
+ else
+ {
+ mem = temp;
+ return false;
+ }
+ return true;
+ }
}
Modified: code/branches/presentation3/src/orxonox/Level.cc
===================================================================
--- code/branches/presentation3/src/orxonox/Level.cc 2010-06-03 00:21:26 UTC (rev 7104)
+++ code/branches/presentation3/src/orxonox/Level.cc 2010-06-03 00:24:14 UTC (rev 7105)
@@ -79,9 +79,10 @@
void Level::registerVariables()
{
- registerVariable(this->xmlfilename_, VariableDirection::ToClient, new NetworkCallback<Level>(this, &Level::networkcallback_applyXMLFile));
- registerVariable(this->name_, VariableDirection::ToClient, new NetworkCallback<Level>(this, &Level::changedName));
- registerVariable(this->description_, VariableDirection::ToClient);
+ registerVariable(this->xmlfilename_, VariableDirection::ToClient, new NetworkCallback<Level>(this, &Level::networkcallback_applyXMLFile));
+ registerVariable(this->name_, VariableDirection::ToClient, new NetworkCallback<Level>(this, &Level::changedName));
+ registerVariable(this->description_, VariableDirection::ToClient);
+ registerVariable(this->networkTemplateNames_, VariableDirection::ToClient, new NetworkCallback<Level>(this, &Level::networkCallbackTemplatesChanged));
}
void Level::networkcallback_applyXMLFile()
@@ -97,6 +98,15 @@
Loader::open(this->xmlfile_);
}
+
+ void Level::networkCallbackTemplatesChanged()
+ {
+ for( std::set<std::string>::iterator it = this->networkTemplateNames_.begin(); it!=this->networkTemplateNames_.end(); ++it )
+ {
+ assert(Template::getTemplate(*it));
+ Template::getTemplate(*it)->applyOn(this);
+ }
+ }
void Level::setGametypeString(const std::string& gametype)
{
Modified: code/branches/presentation3/src/orxonox/Level.h
===================================================================
--- code/branches/presentation3/src/orxonox/Level.h 2010-06-03 00:21:26 UTC (rev 7104)
+++ code/branches/presentation3/src/orxonox/Level.h 2010-06-03 00:24:14 UTC (rev 7105)
@@ -65,6 +65,7 @@
BaseObject* getObject(unsigned int index) const;
void addLodInfo(MeshLodInformation* object);
+ void networkCallbackTemplatesChanged();
// const MeshLodInformation* getLodInfo(std::string meshName) const;
// MeshLodInformation* getLodInfo(unsigned int index) const;
Modified: code/branches/presentation3/src/orxonox/Test.cc
===================================================================
--- code/branches/presentation3/src/orxonox/Test.cc 2010-06-03 00:21:26 UTC (rev 7104)
+++ code/branches/presentation3/src/orxonox/Test.cc 2010-06-03 00:24:14 UTC (rev 7105)
@@ -87,17 +87,19 @@
void Test::registerVariables()
{
- registerVariable ( u1, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::checkU1 ));
- registerVariable ( u2, VariableDirection::ToServer, new NetworkCallback<Test> ( this, &Test::checkU2 ));
- registerVariable ( u3, Bidirectionality::ServerMaster, new NetworkCallback<Test> ( this, &Test::checkU3 ), true );
- registerVariable ( u4, Bidirectionality::ClientMaster, new NetworkCallback<Test> ( this, &Test::checkU4 ), true );
+ registerVariable ( this->mySet_, VariableDirection::ToClient );
+
+// registerVariable ( u1, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::checkU1 ));
+// registerVariable ( u2, VariableDirection::ToServer, new NetworkCallback<Test> ( this, &Test::checkU2 ));
+// registerVariable ( u3, Bidirectionality::ServerMaster, new NetworkCallback<Test> ( this, &Test::checkU3 ), true );
+// registerVariable ( u4, Bidirectionality::ClientMaster, new NetworkCallback<Test> ( this, &Test::checkU4 ), true );
- registerVariable ( s1, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::checkS1 ));
- registerVariable ( s2, VariableDirection::ToServer, new NetworkCallback<Test> ( this, &Test::checkS2 ));
- registerVariable ( s3, Bidirectionality::ServerMaster, new NetworkCallback<Test> ( this, &Test::checkS3 ), true );
- registerVariable ( s4, Bidirectionality::ClientMaster, new NetworkCallback<Test> ( this, &Test::checkS4 ), true );
+// registerVariable ( s1, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::checkS1 ));
+// registerVariable ( s2, VariableDirection::ToServer, new NetworkCallback<Test> ( this, &Test::checkS2 ));
+// registerVariable ( s3, Bidirectionality::ServerMaster, new NetworkCallback<Test> ( this, &Test::checkS3 ), true );
+// registerVariable ( s4, Bidirectionality::ClientMaster, new NetworkCallback<Test> ( this, &Test::checkS4 ), true );
- registerVariable ( pointer_, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::printPointer ) );
+// registerVariable ( pointer_, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::printPointer ) );
}
void Test::call(unsigned int clientID)
Modified: code/branches/presentation3/src/orxonox/Test.h
===================================================================
--- code/branches/presentation3/src/orxonox/Test.h 2010-06-03 00:21:26 UTC (rev 7104)
+++ code/branches/presentation3/src/orxonox/Test.h 2010-06-03 00:24:14 UTC (rev 7105)
@@ -34,6 +34,7 @@
#include "network/synchronisable/Synchronisable.h"
#include "tools/interfaces/Tickable.h"
+#include <set>
typedef int TYPE;
typedef unsigned int UTYPE;
@@ -77,8 +78,8 @@
void printPointer();
- static void printV1(){ instance_->checkU1(); }
- static void printV2(){ instance_->checkU2(); }
+ static void printV1(){ instance_->blub(); }
+ static void printV2(){ instance_->blub2(); }
static void printV3(){ instance_->checkU3(); }
static void printV4(){ instance_->checkU4(); }
@@ -96,8 +97,16 @@
TYPE s4;
Test* pointer_;
+
+ std::set<uint32_t> mySet_;
static Test* instance_;
+
+ void blub()
+ { mySet_.insert(2); }
+
+ void blub2()
+ { for( std::set<uint32_t>::iterator it=mySet_.begin(); it!=mySet_.end(); ++it ) COUT(0) << *it << endl; }
};
}
More information about the Orxonox-commit
mailing list