Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 23, 2009, 8:19:58 PM (15 years ago)
Author:
scheusso
Message:

synchronisation of pointers to classes that inherit from Synchronisable are now possible
just use the normal registerVariable syntax

Location:
code/branches/presentation2/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2/src/libraries/network/synchronisable/CMakeLists.txt

    r5781 r6123  
    1010  NetworkCallbackManager.h
    1111  Synchronisable.h
     12  SynchronisablePointer.h
    1213  SynchronisableVariable.h
    1314)
  • code/branches/presentation2/src/libraries/network/synchronisable/Synchronisable.h

    r5929 r6123  
    138138    Synchronisable(BaseObject* creator);
    139139    template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false);
    140     //template <class T> void unregisterVariable(T& var);
    141140    void setPriority(unsigned int freq){ objectFrequency_ = freq; }
    142141
     
    187186    if (bidirectional)
    188187    {
    189       syncList.push_back(new SynchronisableVariableBidirectional<const T>(variable, mode, cb));
     188      syncList.push_back(new SynchronisableVariableBidirectional<T>(variable, mode, cb));
    190189      this->dataSize_ += syncList.back()->getSize(state_);
    191190    }
    192191    else
    193192    {
    194       syncList.push_back(new SynchronisableVariable<const T>(variable, mode, cb));
     193      syncList.push_back(new SynchronisableVariable<T>(variable, mode, cb));
    195194      if ( this->state_ == mode )
    196195        this->dataSize_ += syncList.back()->getSize(state_);
    197196    }
    198197  }
    199  
    200 
    201 
    202 //   template <class T> void Synchronisable::unregisterVariable(T& var){
    203 //     std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin();
    204 //     while(it!=syncList.end()){
    205 //       if( ((*it)->getReference()) == &var ){
    206 //         delete (*it);
    207 //         syncList.erase(it);
    208 //         return;
    209 //       }
    210 //       else
    211 //         it++;
    212 //     }
    213 //     bool unregistered_nonexistent_variable = false;
    214 //     assert(unregistered_nonexistent_variable); //if we reach this point something went wrong:
    215 //     // the variable has not been registered before
    216 //   }
    217198
    218199 
  • code/branches/presentation2/src/libraries/network/synchronisable/SynchronisableVariable.h

    r5781 r6123  
    3535#include <cassert>
    3636#include <cstring>
    37 #include "util/Serialise.h"
     37#include "Serialise.h"
    3838#include "util/TypeTraits.h"
    3939#include "core/GameMode.h"
     
    143143    if ( this->callback_ != 0 )
    144144    {
    145       if( forceCallback || !checkEquality( this->variable_, mem ) )
    146         callback = true;
     145      callback = forceCallback || !checkEquality( this->variable_, mem );
    147146    }
    148147  // write the data
  • code/branches/presentation2/src/libraries/util/Serialise.h

    r5738 r6123  
    4040namespace orxonox{
    4141   
    42 // general template declaration
    43    
    4442    /** @brief returns the size of the variable in a datastream */
    45     template <class T> inline uint32_t returnSize( const T& );
     43    template <class T> inline uint32_t returnSize( const T& variable );
    4644    /** @brief loads the value of a variable out of the bytestream and increases the mem pointer */
    47     template <class T> inline void loadAndIncrease( const T&, uint8_t*& );
     45    template <class T> inline void loadAndIncrease( const T& variable, uint8_t*& mem );
    4846    /** @brief saves the value of a variable into the bytestream and increases the mem pointer */
    49     template <class T> inline void saveAndIncrease( const T&, uint8_t*& );
     47    template <class T> inline void saveAndIncrease( const T& variable, uint8_t*& mem );
    5048    /** @brief checks whether the variable of type T is the same as in the bytestream */
    51     template <class T> inline  bool checkEquality( const T&, uint8_t* );
     49    template <class T> inline bool checkEquality( const T& variable, uint8_t* mem );
    5250
    5351// =================== Template specialisation stuff =============
     
    471469        return variable==Degree(*r);
    472470    }
    473    
    474    
    475471}
    476472
  • code/branches/presentation2/src/orxonox/Test.cc

    r6084 r6123  
    3838    CreateFactory ( Test );
    3939 
    40   SetConsoleCommand(Test, printV1, true).accessLevel(AccessLevel::User);
    41   SetConsoleCommand(Test, printV2, true).accessLevel(AccessLevel::User);
    42   SetConsoleCommand(Test, printV3, true).accessLevel(AccessLevel::User);
    43   SetConsoleCommand(Test, printV4, true).accessLevel(AccessLevel::User);
    44   SetConsoleCommand(Test, call, true).accessLevel(AccessLevel::User);
    45   SetConsoleCommand(Test, call2, true).accessLevel(AccessLevel::User);
     40    SetConsoleCommand(Test, printV1, true).accessLevel(AccessLevel::User);
     41    SetConsoleCommand(Test, printV2, true).accessLevel(AccessLevel::User);
     42    SetConsoleCommand(Test, printV3, true).accessLevel(AccessLevel::User);
     43    SetConsoleCommand(Test, printV4, true).accessLevel(AccessLevel::User);
     44    SetConsoleCommand(Test, call, true).accessLevel(AccessLevel::User);
     45    SetConsoleCommand(Test, call2, true).accessLevel(AccessLevel::User);
    4646 
    4747 
     
    5050//   NetworkFunctionBase* NETWORK_FUNCTION_TEST_C = new NetworkFunctionStatic( createFunctor(&Test::printV1), "bla", NETWORK_FUNCTION_POINTER );
    5151 
    52   registerStaticNetworkFunction( &Test::printV1 );
    53   registerMemberNetworkFunction( Test, checkU1 );
    54   registerMemberNetworkFunction( Test, printBlaBla );
     52    registerStaticNetworkFunction( &Test::printV1 );
     53    registerMemberNetworkFunction( Test, checkU1 );
     54    registerMemberNetworkFunction( Test, printBlaBla );
    5555 
    56   Test* Test::instance_ = 0;
     56    Test* Test::instance_ = 0;
    5757
    5858    Test::Test(BaseObject* creator) : BaseObject(creator), Synchronisable(creator)
    5959    {
    60     assert(instance_==0);
    61     instance_=this;
     60        assert(instance_==0);
     61        instance_=this;
    6262        RegisterObject ( Test );
    63     setConfigValues();
    64     registerVariables();
     63        setConfigValues();
     64        registerVariables();
    6565        setSyncMode(0x3);
     66        this->pointer_ = 0;
    6667    }
    6768
    6869    Test::~Test()
    6970    {
    70     instance_=0;
     71        instance_=0;
    7172    }
    7273
     
    7475    {
    7576        SetConfigValue ( u1, 1 )/*.callback ( this, &Test::checkV1 )*/;
    76     SetConfigValue ( u2, 2 )/*.callback ( this, &Test::checkV2 )*/;
    77     SetConfigValue ( u3, 3 )/*.callback ( this, &Test::checkV3 )*/;
    78     SetConfigValue ( u4, 4 )/*.callback ( this, &Test::checkV4 )*/;
     77        SetConfigValue ( u2, 2 )/*.callback ( this, &Test::checkV2 )*/;
     78        SetConfigValue ( u3, 3 )/*.callback ( this, &Test::checkV3 )*/;
     79        SetConfigValue ( u4, 4 )/*.callback ( this, &Test::checkV4 )*/;
    7980   
    80     SetConfigValue ( s1, 1 )/*.callback ( this, &Test::checkV1 )*/;
    81     SetConfigValue ( s2, 2 )/*.callback ( this, &Test::checkV2 )*/;
    82     SetConfigValue ( s3, 3 )/*.callback ( this, &Test::checkV3 )*/;
    83     SetConfigValue ( s4, 4 )/*.callback ( this, &Test::checkV4 )*/;
     81        SetConfigValue ( s1, 1 )/*.callback ( this, &Test::checkV1 )*/;
     82        SetConfigValue ( s2, 2 )/*.callback ( this, &Test::checkV2 )*/;
     83        SetConfigValue ( s3, 3 )/*.callback ( this, &Test::checkV3 )*/;
     84        SetConfigValue ( s4, 4 )/*.callback ( this, &Test::checkV4 )*/;
    8485    }
    8586
    8687
    87   void Test::registerVariables()
    88   {
    89     registerVariable ( u1, variableDirection::toclient, new NetworkCallback<Test> ( this, &Test::checkU1 ));
    90     registerVariable ( u2, variableDirection::toserver, new NetworkCallback<Test> ( this, &Test::checkU2 ));
    91     registerVariable ( u3, variableDirection::serverMaster, new NetworkCallback<Test> ( this, &Test::checkU3 ), true );
    92     registerVariable ( u4, variableDirection::clientMaster, new NetworkCallback<Test> ( this, &Test::checkU4 ), true );
     88    void Test::registerVariables()
     89    {
     90        registerVariable ( u1, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::checkU1 ));
     91        registerVariable ( u2, VariableDirection::ToServer, new NetworkCallback<Test> ( this, &Test::checkU2 ));
     92        registerVariable ( u3, Bidirectionality::ServerMaster, new NetworkCallback<Test> ( this, &Test::checkU3 ), true );
     93        registerVariable ( u4, Bidirectionality::ClientMaster, new NetworkCallback<Test> ( this, &Test::checkU4 ), true );
    9394   
    94     registerVariable ( s1, variableDirection::toclient, new NetworkCallback<Test> ( this, &Test::checkS1 ));
    95     registerVariable ( s2, variableDirection::toserver, new NetworkCallback<Test> ( this, &Test::checkS2 ));
    96     registerVariable ( s3, variableDirection::serverMaster, new NetworkCallback<Test> ( this, &Test::checkS3 ), true );
    97     registerVariable ( s4, variableDirection::clientMaster, new NetworkCallback<Test> ( this, &Test::checkS4 ), true );
    98   }
     95        registerVariable ( s1, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::checkS1 ));
     96        registerVariable ( s2, VariableDirection::ToServer, new NetworkCallback<Test> ( this, &Test::checkS2 ));
     97        registerVariable ( s3, Bidirectionality::ServerMaster, new NetworkCallback<Test> ( this, &Test::checkS3 ), true );
     98        registerVariable ( s4, Bidirectionality::ClientMaster, new NetworkCallback<Test> ( this, &Test::checkS4 ), true );
     99   
     100        registerVariable ( pointer_, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::printPointer ) );
     101    }
    99102 
    100103  void Test::call(unsigned int clientID)
    101   {
    102     callStaticNetworkFunction( &Test::printV1, clientID );
    103     callStaticNetworkFunction( &Test::printV1, clientID );
    104   }
     104    {
     105        callStaticNetworkFunction( &Test::printV1, clientID );
     106        callStaticNetworkFunction( &Test::printV1, clientID );
     107    }
    105108 
    106   void Test::call2(unsigned int clientID, std::string s1, std::string s2, std::string s3, std::string s4)
    107   {
    108     callMemberNetworkFunction( Test, printBlaBla, this->getObjectID(), clientID, s1, s2, s3, s4, s4 );
    109   }
     109    void Test::call2(unsigned int clientID, std::string s1, std::string s2, std::string s3, std::string s4)
     110    {
     111        callMemberNetworkFunction( Test, printBlaBla, this->getObjectID(), clientID, s1, s2, s3, s4, s4 );
     112    }
    110113 
    111   void Test::tick(float dt)
    112   {
    113 //     std::string str1 = "blub";
    114 //     //MultiType mt1(std::string("blub"));
    115 //     MultiType mt1(str1);
    116 //     uint8_t* mem = new uint8_t[mt1.getNetworkSize()];
    117 //     uint8_t* temp = mem;
    118 //     mt1.exportData( temp );
    119 //     assert( temp-mem == mt1.getNetworkSize() );
    120 //     MultiType mt2;
    121 //     temp = mem;
    122 //     mt2.importData( temp );
    123 //     assert( temp-mem == mt1.getNetworkSize() );
    124 //     COUT(0) << mt2 << endl;
    125     if(!Core::isMaster())
    126       call2(0, "bal", "a", "n", "ce");
    127 //       callMemberNetworkFunction( Test, checkU1, this->getObjectID(), 0 );
    128   }
    129  
    130   void Test::printBlaBla(std::string s1, std::string s2, std::string s3, std::string s4, std::string s5)
    131   {
    132     COUT(0) << s1 << s2 << s3 << s4 << s5 << endl;
    133   }
    134  
    135   void Test::checkU1(){ COUT(1) << "U1 changed: " << u1 << std::endl; }
    136   void Test::checkU2(){ COUT(1) << "U2 changed: " << u2 << std::endl; }
    137   void Test::checkU3(){ COUT(1) << "U3 changed: " << u3 << std::endl; }
    138   void Test::checkU4(){ COUT(1) << "U4 changed: " << u4 << std::endl; }
     114    void Test::tick(float dt)
     115    {
     116    //     std::string str1 = "blub";
     117    //     //MultiType mt1(std::string("blub"));
     118    //     MultiType mt1(str1);
     119    //     uint8_t* mem = new uint8_t[mt1.getNetworkSize()];
     120    //     uint8_t* temp = mem;
     121    //     mt1.exportData( temp );
     122    //     assert( temp-mem == mt1.getNetworkSize() );
     123    //     MultiType mt2;
     124    //     temp = mem;
     125    //     mt2.importData( temp );
     126    //     assert( temp-mem == mt1.getNetworkSize() );
     127    //     COUT(0) << mt2 << endl;
     128    //     if(!Core::isMaster())
     129    //       call2(0, "bal", "a", "n", "ce");
     130    //       callMemberNetworkFunction( Test, checkU1, this->getObjectID(), 0 );
     131    }
     132   
     133    void Test::printBlaBla(std::string s1, std::string s2, std::string s3, std::string s4, std::string s5)
     134    {
     135        COUT(0) << s1 << s2 << s3 << s4 << s5 << endl;
     136    }
     137   
     138    void Test::checkU1(){ COUT(1) << "U1 changed: " << u1 << std::endl; }
     139    void Test::checkU2(){ COUT(1) << "U2 changed: " << u2 << std::endl; }
     140    void Test::checkU3(){ COUT(1) << "U3 changed: " << u3 << std::endl; }
     141    void Test::checkU4(){ COUT(1) << "U4 changed: " << u4 << std::endl; }
    139142
    140   void Test::checkS1(){ COUT(1) << "S1 changed: " << s1 << std::endl; }
    141   void Test::checkS2(){ COUT(1) << "S2 changed: " << s2 << std::endl; }
    142   void Test::checkS3(){ COUT(1) << "S3 changed: " << s3 << std::endl; }
    143   void Test::checkS4(){ COUT(1) << "S4 changed: " << s4 << std::endl; }
     143    void Test::checkS1(){ COUT(1) << "S1 changed: " << s1 << std::endl; }
     144    void Test::checkS2(){ COUT(1) << "S2 changed: " << s2 << std::endl; }
     145    void Test::checkS3(){ COUT(1) << "S3 changed: " << s3 << std::endl; }
     146    void Test::checkS4(){ COUT(1) << "S4 changed: " << s4 << std::endl; }
     147   
     148    void Test::printPointer(){ CCOUT(1) << "pointer: " << this->pointer_ << endl; }
    144149
    145150}
  • code/branches/presentation2/src/orxonox/Test.h

    r5781 r6123  
    7575      void checkS3();
    7676      void checkS4();
     77     
     78      void printPointer();
    7779
    7880      static void printV1(){ instance_->checkU1(); }
     
    9395      TYPE s3;
    9496      TYPE s4;
     97     
     98      Test* pointer_;
    9599
    96100      static Test* instance_;
Note: See TracChangeset for help on using the changeset viewer.