Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7105


Ignore:
Timestamp:
Jun 3, 2010, 2:24:14 AM (15 years ago)
Author:
scheusso
Message:

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

Location:
code/branches/presentation3/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation3/src/libraries/core/BaseObject.cc

    r6926 r7105  
    196196    {
    197197        this->templates_.insert(temp);
     198        if( temp->isLink() )
     199        {
     200          this->networkTemplateNames_.insert(temp->getLink());
     201          assert( !Template::getTemplate(temp->getLink())->isLink() );
     202        }
     203        else
     204          this->networkTemplateNames_.insert(temp->getName());
    198205        temp->applyOn(this);
    199206    }
  • code/branches/presentation3/src/libraries/core/BaseObject.h

    r6926 r7105  
    191191            EventState* getEventState(const std::string& name) const;
    192192
    193             std::string name_;                                 //!< The name of the object
    194             std::string oldName_;                              //!< The old name of the object
    195             mbool       bActive_;                              //!< True = the object is active
    196             mbool       bVisible_;                             //!< True = the object is visible
    197             std::string mainStateName_;
    198             Functor*    mainStateFunctor_;
     193            std::string             name_;                     //!< The name of the object
     194            std::string             oldName_;                  //!< The old name of the object
     195            mbool                   bActive_;                  //!< True = the object is active
     196            mbool                   bVisible_;                 //!< True = the object is visible
     197            std::string             mainStateName_;
     198            Functor*                mainStateFunctor_;
     199            std::set<std::string>   networkTemplateNames_;
    199200
    200201        private:
  • code/branches/presentation3/src/libraries/core/Template.h

    r6938 r7105  
    5151            inline const std::string& getLink() const
    5252                { return this->link_; }
     53            inline bool isLink() const
     54                { return this->bIsLink_; }
    5355
    5456            inline void setLoadDefaults(bool bLoadDefaults)
  • code/branches/presentation3/src/libraries/network/synchronisable/Synchronisable.h

    r6417 r7105  
    3737#include <map>
    3838#include <queue>
     39#include <set>
    3940
    4041#include "util/mbool.h"
     
    138139    Synchronisable(BaseObject* creator);
    139140    template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false);
     141    template <class T> void registerVariable(std::set<T>& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false);
    140142
    141143    void setPriority(unsigned int freq){ objectFrequency_ = freq; }
     
    181183    }
    182184  }
     185 
     186  template <class T> void Synchronisable::registerVariable( std::set<T>& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
     187  {
     188    SynchronisableVariableBase* sv;
     189    if (bidirectional)
     190      sv = new SynchronisableVariableBidirectional<std::set<T> >(variable, mode, cb);
     191    else
     192      sv = new SynchronisableVariable<std::set<T> >(variable, mode, cb);
     193    syncList.push_back(sv);
     194    stringList.push_back(sv);
     195  }
    183196
    184197  template <> _NetworkExport void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional);
     198//   template <class T> _NetworkExport void Synchronisable::registerVariable<std::set<T> >( std::set<T>& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional);
    185199
    186200
  • code/branches/presentation3/src/libraries/util/Serialise.h

    r6746 r7105  
    3838
    3939#include <cstring>
     40#include <set>
    4041#include "Math.h"
    4142#include "mbool.h"
     
    635636        return checkEquality( (unsigned char&)((mbool&)variable).getMemory(), mem );
    636637    }
     638   
     639    // =========== std::set
     640   
     641    template <class T> inline uint32_t returnSize( const std::set<T>& variable )
     642    {
     643        uint32_t tempsize = sizeof(uint32_t); // for the number of entries
     644        for( typename std::set<T>::iterator it=((std::set<T>*)(&variable))->begin(); it!=((std::set<T>*)(&variable))->end(); ++it)
     645            tempsize += returnSize( *it );
     646        return tempsize;
     647    }
     648   
     649    template <class T> inline void saveAndIncrease(  const std::set<T>& variable, uint8_t*& mem )
     650    {
     651        typename std::set<T>::const_iterator it = variable.begin();
     652        saveAndIncrease( (uint32_t)variable.size(), mem );
     653        for( ; it!=variable.end(); ++it )
     654            saveAndIncrease( *it, mem );
     655    }
     656   
     657    template <class T> inline void loadAndIncrease( const std::set<T>& variable, uint8_t*& mem )
     658    {
     659        uint32_t nrOfElements = 0;
     660        loadAndIncrease( nrOfElements, mem );
     661        typename std::set<T>::const_iterator it = variable.begin();
     662        for( uint32_t i = 0; i<nrOfElements; ++i )
     663        {
     664            T temp;
     665            loadAndIncrease(temp, mem);
     666            while( it!=variable.end() && *it!=temp )
     667            {
     668                ((std::set<T>*)(&variable))->erase(it++);
     669                ++it;
     670            }
     671            if( it==variable.end() )
     672            {
     673                ((std::set<T>*)(&variable))->insert(temp);
     674            }
     675        }
     676    }
     677   
     678    template <class T> inline bool checkEquality( const std::set<T>& variable, uint8_t* mem )
     679    {
     680        uint8_t* temp = mem;
     681        uint32_t nrOfElements;
     682        loadAndIncrease(nrOfElements, mem);
     683        if( variable.size() == nrOfElements )
     684        {
     685            T tempT;
     686            for( uint32_t i=0; i<nrOfElements; ++i )
     687            {
     688                loadAndIncrease(tempT, mem);
     689                if( variable.find(tempT) == variable.end() )
     690                {
     691                    mem = temp;
     692                    return false;
     693                }
     694            }
     695        }
     696        else
     697        {
     698            mem = temp;
     699            return false;
     700        }
     701        return true;
     702    }
    637703}
    638704
  • code/branches/presentation3/src/orxonox/Level.cc

    r7036 r7105  
    8080    void Level::registerVariables()
    8181    {
    82         registerVariable(this->xmlfilename_, VariableDirection::ToClient, new NetworkCallback<Level>(this, &Level::networkcallback_applyXMLFile));
    83         registerVariable(this->name_,        VariableDirection::ToClient, new NetworkCallback<Level>(this, &Level::changedName));
    84         registerVariable(this->description_, VariableDirection::ToClient);
     82        registerVariable(this->xmlfilename_,            VariableDirection::ToClient, new NetworkCallback<Level>(this, &Level::networkcallback_applyXMLFile));
     83        registerVariable(this->name_,                   VariableDirection::ToClient, new NetworkCallback<Level>(this, &Level::changedName));
     84        registerVariable(this->description_,            VariableDirection::ToClient);
     85        registerVariable(this->networkTemplateNames_,   VariableDirection::ToClient, new NetworkCallback<Level>(this, &Level::networkCallbackTemplatesChanged));
    8586    }
    8687
     
    9798
    9899        Loader::open(this->xmlfile_);
     100    }
     101   
     102    void Level::networkCallbackTemplatesChanged()
     103    {
     104        for( std::set<std::string>::iterator it = this->networkTemplateNames_.begin(); it!=this->networkTemplateNames_.end(); ++it )
     105        {
     106            assert(Template::getTemplate(*it));
     107            Template::getTemplate(*it)->applyOn(this);
     108        }
    99109    }
    100110
  • code/branches/presentation3/src/orxonox/Level.h

    r7039 r7105  
    6666
    6767            void addLodInfo(MeshLodInformation* object);
     68            void networkCallbackTemplatesChanged();
    6869//            const MeshLodInformation* getLodInfo(std::string meshName) const;
    6970//            MeshLodInformation* getLodInfo(unsigned int index) const;
  • code/branches/presentation3/src/orxonox/Test.cc

    r6417 r7105  
    8888    void Test::registerVariables()
    8989    {
    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 );
     90        registerVariable ( this->mySet_, VariableDirection::ToClient );
     91     
     92//         registerVariable ( u1, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::checkU1 ));
     93//         registerVariable ( u2, VariableDirection::ToServer, new NetworkCallback<Test> ( this, &Test::checkU2 ));
     94//         registerVariable ( u3, Bidirectionality::ServerMaster, new NetworkCallback<Test> ( this, &Test::checkU3 ), true );
     95//         registerVariable ( u4, Bidirectionality::ClientMaster, new NetworkCallback<Test> ( this, &Test::checkU4 ), true );
    9496   
    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 );
     97//         registerVariable ( s1, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::checkS1 ));
     98//         registerVariable ( s2, VariableDirection::ToServer, new NetworkCallback<Test> ( this, &Test::checkS2 ));
     99//         registerVariable ( s3, Bidirectionality::ServerMaster, new NetworkCallback<Test> ( this, &Test::checkS3 ), true );
     100//         registerVariable ( s4, Bidirectionality::ClientMaster, new NetworkCallback<Test> ( this, &Test::checkS4 ), true );
    99101   
    100         registerVariable ( pointer_, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::printPointer ) );
     102//         registerVariable ( pointer_, VariableDirection::ToClient, new NetworkCallback<Test> ( this, &Test::printPointer ) );
    101103    }
    102104 
  • code/branches/presentation3/src/orxonox/Test.h

    r6417 r7105  
    3535#include "tools/interfaces/Tickable.h"
    3636
     37#include <set>
    3738
    3839typedef int TYPE;
     
    7879      void printPointer();
    7980
    80       static void printV1(){ instance_->checkU1(); }
    81       static void printV2(){ instance_->checkU2(); }
     81      static void printV1(){ instance_->blub(); }
     82      static void printV2(){ instance_->blub2(); }
    8283      static void printV3(){ instance_->checkU3(); }
    8384      static void printV4(){ instance_->checkU4(); }
     
    9798
    9899      Test* pointer_;
     100     
     101      std::set<uint32_t> mySet_;
    99102
    100103      static Test* instance_;
     104     
     105      void blub()
     106      { mySet_.insert(2); }
     107     
     108      void blub2()
     109      { for( std::set<uint32_t>::iterator it=mySet_.begin(); it!=mySet_.end(); ++it ) COUT(0) << *it << endl; }
    101110  };
    102111}
Note: See TracChangeset for help on using the changeset viewer.