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
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network64/src/network/GamestateClient.cc

    r2211 r2309  
    3636#include "core/Iterator.h"
    3737#include "synchronisable/Synchronisable.h"
     38#include "synchronisable/NetworkCallbackManager.h"
    3839#include "packet/Acknowledgement.h"
    3940
     
    7778    packet::Gamestate *processed = processGamestate(tempGamestate_);
    7879//    assert(processed);
     80   
     81    //now call the queued callbacks
     82    NetworkCallbackManager::callCallbacks();
     83   
    7984    if (!processed)
    8085        return false;
  • code/branches/network64/src/network/GamestateManager.cc

    r2211 r2309  
    5050#include "ClientInformation.h"
    5151#include "synchronisable/Synchronisable.h"
     52#include "synchronisable/NetworkCallbackManager.h"
    5253
    5354namespace orxonox
     
    8687    // now clear the queue
    8788    gamestateQueue.clear();
     89    //and call all queued callbacks
     90    NetworkCallbackManager::callCallbacks();
    8891    return true;
    8992  }
  • code/branches/network64/src/network/NetworkPrereqs.h

    r2245 r2309  
    7171  class GamestateHandler;
    7272  class NetworkCallbackBase;
     73  template <class T> class NetworkCallback;
     74  class NetworkCallbackManager;
    7375  class PacketBuffer;
    7476  class Server;
  • code/branches/network64/src/network/packet/Gamestate.cc

    r2171 r2309  
    7373bool Gamestate::collectData(int id, uint8_t mode)
    7474{
    75   unsigned int tempsize=0, currentsize=0;
     75  uint32_t tempsize=0, currentsize=0;
    7676  assert(data_==0);
    77   unsigned int size = calcGamestateSize(id, mode);
     77  uint32_t size = calcGamestateSize(id, mode);
    7878
    7979  COUT(4) << "G.ST.Man: producing gamestate with id: " << id << std::endl;
     
    166166}
    167167
    168 unsigned int Gamestate::getSize() const
     168uint32_t Gamestate::getSize() const
    169169{
    170170  assert(data_);
     
    251251  assert(HEADER->compressed);
    252252  COUT(4) << "GameStateClient: uncompressing gamestate. id: " << HEADER->id << ", baseid: " << HEADER->base_id << ", datasize: " << HEADER->datasize << ", compsize: " << HEADER->compsize << std::endl;
    253   unsigned int datasize = HEADER->datasize;
    254   unsigned int compsize = HEADER->compsize;
    255   unsigned int bufsize;
     253  uint32_t datasize = HEADER->datasize;
     254  uint32_t compsize = HEADER->compsize;
     255  uint32_t bufsize;
    256256//  assert(compsize<=datasize);
    257257  bufsize = datasize;
     
    302302  //unsigned char *basep = base->getGs()/*, *gs = getGs()*/;
    303303  uint8_t *basep = GAMESTATE_START(base->data_), *gs = GAMESTATE_START(this->data_);
    304   unsigned int of=0; // pointers offset
    305   unsigned int dest_length=0;
     304  uint32_t of=0; // pointers offset
     305  uint32_t dest_length=0;
    306306  dest_length=HEADER->datasize;
    307307  if(dest_length==0)
     
    334334Gamestate* Gamestate::doSelection(unsigned int clientID){
    335335  assert(data_);
    336   std::map<unsigned int, Synchronisable *>::iterator it;
     336  std::map<uint32_t, Synchronisable *>::iterator it;
    337337
    338338  // allocate memory for new data
     
    347347
    348348  synchronisableHeader *oldobjectheader, *newobjectheader;
    349   unsigned int objectOffset;
     349  uint32_t objectOffset;
    350350
    351351  //copy in the zeros
     
    353353    oldobjectheader = (synchronisableHeader*)origdata;
    354354    newobjectheader = (synchronisableHeader*)newdata;
    355     unsigned int objectsize = oldobjectheader->size;
     355    uint32_t objectsize = oldobjectheader->size;
    356356    assert(it->second->objectID==oldobjectheader->objectID);
    357357    *newobjectheader = *oldobjectheader;
     
    382382
    383383  //preparations
    384   std::map<unsigned int, Synchronisable *>::iterator it;
     384  std::map<uint32_t, Synchronisable *>::iterator it;
    385385  uint8_t *origdata, *basedata, *destdata, *ndata;
    386   unsigned int objectOffset, streamOffset=0;    //data offset
    387   unsigned int minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize;
     386  uint32_t objectOffset, streamOffset=0;    //data offset
     387  uint32_t minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize;
    388388  synchronisableHeader *origheader;
    389389  synchronisableHeader *destheader;
     
    402402
    403403    //copy and partially diff the object header
    404     assert(sizeof(synchronisableHeader)==3*sizeof(unsigned int)+sizeof(bool));
     404    assert(sizeof(synchronisableHeader)==3*sizeof(uint32_t)+sizeof(bool));
    405405    *(uint32_t*)destdata = *(uint32_t*)origdata; //size (do not diff)
    406406    *(bool*)(destdata+sizeof(uint32_t)) = sendData;
     
    450450
    451451  //preparations
    452   std::map<unsigned int, Synchronisable *>::iterator it;
     452  std::map<uint32_t, Synchronisable *>::iterator it;
    453453  uint8_t *origdata, *basedata, *destdata, *ndata;
    454   unsigned int objectOffset, streamOffset=0;    //data offset
    455   unsigned int minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize;
     454  uint32_t objectOffset, streamOffset=0;    //data offset
     455  uint32_t minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize;
    456456  synchronisableHeader *origheader;
    457457  synchronisableHeader *destheader;
     
    470470
    471471    //copy and partially diff the object header
    472     assert(sizeof(synchronisableHeader)==3*sizeof(unsigned int)+sizeof(bool));
    473     *(unsigned int*)destdata = *(unsigned int*)origdata; //size (do not diff)
    474     *(bool*)(destdata+sizeof(unsigned int)) = *(bool*)(origdata+sizeof(unsigned int));
    475     sendData = *(bool*)(origdata+sizeof(unsigned int));
     472    assert(sizeof(synchronisableHeader)==3*sizeof(uint32_t)+sizeof(bool));
     473    *(uint32_t*)destdata = *(uint32_t*)origdata; //size (do not diff)
     474    *(bool*)(destdata+sizeof(uint32_t)) = *(bool*)(origdata+sizeof(uint32_t));
     475    sendData = *(bool*)(origdata+sizeof(uint32_t));
    476476    if(sendData){
    477       *(unsigned int*)(destdata+sizeof(unsigned int)+sizeof(bool)) = *(unsigned int*)(basedata+sizeof(unsigned int)+sizeof(bool)) ^ *(unsigned int*)(origdata+sizeof(unsigned int)+sizeof(bool)); //objectid (diff it)
    478       *(unsigned int*)(destdata+2*sizeof(unsigned int)+sizeof(bool)) = *(unsigned int*)(basedata+2*sizeof(unsigned int)+sizeof(bool)) ^ *(unsigned int*)(origdata+2*sizeof(unsigned int)+sizeof(bool)); //classid (diff it)
     477      *(uint32_t*)(destdata+sizeof(uint32_t)+sizeof(bool)) = *(uint32_t*)(basedata+sizeof(uint32_t)+sizeof(bool)) ^ *(uint32_t*)(origdata+sizeof(uint32_t)+sizeof(bool)); //objectid (diff it)
     478      *(uint32_t*)(destdata+2*sizeof(uint32_t)+sizeof(bool)) = *(uint32_t*)(basedata+2*sizeof(uint32_t)+sizeof(bool)) ^ *(uint32_t*)(origdata+2*sizeof(uint32_t)+sizeof(bool)); //classid (diff it)
    479479    }else{
    480       *(unsigned int*)(destdata+sizeof(unsigned int)+sizeof(bool)) = 0;
    481       *(unsigned int*)(destdata+2*sizeof(unsigned int)+sizeof(bool)) = 0;
     480      *(uint32_t*)(destdata+sizeof(uint32_t)+sizeof(bool)) = 0;
     481      *(uint32_t*)(destdata+2*sizeof(uint32_t)+sizeof(bool)) = 0;
    482482    }
    483483    objectOffset=sizeof(synchronisableHeader);
     
    517517  uint8_t *basep = GAMESTATE_START(base->data_);
    518518  uint8_t *gs = GAMESTATE_START(this->data_);
    519   unsigned int of=0; // pointers offset
    520   unsigned int dest_length=0;
     519  uint32_t of=0; // pointers offset
     520  uint32_t dest_length=0;
    521521  dest_length=HEADER->datasize;
    522522  if(dest_length==0)
     
    548548
    549549
    550 unsigned int Gamestate::calcGamestateSize(unsigned int id, uint8_t mode)
    551 {
    552   unsigned int size=0;
     550uint32_t Gamestate::calcGamestateSize(int32_t id, uint8_t mode)
     551{
     552  uint32_t size=0;
    553553    // get the start of the Synchronisable list
    554554  ObjectList<Synchronisable>::iterator it;
  • code/branches/network64/src/network/packet/Gamestate.h

    r2211 r2309  
    8585    // Packet functions
    8686  private:
    87     virtual unsigned int getSize() const;
     87    virtual uint32_t getSize() const;
    8888    virtual bool process();
    8989
    9090    bool operator ==(packet::Gamestate gs);
    9191  private:
    92     unsigned int calcGamestateSize(unsigned int id, uint8_t mode=0x0);
     92    uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0);
    9393    void removeObject(ObjectListIterator<Synchronisable> &it);
    94     std::map<unsigned int, Synchronisable*> dataMap_;
     94    std::map<uint32_t, Synchronisable*> dataMap_;
    9595};
    9696
  • 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.