[Orxonox-commit 1405] r6123 - in code/branches/presentation2/src: libraries/network/synchronisable libraries/util orxonox
scheusso at orxonox.net
scheusso at orxonox.net
Mon Nov 23 20:19:58 CET 2009
Author: scheusso
Date: 2009-11-23 20:19:58 +0100 (Mon, 23 Nov 2009)
New Revision: 6123
Modified:
code/branches/presentation2/src/libraries/network/synchronisable/CMakeLists.txt
code/branches/presentation2/src/libraries/network/synchronisable/Synchronisable.h
code/branches/presentation2/src/libraries/network/synchronisable/SynchronisableVariable.h
code/branches/presentation2/src/libraries/util/Serialise.h
code/branches/presentation2/src/orxonox/Test.cc
code/branches/presentation2/src/orxonox/Test.h
Log:
synchronisation of pointers to classes that inherit from Synchronisable are now possible
just use the normal registerVariable syntax
Modified: code/branches/presentation2/src/libraries/network/synchronisable/CMakeLists.txt
===================================================================
--- code/branches/presentation2/src/libraries/network/synchronisable/CMakeLists.txt 2009-11-23 19:10:03 UTC (rev 6122)
+++ code/branches/presentation2/src/libraries/network/synchronisable/CMakeLists.txt 2009-11-23 19:19:58 UTC (rev 6123)
@@ -9,5 +9,6 @@
NetworkCallback.h
NetworkCallbackManager.h
Synchronisable.h
+ SynchronisablePointer.h
SynchronisableVariable.h
)
Modified: code/branches/presentation2/src/libraries/network/synchronisable/Synchronisable.h
===================================================================
--- code/branches/presentation2/src/libraries/network/synchronisable/Synchronisable.h 2009-11-23 19:10:03 UTC (rev 6122)
+++ code/branches/presentation2/src/libraries/network/synchronisable/Synchronisable.h 2009-11-23 19:19:58 UTC (rev 6123)
@@ -137,7 +137,6 @@
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 unregisterVariable(T& var);
void setPriority(unsigned int freq){ objectFrequency_ = freq; }
@@ -186,35 +185,17 @@
{
if (bidirectional)
{
- syncList.push_back(new SynchronisableVariableBidirectional<const T>(variable, mode, cb));
+ syncList.push_back(new SynchronisableVariableBidirectional<T>(variable, mode, cb));
this->dataSize_ += syncList.back()->getSize(state_);
}
else
{
- syncList.push_back(new SynchronisableVariable<const T>(variable, mode, cb));
+ syncList.push_back(new SynchronisableVariable<T>(variable, mode, cb));
if ( this->state_ == mode )
this->dataSize_ += syncList.back()->getSize(state_);
}
}
-
-
-// template <class T> void Synchronisable::unregisterVariable(T& var){
-// std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin();
-// while(it!=syncList.end()){
-// if( ((*it)->getReference()) == &var ){
-// delete (*it);
-// syncList.erase(it);
-// return;
-// }
-// else
-// it++;
-// }
-// bool unregistered_nonexistent_variable = false;
-// assert(unregistered_nonexistent_variable); //if we reach this point something went wrong:
-// // the variable has not been registered before
-// }
-
}
Modified: code/branches/presentation2/src/libraries/network/synchronisable/SynchronisableVariable.h
===================================================================
--- code/branches/presentation2/src/libraries/network/synchronisable/SynchronisableVariable.h 2009-11-23 19:10:03 UTC (rev 6122)
+++ code/branches/presentation2/src/libraries/network/synchronisable/SynchronisableVariable.h 2009-11-23 19:19:58 UTC (rev 6123)
@@ -34,7 +34,7 @@
#include <cassert>
#include <cstring>
-#include "util/Serialise.h"
+#include "Serialise.h"
#include "util/TypeTraits.h"
#include "core/GameMode.h"
#include "network/synchronisable/NetworkCallbackManager.h"
@@ -142,8 +142,7 @@
// check whether we need to consider a callback
if ( this->callback_ != 0 )
{
- if( forceCallback || !checkEquality( this->variable_, mem ) )
- callback = true;
+ callback = forceCallback || !checkEquality( this->variable_, mem );
}
// write the data
loadAndIncrease( this->variable_, mem );
Modified: code/branches/presentation2/src/libraries/util/Serialise.h
===================================================================
--- code/branches/presentation2/src/libraries/util/Serialise.h 2009-11-23 19:10:03 UTC (rev 6122)
+++ code/branches/presentation2/src/libraries/util/Serialise.h 2009-11-23 19:19:58 UTC (rev 6123)
@@ -39,16 +39,14 @@
namespace orxonox{
-// general template declaration
-
/** @brief returns the size of the variable in a datastream */
- template <class T> inline uint32_t returnSize( const T& );
+ template <class T> inline uint32_t returnSize( const T& variable );
/** @brief loads the value of a variable out of the bytestream and increases the mem pointer */
- template <class T> inline void loadAndIncrease( const T&, uint8_t*& );
+ template <class T> inline void loadAndIncrease( const T& variable, uint8_t*& mem );
/** @brief saves the value of a variable into the bytestream and increases the mem pointer */
- template <class T> inline void saveAndIncrease( const T&, uint8_t*& );
+ template <class T> inline void saveAndIncrease( const T& variable, uint8_t*& mem );
/** @brief checks whether the variable of type T is the same as in the bytestream */
- template <class T> inline bool checkEquality( const T&, uint8_t* );
+ template <class T> inline bool checkEquality( const T& variable, uint8_t* mem );
// =================== Template specialisation stuff =============
@@ -470,8 +468,6 @@
Ogre::Real* r = (Ogre::Real*)mem;
return variable==Degree(*r);
}
-
-
}
Modified: code/branches/presentation2/src/orxonox/Test.cc
===================================================================
--- code/branches/presentation2/src/orxonox/Test.cc 2009-11-23 19:10:03 UTC (rev 6122)
+++ code/branches/presentation2/src/orxonox/Test.cc 2009-11-23 19:19:58 UTC (rev 6123)
@@ -37,109 +37,114 @@
{
CreateFactory ( Test );
- SetConsoleCommand(Test, printV1, true).accessLevel(AccessLevel::User);
- SetConsoleCommand(Test, printV2, true).accessLevel(AccessLevel::User);
- SetConsoleCommand(Test, printV3, true).accessLevel(AccessLevel::User);
- SetConsoleCommand(Test, printV4, true).accessLevel(AccessLevel::User);
- SetConsoleCommand(Test, call, true).accessLevel(AccessLevel::User);
- SetConsoleCommand(Test, call2, true).accessLevel(AccessLevel::User);
+ SetConsoleCommand(Test, printV1, true).accessLevel(AccessLevel::User);
+ SetConsoleCommand(Test, printV2, true).accessLevel(AccessLevel::User);
+ SetConsoleCommand(Test, printV3, true).accessLevel(AccessLevel::User);
+ SetConsoleCommand(Test, printV4, true).accessLevel(AccessLevel::User);
+ SetConsoleCommand(Test, call, true).accessLevel(AccessLevel::User);
+ SetConsoleCommand(Test, call2, true).accessLevel(AccessLevel::User);
//void=* aaaaa = copyPtr<sizeof(&Test::printV1)>( &NETWORK_FUNCTION_POINTER, &Test::printV1 );
//void* NETWORK_FUNCTION_TEST_B = memcpy(&NETWORK_FUNCTION_POINTER, &a, sizeof(a));
// NetworkFunctionBase* NETWORK_FUNCTION_TEST_C = new NetworkFunctionStatic( createFunctor(&Test::printV1), "bla", NETWORK_FUNCTION_POINTER );
- registerStaticNetworkFunction( &Test::printV1 );
- registerMemberNetworkFunction( Test, checkU1 );
- registerMemberNetworkFunction( Test, printBlaBla );
+ registerStaticNetworkFunction( &Test::printV1 );
+ registerMemberNetworkFunction( Test, checkU1 );
+ registerMemberNetworkFunction( Test, printBlaBla );
- Test* Test::instance_ = 0;
+ Test* Test::instance_ = 0;
Test::Test(BaseObject* creator) : BaseObject(creator), Synchronisable(creator)
{
- assert(instance_==0);
- instance_=this;
+ assert(instance_==0);
+ instance_=this;
RegisterObject ( Test );
- setConfigValues();
- registerVariables();
+ setConfigValues();
+ registerVariables();
setSyncMode(0x3);
+ this->pointer_ = 0;
}
Test::~Test()
{
- instance_=0;
+ instance_=0;
}
void Test::setConfigValues()
{
SetConfigValue ( u1, 1 )/*.callback ( this, &Test::checkV1 )*/;
- SetConfigValue ( u2, 2 )/*.callback ( this, &Test::checkV2 )*/;
- SetConfigValue ( u3, 3 )/*.callback ( this, &Test::checkV3 )*/;
- SetConfigValue ( u4, 4 )/*.callback ( this, &Test::checkV4 )*/;
+ SetConfigValue ( u2, 2 )/*.callback ( this, &Test::checkV2 )*/;
+ SetConfigValue ( u3, 3 )/*.callback ( this, &Test::checkV3 )*/;
+ SetConfigValue ( u4, 4 )/*.callback ( this, &Test::checkV4 )*/;
- SetConfigValue ( s1, 1 )/*.callback ( this, &Test::checkV1 )*/;
- SetConfigValue ( s2, 2 )/*.callback ( this, &Test::checkV2 )*/;
- SetConfigValue ( s3, 3 )/*.callback ( this, &Test::checkV3 )*/;
- SetConfigValue ( s4, 4 )/*.callback ( this, &Test::checkV4 )*/;
+ SetConfigValue ( s1, 1 )/*.callback ( this, &Test::checkV1 )*/;
+ SetConfigValue ( s2, 2 )/*.callback ( this, &Test::checkV2 )*/;
+ SetConfigValue ( s3, 3 )/*.callback ( this, &Test::checkV3 )*/;
+ SetConfigValue ( s4, 4 )/*.callback ( this, &Test::checkV4 )*/;
}
- 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, variableDirection::serverMaster, new NetworkCallback<Test> ( this, &Test::checkU3 ), true );
- registerVariable ( u4, variableDirection::clientMaster, new NetworkCallback<Test> ( this, &Test::checkU4 ), true );
+ 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 ( s1, variableDirection::toclient, new NetworkCallback<Test> ( this, &Test::checkS1 ));
- registerVariable ( s2, variableDirection::toserver, new NetworkCallback<Test> ( this, &Test::checkS2 ));
- registerVariable ( s3, variableDirection::serverMaster, new NetworkCallback<Test> ( this, &Test::checkS3 ), true );
- registerVariable ( s4, variableDirection::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 ) );
+ }
void Test::call(unsigned int clientID)
- {
- callStaticNetworkFunction( &Test::printV1, clientID );
- callStaticNetworkFunction( &Test::printV1, clientID );
- }
+ {
+ callStaticNetworkFunction( &Test::printV1, clientID );
+ callStaticNetworkFunction( &Test::printV1, clientID );
+ }
- void Test::call2(unsigned int clientID, std::string s1, std::string s2, std::string s3, std::string s4)
- {
- callMemberNetworkFunction( Test, printBlaBla, this->getObjectID(), clientID, s1, s2, s3, s4, s4 );
- }
+ void Test::call2(unsigned int clientID, std::string s1, std::string s2, std::string s3, std::string s4)
+ {
+ callMemberNetworkFunction( Test, printBlaBla, this->getObjectID(), clientID, s1, s2, s3, s4, s4 );
+ }
- void Test::tick(float dt)
- {
-// std::string str1 = "blub";
-// //MultiType mt1(std::string("blub"));
-// MultiType mt1(str1);
-// uint8_t* mem = new uint8_t[mt1.getNetworkSize()];
-// uint8_t* temp = mem;
-// mt1.exportData( temp );
-// assert( temp-mem == mt1.getNetworkSize() );
-// MultiType mt2;
-// temp = mem;
-// mt2.importData( temp );
-// assert( temp-mem == mt1.getNetworkSize() );
-// COUT(0) << mt2 << endl;
- if(!Core::isMaster())
- call2(0, "bal", "a", "n", "ce");
-// callMemberNetworkFunction( Test, checkU1, this->getObjectID(), 0 );
- }
-
- void Test::printBlaBla(std::string s1, std::string s2, std::string s3, std::string s4, std::string s5)
- {
- COUT(0) << s1 << s2 << s3 << s4 << s5 << endl;
- }
-
- void Test::checkU1(){ COUT(1) << "U1 changed: " << u1 << std::endl; }
- void Test::checkU2(){ COUT(1) << "U2 changed: " << u2 << std::endl; }
- void Test::checkU3(){ COUT(1) << "U3 changed: " << u3 << std::endl; }
- void Test::checkU4(){ COUT(1) << "U4 changed: " << u4 << std::endl; }
+ void Test::tick(float dt)
+ {
+ // std::string str1 = "blub";
+ // //MultiType mt1(std::string("blub"));
+ // MultiType mt1(str1);
+ // uint8_t* mem = new uint8_t[mt1.getNetworkSize()];
+ // uint8_t* temp = mem;
+ // mt1.exportData( temp );
+ // assert( temp-mem == mt1.getNetworkSize() );
+ // MultiType mt2;
+ // temp = mem;
+ // mt2.importData( temp );
+ // assert( temp-mem == mt1.getNetworkSize() );
+ // COUT(0) << mt2 << endl;
+ // if(!Core::isMaster())
+ // call2(0, "bal", "a", "n", "ce");
+ // callMemberNetworkFunction( Test, checkU1, this->getObjectID(), 0 );
+ }
+
+ void Test::printBlaBla(std::string s1, std::string s2, std::string s3, std::string s4, std::string s5)
+ {
+ COUT(0) << s1 << s2 << s3 << s4 << s5 << endl;
+ }
+
+ void Test::checkU1(){ COUT(1) << "U1 changed: " << u1 << std::endl; }
+ void Test::checkU2(){ COUT(1) << "U2 changed: " << u2 << std::endl; }
+ void Test::checkU3(){ COUT(1) << "U3 changed: " << u3 << std::endl; }
+ void Test::checkU4(){ COUT(1) << "U4 changed: " << u4 << std::endl; }
- void Test::checkS1(){ COUT(1) << "S1 changed: " << s1 << std::endl; }
- void Test::checkS2(){ COUT(1) << "S2 changed: " << s2 << std::endl; }
- void Test::checkS3(){ COUT(1) << "S3 changed: " << s3 << std::endl; }
- void Test::checkS4(){ COUT(1) << "S4 changed: " << s4 << std::endl; }
+ void Test::checkS1(){ COUT(1) << "S1 changed: " << s1 << std::endl; }
+ void Test::checkS2(){ COUT(1) << "S2 changed: " << s2 << std::endl; }
+ void Test::checkS3(){ COUT(1) << "S3 changed: " << s3 << std::endl; }
+ void Test::checkS4(){ COUT(1) << "S4 changed: " << s4 << std::endl; }
+
+ void Test::printPointer(){ CCOUT(1) << "pointer: " << this->pointer_ << endl; }
}
Modified: code/branches/presentation2/src/orxonox/Test.h
===================================================================
--- code/branches/presentation2/src/orxonox/Test.h 2009-11-23 19:10:03 UTC (rev 6122)
+++ code/branches/presentation2/src/orxonox/Test.h 2009-11-23 19:19:58 UTC (rev 6123)
@@ -74,6 +74,8 @@
void checkS2();
void checkS3();
void checkS4();
+
+ void printPointer();
static void printV1(){ instance_->checkU1(); }
static void printV2(){ instance_->checkU2(); }
@@ -92,6 +94,8 @@
TYPE s2;
TYPE s3;
TYPE s4;
+
+ Test* pointer_;
static Test* instance_;
};
More information about the Orxonox-commit
mailing list