Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 28, 2009, 11:19:06 PM (16 years ago)
Author:
scheusso
Message:
  • moved serialise functions from SynchronisableVariableSpecialisation.cc

to util/Serialise.h

  • made MultiType serialisable (use functions importData/exportData or

operator << / >> )

Location:
code/branches/netp2/src
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/netp2/src/network/synchronisable/SynchronisableSpecialisations.cc

    r2836 r2861  
    7171    registerVariable(variable.y, mode, cb, bidirectional);
    7272  }
    73   template <> void Synchronisable::registerVariable( Vector2& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
    74   {
    75     registerVariable( (const ColourValue&)variable, mode, cb, bidirectional);
    76   }
     73//   template <> void Synchronisable::registerVariable( Vector2& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
     74//   {
     75//     registerVariable( (const ColourValue&)variable, mode, cb, bidirectional);
     76//   }
    7777 
    7878  template <> void Synchronisable::registerVariable( const Vector3& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
  • code/branches/netp2/src/network/synchronisable/SynchronisableVariable.h

    r2836 r2861  
    2121 *
    2222 *   Author:
    23  *      Oliver Scheuss, (C) 2008
     23 *      Oliver Scheuss
    2424 *   Co-authors:
    2525 *      ...
     
    3535#include <string>
    3636#include <cassert>
     37#include "util/Serialise.h"
    3738#include "core/Core.h"
    3839#include "core/CoreIncludes.h"
     
    7980      virtual inline void* getReference(){ return (void *)&this->variable_; }
    8081    protected:
    81       inline bool checkEquality(uint8_t* mem);
    82       inline void setAndIncrease(uint8_t*& mem);
    83       inline void getAndIncrease(uint8_t*& mem);
    84       inline uint32_t returnSize();
     82//       inline bool checkEquality(uint8_t* mem);
     83//       inline void loadAndIncrease(uint8_t*& mem);
     84//       inline void saveAndIncrease(uint8_t*& mem);
     85//       inline uint32_t returnSize();
    8586     
    8687      T& variable_;
     
    126127    if ( state_ == this->mode_ )
    127128    {
    128       getAndIncrease( mem );
    129       return returnSize();
     129      saveAndIncrease( this->variable_, mem );
     130      return returnSize( this->variable_ );
    130131    }
    131132    else
     
    143144    if ( this->callback_ != 0 )
    144145    {
    145       if( forceCallback || !checkEquality( mem ) )
     146      if( forceCallback || !checkEquality( this->variable_, mem ) )
    146147        callback = true;
    147148    }
    148149  // write the data
    149     setAndIncrease( mem );
     150    loadAndIncrease( this->variable_, mem );
    150151  // now do a callback if neccessary
    151152    if ( callback )
     
    156157  {
    157158    if ( mode == this->mode_ )
    158       return returnSize();
     159      return returnSize( this->variable_ );
    159160    else
    160161      return 0;
    161162  }
    162163
    163   template <> _NetworkExport uint32_t SynchronisableVariable<const bool>::returnSize();
    164   template <> _NetworkExport void     SynchronisableVariable<const bool>::setAndIncrease(uint8_t*& mem);
    165   template <> _NetworkExport void     SynchronisableVariable<const bool>::getAndIncrease(uint8_t*& mem);
     164  /*template <> _NetworkExport uint32_t SynchronisableVariable<const bool>::returnSize();
     165  template <> _NetworkExport void     SynchronisableVariable<const bool>::loadAndIncrease(uint8_t*& mem);
     166  template <> _NetworkExport void     SynchronisableVariable<const bool>::saveAndIncrease(uint8_t*& mem);
    166167  template <> _NetworkExport bool     SynchronisableVariable<const bool>::checkEquality(uint8_t* mem);
    167168  template <> _NetworkExport uint32_t SynchronisableVariable<const unsigned char>::returnSize();
    168   template <> _NetworkExport void     SynchronisableVariable<const unsigned char>::setAndIncrease(uint8_t*& mem);
    169   template <> _NetworkExport void     SynchronisableVariable<const unsigned char>::getAndIncrease(uint8_t*& mem);
     169  template <> _NetworkExport void     SynchronisableVariable<const unsigned char>::loadAndIncrease(uint8_t*& mem);
     170  template <> _NetworkExport void     SynchronisableVariable<const unsigned char>::saveAndIncrease(uint8_t*& mem);
    170171  template <> _NetworkExport bool     SynchronisableVariable<const unsigned char>::checkEquality(uint8_t* mem);
    171172  template <> _NetworkExport uint32_t SynchronisableVariable<const short>::returnSize();
    172   template <> _NetworkExport void     SynchronisableVariable<const short>::setAndIncrease(uint8_t*& mem);
    173   template <> _NetworkExport void     SynchronisableVariable<const short>::getAndIncrease(uint8_t*& mem);
     173  template <> _NetworkExport void     SynchronisableVariable<const short>::loadAndIncrease(uint8_t*& mem);
     174  template <> _NetworkExport void     SynchronisableVariable<const short>::saveAndIncrease(uint8_t*& mem);
    174175  template <> _NetworkExport bool     SynchronisableVariable<const short>::checkEquality(uint8_t* mem);
    175176  template <> _NetworkExport uint32_t SynchronisableVariable<const unsigned short>::returnSize();
    176   template <> _NetworkExport void     SynchronisableVariable<const unsigned short>::setAndIncrease(uint8_t*& mem);
    177   template <> _NetworkExport void     SynchronisableVariable<const unsigned short>::getAndIncrease(uint8_t*& mem);
     177  template <> _NetworkExport void     SynchronisableVariable<const unsigned short>::loadAndIncrease(uint8_t*& mem);
     178  template <> _NetworkExport void     SynchronisableVariable<const unsigned short>::saveAndIncrease(uint8_t*& mem);
    178179  template <> _NetworkExport bool     SynchronisableVariable<const unsigned short>::checkEquality(uint8_t* mem);
    179180  template <> _NetworkExport uint32_t SynchronisableVariable<const int>::returnSize();
    180   template <> _NetworkExport void     SynchronisableVariable<const int>::setAndIncrease(uint8_t*& mem);
    181   template <> _NetworkExport void     SynchronisableVariable<const int>::getAndIncrease(uint8_t*& mem);
     181  template <> _NetworkExport void     SynchronisableVariable<const int>::loadAndIncrease(uint8_t*& mem);
     182  template <> _NetworkExport void     SynchronisableVariable<const int>::saveAndIncrease(uint8_t*& mem);
    182183  template <> _NetworkExport bool     SynchronisableVariable<const int>::checkEquality(uint8_t* mem);
    183184  template <> _NetworkExport uint32_t SynchronisableVariable<const unsigned int>::returnSize();
    184   template <> _NetworkExport void     SynchronisableVariable<const unsigned int>::setAndIncrease(uint8_t*& mem);
    185   template <> _NetworkExport void     SynchronisableVariable<const unsigned int>::getAndIncrease(uint8_t*& mem);
     185  template <> _NetworkExport void     SynchronisableVariable<const unsigned int>::loadAndIncrease(uint8_t*& mem);
     186  template <> _NetworkExport void     SynchronisableVariable<const unsigned int>::saveAndIncrease(uint8_t*& mem);
    186187  template <> _NetworkExport bool     SynchronisableVariable<const unsigned int>::checkEquality(uint8_t* mem);
    187188  template <> _NetworkExport uint32_t SynchronisableVariable<const long>::returnSize();
    188   template <> _NetworkExport void     SynchronisableVariable<const long>::setAndIncrease(uint8_t*& mem);
    189   template <> _NetworkExport void     SynchronisableVariable<const long>::getAndIncrease(uint8_t*& mem);
     189  template <> _NetworkExport void     SynchronisableVariable<const long>::loadAndIncrease(uint8_t*& mem);
     190  template <> _NetworkExport void     SynchronisableVariable<const long>::saveAndIncrease(uint8_t*& mem);
    190191  template <> _NetworkExport bool     SynchronisableVariable<const long>::checkEquality(uint8_t* mem);
    191192  template <> _NetworkExport uint32_t SynchronisableVariable<const unsigned long>::returnSize();
    192   template <> _NetworkExport void     SynchronisableVariable<const unsigned long>::setAndIncrease(uint8_t*& mem);
    193   template <> _NetworkExport void     SynchronisableVariable<const unsigned long>::getAndIncrease(uint8_t*& mem);
     193  template <> _NetworkExport void     SynchronisableVariable<const unsigned long>::loadAndIncrease(uint8_t*& mem);
     194  template <> _NetworkExport void     SynchronisableVariable<const unsigned long>::saveAndIncrease(uint8_t*& mem);
    194195  template <> _NetworkExport bool     SynchronisableVariable<const unsigned long>::checkEquality(uint8_t* mem);
    195196  template <> _NetworkExport uint32_t SynchronisableVariable<const long long>::returnSize();
    196   template <> _NetworkExport void     SynchronisableVariable<const long long>::setAndIncrease(uint8_t*& mem);
    197   template <> _NetworkExport void     SynchronisableVariable<const long long>::getAndIncrease(uint8_t*& mem);
     197  template <> _NetworkExport void     SynchronisableVariable<const long long>::loadAndIncrease(uint8_t*& mem);
     198  template <> _NetworkExport void     SynchronisableVariable<const long long>::saveAndIncrease(uint8_t*& mem);
    198199  template <> _NetworkExport bool     SynchronisableVariable<const long long>::checkEquality(uint8_t* mem);
    199200  template <> _NetworkExport uint32_t SynchronisableVariable<const unsigned long long>::returnSize();
    200   template <> _NetworkExport void     SynchronisableVariable<const unsigned long long>::setAndIncrease(uint8_t*& mem);
    201   template <> _NetworkExport void     SynchronisableVariable<const unsigned long long>::getAndIncrease(uint8_t*& mem);
     201  template <> _NetworkExport void     SynchronisableVariable<const unsigned long long>::loadAndIncrease(uint8_t*& mem);
     202  template <> _NetworkExport void     SynchronisableVariable<const unsigned long long>::saveAndIncrease(uint8_t*& mem);
    202203  template <> _NetworkExport bool     SynchronisableVariable<const unsigned long long>::checkEquality(uint8_t* mem);
    203204  template <> _NetworkExport uint32_t SynchronisableVariable<const float>::returnSize();
    204   template <> _NetworkExport void     SynchronisableVariable<const float>::setAndIncrease(uint8_t*& mem);
    205   template <> _NetworkExport void     SynchronisableVariable<const float>::getAndIncrease(uint8_t*& mem);
     205  template <> _NetworkExport void     SynchronisableVariable<const float>::loadAndIncrease(uint8_t*& mem);
     206  template <> _NetworkExport void     SynchronisableVariable<const float>::saveAndIncrease(uint8_t*& mem);
    206207  template <> _NetworkExport bool     SynchronisableVariable<const float>::checkEquality(uint8_t* mem);
    207208  template <> _NetworkExport uint32_t SynchronisableVariable<const double>::returnSize();
    208   template <> _NetworkExport void     SynchronisableVariable<const double>::setAndIncrease(uint8_t*& mem);
    209   template <> _NetworkExport void     SynchronisableVariable<const double>::getAndIncrease(uint8_t*& mem);
     209  template <> _NetworkExport void     SynchronisableVariable<const double>::loadAndIncrease(uint8_t*& mem);
     210  template <> _NetworkExport void     SynchronisableVariable<const double>::saveAndIncrease(uint8_t*& mem);
    210211  template <> _NetworkExport bool     SynchronisableVariable<const double>::checkEquality(uint8_t* mem);
    211212  template <> _NetworkExport uint32_t SynchronisableVariable<const long double>::returnSize();
    212   template <> _NetworkExport void     SynchronisableVariable<const long double>::setAndIncrease(uint8_t*& mem);
    213   template <> _NetworkExport void     SynchronisableVariable<const long double>::getAndIncrease(uint8_t*& mem);
     213  template <> _NetworkExport void     SynchronisableVariable<const long double>::loadAndIncrease(uint8_t*& mem);
     214  template <> _NetworkExport void     SynchronisableVariable<const long double>::saveAndIncrease(uint8_t*& mem);
    214215  template <> _NetworkExport bool     SynchronisableVariable<const long double>::checkEquality(uint8_t* mem);
    215216  template <> _NetworkExport uint32_t SynchronisableVariable<const std::string>::returnSize();
    216   template <> _NetworkExport void     SynchronisableVariable<const std::string>::setAndIncrease(uint8_t*& mem);
    217   template <> _NetworkExport void     SynchronisableVariable<const std::string>::getAndIncrease(uint8_t*& mem);
     217  template <> _NetworkExport void     SynchronisableVariable<const std::string>::loadAndIncrease(uint8_t*& mem);
     218  template <> _NetworkExport void     SynchronisableVariable<const std::string>::saveAndIncrease(uint8_t*& mem);
    218219  template <> _NetworkExport bool     SynchronisableVariable<const std::string>::checkEquality(uint8_t* mem);
    219220  template <> _NetworkExport uint32_t SynchronisableVariable<const Degree>::returnSize();
    220   template <> _NetworkExport void     SynchronisableVariable<const Degree>::setAndIncrease(uint8_t*& mem);
    221   template <> _NetworkExport void     SynchronisableVariable<const Degree>::getAndIncrease(uint8_t*& mem);
    222   template <> _NetworkExport bool     SynchronisableVariable<const Degree>::checkEquality(uint8_t* mem);
     221  template <> _NetworkExport void     SynchronisableVariable<const Degree>::loadAndIncrease(uint8_t*& mem);
     222  template <> _NetworkExport void     SynchronisableVariable<const Degree>::saveAndIncrease(uint8_t*& mem);
     223  template <> _NetworkExport bool     SynchronisableVariable<const Degree>::checkEquality(uint8_t* mem);*/
    223224
    224225
     
    249250      mem += sizeof(this->varReference_);
    250251  // now write the content
    251       SynchronisableVariable<T>::getAndIncrease( mem );
     252      saveAndIncrease( this->variable_, mem );
    252253//   mem += SynchronisableVariable<T>::getSize();
    253254      return SynchronisableVariableBidirectional::getSize(mode);
     
    268269          // apply data
    269270          mem += sizeof(varReference_);
    270           if ( SynchronisableVariableBidirectional<T>::checkEquality( mem )==true )
     271          if ( checkEquality( this->variable_, mem )==true )
    271272          {
    272             mem += SynchronisableVariable<T>::getSize( mode );
     273            mem += getSize( mode );
    273274            return;
    274275          }
     
    292293          this->varReference_ = *static_cast<uint8_t*>(mem);
    293294          mem += sizeof(varReference_);
    294           if ( SynchronisableVariable<T>::checkEquality( mem ) == false )
     295          if ( checkEquality( this->variable_, mem ) == false )
    295296          {
    296297            // value changed so remark for callback
     
    301302      }
    302303  // now write the data
    303       SynchronisableVariable<T>::setAndIncrease(mem);
     304      loadAndIncrease(this->variable_, mem);
    304305  // now do a callback if neccessary
    305306      if ( callback )
     
    310311    template <class T> inline uint32_t SynchronisableVariableBidirectional<T>::getSize(uint8_t mode)
    311312    {
    312       return SynchronisableVariable<T>::returnSize() + sizeof(varReference_);
     313      return returnSize( this->variable_ ) + sizeof(varReference_);
    313314    }
    314315 
     
    316317}
    317318
    318 #include "network/synchronisable/SynchronisableVariableSpecialisations.h"
     319//#include "network/synchronisable/SynchronisableVariableSpecialisations.h"
    319320
    320321#endif
  • code/branches/netp2/src/util/MultiType.h

    r2662 r2861  
    223223
    224224            virtual void toString(std::ostream& outstream) const = 0;
     225           
     226            virtual void importData( uint8_t*& mem )=0;
     227            virtual void exportData( uint8_t*& mem ) const=0;
     228            virtual uint8_t getSize() const=0;
    225229
    226230            MT_Type type_;          //!< The type of the current value
     
    320324            template <typename T> inline bool isType()                  const { return false; } // Only works for specialized values - see below
    321325            std::string                       getTypename()             const;
     326           
     327            /** @brief Saves the value of the MT to a bytestream (pointed at by mem) and increases mem pointer by size of MT */
     328            inline void                       importData(uint8_t*& mem) { assert(sizeof(MT_Type)<=8); *(uint8_t*)(mem) = this->getType(); mem+=sizeof(uint8_t); this->value_->importData(mem); }
     329            /** @brief Loads the value of the MT from a bytestream (pointed at by mem) and increases mem pointer by size of MT */
     330            inline void                       exportData(uint8_t*& mem) { assert(sizeof(MT_Type)<=8); this->setType(*(uint8_t*)mem); mem+=sizeof(uint8_t); this->value_->exportData(mem); }
     331            /** @brief Saves the value of the MT to a bytestream and increases pointer to bytestream by size of MT */
     332            inline uint8_t*& operator << (uint8_t*& mem) { importData(mem); return mem; }
     333            /** @brief Loads the value of the MT to a bytestream and increases pointer to bytestream by size of MT */
     334            inline void operator >> (uint8_t*& mem) { exportData(mem); }
    322335
    323336            /** @brief Checks whether the value is a default one. */
  • code/branches/netp2/src/util/MultiTypeValue.h

    r2171 r2861  
    4040#include "MathConvert.h"
    4141#include "MultiType.h"
     42#include "Serialise.h"
     43#include <cassert>
    4244
    4345namespace orxonox
     
    147149        /** @brief Puts the current value on the stream */
    148150        inline void toString(std::ostream& outstream) const { outstream << this->value_; }
     151       
     152        /** @brief loads data from the bytestream (mem) into the MT and increases the bytestream pointer by the size of the data */
     153        inline void importData( uint8_t*& mem )         { loadAndIncrease( /*(const T&)*/this->value_, mem ); }
     154        /** @brief saves data from the MT into the bytestream (mem) and increases the bytestream pointer by the size of the data */
     155        inline void exportData( uint8_t*& mem ) const   { saveAndIncrease( /*(const T&)*/this->value_, mem ); }
     156        /** @brief returns the size of the data that would be saved by exportData */
     157        inline uint8_t getSize() const { return returnSize( this->value_ ); }
    149158
    150159        T value_; //!< The stored value
    151160    };
     161   
     162    // Import / Export specialisation
     163    // ColourValue
     164    template <> inline void MT_Value<ColourValue>::importData( uint8_t*& mem )
     165    {
     166        loadAndIncrease( this->value_.r, mem );
     167        loadAndIncrease( this->value_.g, mem );
     168        loadAndIncrease( this->value_.b, mem );
     169        loadAndIncrease( this->value_.a, mem );
     170    }
     171    template <> inline void MT_Value<ColourValue>::exportData( uint8_t*& mem ) const
     172    {
     173        saveAndIncrease( this->value_.r, mem );
     174        saveAndIncrease( this->value_.g, mem );
     175        saveAndIncrease( this->value_.b, mem );
     176        saveAndIncrease( this->value_.a, mem );
     177    }
     178    template <> inline uint8_t MT_Value<ColourValue>::getSize() const
     179    {
     180        return 4*returnSize(this->value_.r);
     181    }
     182    // Ogre::Quaternion
     183    template <> inline void MT_Value<Ogre::Quaternion>::importData( uint8_t*& mem )
     184    {
     185        loadAndIncrease( this->value_.x, mem );
     186        loadAndIncrease( this->value_.y, mem );
     187        loadAndIncrease( this->value_.z, mem );
     188        loadAndIncrease( this->value_.w, mem );
     189    }
     190    template <> inline void MT_Value<Ogre::Quaternion>::exportData( uint8_t*& mem ) const
     191    {
     192        saveAndIncrease( this->value_.x, mem );
     193        saveAndIncrease( this->value_.y, mem );
     194        saveAndIncrease( this->value_.z, mem );
     195        saveAndIncrease( this->value_.w, mem );
     196    }template <> inline uint8_t MT_Value<Ogre::Quaternion>::getSize() const
     197    {
     198        return 4*returnSize(this->value_.x);
     199    }
     200    // Ogre::Vector2
     201    template <> inline void MT_Value<Ogre::Vector2>::importData( uint8_t*& mem )
     202    {
     203        loadAndIncrease( this->value_.x, mem );
     204        loadAndIncrease( this->value_.y, mem );
     205    }
     206    template <> inline void MT_Value<Ogre::Vector2>::exportData( uint8_t*& mem ) const
     207    {
     208        saveAndIncrease( this->value_.x, mem );
     209        saveAndIncrease( this->value_.y, mem );
     210    }
     211    template <> inline uint8_t MT_Value<Ogre::Vector2>::getSize() const
     212    {
     213        return 2*returnSize(this->value_.x);
     214    }
     215    // Ogre::Vector3
     216    template <> inline void MT_Value<Ogre::Vector3>::importData( uint8_t*& mem )
     217    {
     218        loadAndIncrease( this->value_.x, mem );
     219        loadAndIncrease( this->value_.y, mem );
     220        loadAndIncrease( this->value_.z, mem );
     221    }
     222    template <> inline void MT_Value<Ogre::Vector3>::exportData( uint8_t*& mem ) const
     223    {
     224        saveAndIncrease( this->value_.x, mem );
     225        saveAndIncrease( this->value_.y, mem );
     226        saveAndIncrease( this->value_.z, mem );
     227    }
     228    template <> inline uint8_t MT_Value<Ogre::Vector3>::getSize() const
     229    {
     230        return 3*returnSize(this->value_.x);
     231    }
     232    // Ogre::Vector4
     233    template <> inline void MT_Value<Ogre::Vector4>::importData( uint8_t*& mem )
     234    {
     235        loadAndIncrease( this->value_.x, mem );
     236        loadAndIncrease( this->value_.y, mem );
     237        loadAndIncrease( this->value_.z, mem );
     238        loadAndIncrease( this->value_.w, mem );
     239    }
     240    template <> inline void MT_Value<Ogre::Vector4>::exportData( uint8_t*& mem ) const
     241    {
     242        saveAndIncrease( this->value_.x, mem );
     243        saveAndIncrease( this->value_.y, mem );
     244        saveAndIncrease( this->value_.z, mem );
     245        saveAndIncrease( this->value_.w, mem );
     246    }
     247    template <> inline uint8_t MT_Value<Ogre::Vector4>::getSize() const
     248    {
     249        return 4*returnSize(this->value_.x);
     250    }
     251    template <> inline void MT_Value<void*>::importData( uint8_t*& mem )
     252    {
     253        assert(0);
     254    }
     255    template <> inline void MT_Value<void*>::exportData( uint8_t*& mem ) const
     256    {
     257        assert(0);
     258    }
     259    template <> inline uint8_t MT_Value<void*>::getSize() const
     260    {
     261        assert(0); return 0;
     262    }
    152263}
    153264
Note: See TracChangeset for help on using the changeset viewer.