Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 2, 2008, 9:10:00 PM (16 years ago)
Author:
scheusso
Message:

made some adjustments mostly to the networkid (classid) in order to have it platform independent

Location:
code/branches/network64/src/network/synchronisable
Files:
7 edited

Legend:

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

    r2307 r2309  
    11SET( SRC_FILES
     2  NetworkCallbackManager.cc
    23  Synchronisable.cc
    34  SynchronisableSpecialisations.cc
  • code/branches/network64/src/network/synchronisable/NetworkCallback.h

    r2211 r2309  
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Oliver Scheuss, (C) 2008
     24 *   Co-authors:
     25 *      ...
     26 *
     27 */
     28
     29
    130#ifndef _NETWORK_CALLBACK__
    231#define _NETWORK_CALLBACK__
    332
    433#include "network/NetworkPrereqs.h"
     34#include "NetworkCallbackManager.h"
    535
    636namespace orxonox{
     37 
    738  class _NetworkExport NetworkCallbackBase
    839  {
    940    public:
    1041      virtual void call() = 0;
    11           virtual ~NetworkCallbackBase() {}
     42      NetworkCallbackBase(){ NetworkCallbackManager::registerCallback( this ); }
     43      virtual ~NetworkCallbackBase() {}
    1244  };
    1345
     
    2658  };
    2759
    28 
    2960}
    3061
  • code/branches/network64/src/network/synchronisable/Synchronisable.cc

    r2307 r2309  
    5555
    5656
    57   std::map<unsigned int, Synchronisable *> Synchronisable::objectMap_;
    58   std::queue<unsigned int> Synchronisable::deletedObjects_;
     57  std::map<uint32_t, Synchronisable *> Synchronisable::objectMap_;
     58  std::queue<uint32_t> Synchronisable::deletedObjects_;
    5959
    6060  uint8_t Synchronisable::state_=0x1; // detemines wheter we are server (default) or client
     
    7777    else
    7878      objectID=OBJECTID_UNKNOWN;
    79     classID = (unsigned int)-1;
     79    classID = static_cast<uint32_t>(-1);
    8080
    8181
     
    122122//       objectMap_.erase(objectID);
    123123    }
    124     std::map<unsigned int, Synchronisable*>::iterator it;
     124    std::map<uint32_t, Synchronisable*>::iterator it;
    125125    it = objectMap_.find(objectID);
    126126    if (it != objectMap_.end())
     
    199199   * @return true/false
    200200   */
    201   bool Synchronisable::deleteObject(unsigned int objectID){
     201  bool Synchronisable::deleteObject(uint32_t objectID){
    202202//     assert(getSynchronisable(objectID));
    203203    if(!getSynchronisable(objectID))
     
    218218   * @return pointer to the Synchronisable with the objectID
    219219   */
    220   Synchronisable* Synchronisable::getSynchronisable(unsigned int objectID){
    221     std::map<unsigned int, Synchronisable*>::iterator it1;
     220  Synchronisable* Synchronisable::getSynchronisable(uint32_t objectID){
     221    std::map<uint32_t, Synchronisable*>::iterator it1;
    222222    it1 = objectMap_.find(objectID);
    223223    if (it1 != objectMap_.end())
     
    295295   * @return true: if !doSync or if everything was successfully saved
    296296   */
    297   bool Synchronisable::getData(uint8_t*& mem, unsigned int id, uint8_t mode){
     297  bool Synchronisable::getData(uint8_t*& mem, int32_t id, uint8_t mode){
    298298    if(mode==0x0)
    299299      mode=state_;
     
    302302      return true;
    303303    //std::cout << "inside getData" << std::endl;
    304     unsigned int tempsize = 0;
     304    uint32_t tempsize = 0;
    305305    if(classID==0)
    306306      COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl;
    307307
    308     if (this->classID == (unsigned int)-1)
     308    if (this->classID == static_cast<uint32_t>(-1))
    309309        this->classID = this->getIdentifier()->getNetworkID();
    310310
     
    312312//     this->classID=this->getIdentifier()->getNetworkID(); // TODO: correct this
    313313    std::list<SynchronisableVariableBase*>::iterator i;
    314     unsigned int size;
     314    uint32_t size;
    315315    size=getSize(id, mode);
    316316
     
    384384  * @return amount of bytes
    385385  */
    386   uint32_t Synchronisable::getSize(unsigned int id, uint8_t mode){
     386  uint32_t Synchronisable::getSize(int32_t id, uint8_t mode){
    387387    int tsize=sizeof(synchronisableHeader);
    388388    if(mode==0x0)
     
    402402   * @return true/false
    403403   */
    404   bool Synchronisable::doSync(unsigned int id, uint8_t mode){
     404  bool Synchronisable::doSync(int32_t id, uint8_t mode){
    405405    if(mode==0x0)
    406406      mode=state_;
     
    408408  }
    409409
    410   bool Synchronisable::doSelection(unsigned int id){
     410  bool Synchronisable::doSelection(int32_t id){
    411411    return true; //TODO: change this
    412412    //return ( id==0 || id%objectFrequency_==objectID%objectFrequency_ ) && ((objectMode_&state_)!=0);
  • code/branches/network64/src/network/synchronisable/Synchronisable.h

    r2307 r2309  
    5353namespace orxonox
    5454{
    55   static const unsigned int OBJECTID_UNKNOWN = (unsigned int)-1;
     55  static const uint32_t OBJECTID_UNKNOWN = static_cast<uint32_t>(-1);
    5656
    5757  namespace objectDirection{
     
    8686
    8787    static Synchronisable *fabricate(uint8_t*& mem, uint8_t mode=0x0);
    88     static bool deleteObject(unsigned int objectID);
    89     static Synchronisable *getSynchronisable(unsigned int objectID);
     88    static bool deleteObject(uint32_t objectID);
     89    static Synchronisable *getSynchronisable(uint32_t objectID);
    9090    static unsigned int getNumberOfDeletedObject(){ return deletedObjects_.size(); }
    91     static unsigned int popDeletedObject(){ unsigned int i = deletedObjects_.front(); deletedObjects_.pop(); return i; }
     91    static uint32_t popDeletedObject(){ uint32_t i = deletedObjects_.front(); deletedObjects_.pop(); return i; }
    9292
    93     inline unsigned int getObjectID(){return objectID;}
    94     inline unsigned int getClassID(){return classID;}
     93    inline uint32_t getObjectID(){return objectID;}
     94    inline uint32_t getClassID(){return classID;}
    9595  protected:
    9696    Synchronisable(BaseObject* creator);
     
    103103
    104104  private:
    105     bool getData(uint8_t*& men, unsigned int id, uint8_t mode=0x0);
    106     uint32_t getSize(unsigned int id, uint8_t mode=0x0);
     105    bool getData(uint8_t*& men, int32_t id, uint8_t mode=0x0);
     106    uint32_t getSize(int32_t id, uint8_t mode=0x0);
    107107    bool updateData(uint8_t*& mem, uint8_t mode=0x0, bool forceCallback=false);
    108108    bool isMyData(uint8_t* mem);
    109     bool doSelection(unsigned int id);
    110     bool doSync(unsigned int id, uint8_t mode=0x0);
     109    bool doSelection(int32_t id);
     110    bool doSync(int32_t id, uint8_t mode=0x0);
    111111
    112     unsigned int objectID;
    113     unsigned int creatorID;
    114     unsigned int classID;
     112    uint32_t objectID;
     113    uint32_t creatorID;
     114    uint32_t classID;
    115115
    116116    std::list<SynchronisableVariableBase*> syncList;
     
    119119    unsigned int objectFrequency_;
    120120    int objectMode_;
    121     static std::map<unsigned int, Synchronisable *> objectMap_;
    122     static std::queue<unsigned int> deletedObjects_;
     121    static std::map<uint32_t, Synchronisable *> objectMap_;
     122    static std::queue<uint32_t> deletedObjects_;
    123123  };
    124124 
  • code/branches/network64/src/network/synchronisable/SynchronisableSpecialisations.cc

    r2307 r2309  
    3737  template <> void Synchronisable::registerVariable( const ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
    3838  {
    39     registerVariable(variable.r, mode, 0, bidirectional);
    40     registerVariable(variable.g, mode, 0, bidirectional);
    41     registerVariable(variable.b, mode, 0, bidirectional);
     39    registerVariable(variable.r, mode, cb, bidirectional);
     40    registerVariable(variable.g, mode, cb, bidirectional);
     41    registerVariable(variable.b, mode, cb, bidirectional);
    4242    registerVariable(variable.a, mode, cb, bidirectional);
    4343  }
     
    4949  template <> void Synchronisable::registerVariable( const Vector2& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
    5050  {
    51     registerVariable(variable.x, mode, 0, bidirectional);
     51    registerVariable(variable.x, mode, cb, bidirectional);
    5252    registerVariable(variable.y, mode, cb, bidirectional);
    5353  }
     
    5959  template <> void Synchronisable::registerVariable( const Vector3& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
    6060  {
    61     registerVariable(variable.x, mode, 0, bidirectional);
    62     registerVariable(variable.y, mode, 0, bidirectional);
     61    registerVariable(variable.x, mode, cb, bidirectional);
     62    registerVariable(variable.y, mode, cb, bidirectional);
    6363    registerVariable(variable.z, mode, cb, bidirectional);
    6464  }
     
    7070  template <> void Synchronisable::registerVariable( const Vector4& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
    7171  {
    72     registerVariable(variable.x, mode, 0, bidirectional);
    73     registerVariable(variable.y, mode, 0, bidirectional);
    74     registerVariable(variable.z, mode, 0, bidirectional);
     72    registerVariable(variable.x, mode, cb, bidirectional);
     73    registerVariable(variable.y, mode, cb, bidirectional);
     74    registerVariable(variable.z, mode, cb, bidirectional);
    7575    registerVariable(variable.w, mode, cb, bidirectional);
    7676  }
     
    8787  template <> void Synchronisable::registerVariable( const Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
    8888  {
    89     registerVariable(variable.w, mode, 0, bidirectional);
    90     registerVariable(variable.x, mode, 0, bidirectional);
    91     registerVariable(variable.y, mode, 0, bidirectional);
     89    registerVariable(variable.x, mode, cb, bidirectional);
     90    registerVariable(variable.y, mode, cb, bidirectional);
    9291    registerVariable(variable.z, mode, cb, bidirectional);
     92    registerVariable(variable.w, mode, cb, bidirectional);
    9393  }
    9494  template <> void Synchronisable::registerVariable( Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
  • code/branches/network64/src/network/synchronisable/SynchronisableVariable.cc

    r2255 r2309  
    6464}
    6565
     66// =========== char
     67
     68template <> uint32_t SynchronisableVariable<const char>::returnSize()
     69{
     70  return sizeof(uint8_t);
     71}
     72
     73template <> void SynchronisableVariable<const char>::setAndIncrease( uint8_t*& mem )
     74{
     75  *(uint8_t*)(&this->variable_) = *static_cast<uint8_t*>(mem);
     76  mem += SynchronisableVariable<const char>::returnSize();
     77}
     78
     79template <> void SynchronisableVariable<const char>::getAndIncrease( uint8_t*& mem )
     80{
     81  *static_cast<uint8_t*>(mem) = *(uint8_t*)(&this->variable_);
     82  mem += SynchronisableVariable<const char>::returnSize();
     83}
     84
     85template <> bool SynchronisableVariable<const char>::checkEquality( uint8_t* mem )
     86{
     87  return *static_cast<uint8_t*>(mem) == *(uint8_t*)(&this->variable_);
     88}
     89
    6690// =========== unsigned char
    6791
  • code/branches/network64/src/network/synchronisable/SynchronisableVariable.h

    r2307 r2309  
    3939#include "core/CoreIncludes.h"
    4040#include "network/synchronisable/NetworkCallback.h"
     41#include "network/synchronisable/NetworkCallbackManager.h"
    4142
    4243namespace orxonox{
     
    119120  {
    120121    if (this->callback_ != 0)
    121       delete this->callback_;
     122      NetworkCallbackManager::deleteCallback(this->callback_); //safe call for deletion
    122123  }
    123124
     
    146147  // now do a callback if neccessary
    147148    if ( callback )
    148       this->callback_->call();
     149      NetworkCallbackManager::triggerCallback( this->callback_ );
     150      //this->callback_->call();
    149151  }
    150152
     
    299301  // now do a callback if neccessary
    300302      if ( callback )
    301         this->callback_->call();
     303        NetworkCallbackManager::triggerCallback( this->callback_ );
     304        //this->callback_->call();
    302305    }
    303306
Note: See TracChangeset for help on using the changeset viewer.