Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2836 for code/branches


Ignore:
Timestamp:
Mar 23, 2009, 5:00:54 PM (16 years ago)
Author:
scheusso
Message:

merge old netp branch to netp2 (still because of multiplayer pong…)

Location:
code/branches/netp2/src
Files:
2 added
14 edited

Legend:

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

    r2773 r2836  
    4242#include <enet/enet.h>
    4343#include <iostream>
     44#include <cassert>
    4445// boost.thread library for multithreading support
    4546#include <boost/thread/thread.hpp>
     
    166167        if(enet_host_service(client, event, NETWORK_CLIENT_WAIT_TIME)<0){
    167168          // we should never reach this point
     169                assert(0);
    168170          quit=true;
    169171          continue;
     
    206208    boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
    207209    enet_peer_disconnect(server, 0);
    208     while(enet_host_service(client, &event, NETWORK_CLIENT_WAIT_TIME) > 0){
     210    while(enet_host_service(client, &event, NETWORK_CLIENT_WAIT_TIME) >= 0){
    209211      switch (event.type)
    210212      {
  • code/branches/netp2/src/network/ClientConnection.h

    r2773 r2836  
    5353    const int NETWORK_PORT = 55556;
    5454    const int NETWORK_CLIENT_MAX_CONNECTIONS = 5;
    55     const int NETWORK_CLIENT_WAIT_TIME = 1;
    56     const int NETWORK_CLIENT_CONNECT_TIMEOUT = 3000; // miliseconds
     55    const int NETWORK_CLIENT_WAIT_TIME = 10;
     56    const int NETWORK_CLIENT_CONNECT_TIMEOUT = 10000; // miliseconds
    5757    const int NETWORK_CLIENT_CHANNELS = 2;
    5858
  • code/branches/netp2/src/network/ConnectionManager.cc

    r2773 r2836  
    5757{
    5858  bool operator< (ENetAddress a, ENetAddress b) {
    59     if(a.host <= b.host)
    60       return true;
    61     else
    62       return false;
     59    return a.host <= b.host;
    6360  }
    6461}
     
    198195        if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){
    199196          // we should never reach this point
     197          assert(0);
    200198          quit=true;
    201199          continue;
     
    214212        case ENET_EVENT_TYPE_NONE:
    215213          //receiverThread_->yield();
    216           msleep(1);
     214          msleep(10);
    217215          break;
    218216      }
     
    266264  }
    267265
    268   bool ConnectionManager::processData(ENetEvent *event) {
    269     // just add packet to the buffer
    270     // this can be extended with some preprocessing
    271     return buffer.push(event);
    272   }
    273 
    274 
    275266
    276267  int ConnectionManager::getClientID(ENetPeer* peer) {
  • code/branches/netp2/src/network/ConnectionManager.h

    r2773 r2836  
    5555    const int NETWORK_PORT = 55556;
    5656    const int NETWORK_MAX_CONNECTIONS = 50;
    57     const int NETWORK_WAIT_TIMEOUT = 1;
     57    const int NETWORK_WAIT_TIMEOUT = 10;
    5858    const int NETWORK_DEFAULT_CHANNEL = 0;
    5959
     
    8484  private:
    8585    ConnectionManager(const ConnectionManager& copy); // not used
    86     bool processData(ENetEvent *event);
     86    inline bool processData(ENetEvent *event){ return buffer.push(event); }
    8787    void receiverThread();
    8888    void disconnectClients();
  • code/branches/netp2/src/network/TrafficControl.cc

    r2662 r2836  
    9090  void TrafficControl::setConfigValues()
    9191  {
    92     SetConfigValue ( bActive_, true );
    93     SetConfigValue ( targetSize, 5000 );
     92    SetConfigValue ( bActive_, false );
     93    SetConfigValue ( targetSize, 10000 );
    9494  }
    9595
  • code/branches/netp2/src/network/packet/Gamestate.cc

    r2773 r2836  
    107107  for(it = ObjectList<Synchronisable>::begin(); it; ++it){
    108108   
    109     tempsize=it->getSize(id, mode);
     109//     tempsize=it->getSize(id, mode);
     110
     111    tempsize = it->getData(mem, id, mode);
     112    if ( it->doSync( id, mode ) )
     113      dataMap_.push_back( obj(it->getObjectID(), it->getCreatorID(), tempsize, mem-data_) );
     114   
    110115#ifndef NDEBUG
    111116    if(currentsize+tempsize > size){
     
    123128    }// stop allocate additional memory
    124129#endif
    125 
    126     if ( it->doSync( id, mode ) )
    127       dataMap_.push_back( obj(it->getObjectID(), it->getCreatorID(), tempsize, mem-data_) );
    128     if(!it->getData(mem, id, mode))
    129       return false; // mem pointer gets automatically increased because of call by reference
     130//     if(!it->getData(mem, id, mode))
     131//       return false; // mem pointer gets automatically increased because of call by reference
    130132    // increase size counter by size of current synchronisable
    131133    currentsize+=tempsize;
  • code/branches/netp2/src/network/packet/Packet.h

    r2773 r2836  
    6666    virtual unsigned int getSize() const =0;
    6767    virtual bool process()=0;
    68     uint32_t getFlags()
     68    inline uint32_t getFlags()
    6969      { return flags_; }
    70     int getClientID()
     70    inline int getClientID()
    7171      { return clientID_; }
    72     void setClientID( int id )
     72    inline void setClientID( int id )
    7373      { clientID_ = id; }
    7474
  • code/branches/netp2/src/network/synchronisable/NetworkCallbackManager.cc

    r2662 r2836  
    3232
    3333namespace orxonox{
    34 
     34 
    3535  std::set<NetworkCallbackBase*> NetworkCallbackManager::callbackSet_;
    3636  std::queue<NetworkCallbackBase*> NetworkCallbackManager::triggeredCallbacks_;
     
    6060    while( triggeredCallbacks_.empty()==false )
    6161    {
    62       triggeredCallbacks_.front()->call();
     62      //make sure callback hasn't been deleted before
     63      if ( callbackSet_.find(triggeredCallbacks_.front()) != callbackSet_.end() )
     64        triggeredCallbacks_.front()->call();
    6365      triggeredCallbacks_.pop();
    6466    }
  • code/branches/netp2/src/network/synchronisable/Synchronisable.cc

    r2826 r2836  
    6666      objectID=OBJECTID_UNKNOWN;
    6767    classID = static_cast<uint32_t>(-1);
    68 
     68   
     69    // set dataSize to 0
     70    this->dataSize_ = 0;
    6971    // set standard priority
    7072    this->setPriority( priority::normal );
     
    9698    // delete callback function objects
    9799    if(!Identifier::isCreatingHierarchy()){
    98       for(std::list<SynchronisableVariableBase*>::iterator it = syncList.begin(); it!=syncList.end(); it++)
     100      for(std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin(); it!=syncList.end(); it++)
    99101        delete (*it);
    100102      if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer()))
     
    236238   * @return true: if !doSync or if everything was successfully saved
    237239   */
    238   bool Synchronisable::getData(uint8_t*& mem, int32_t id, uint8_t mode){
     240  uint32_t Synchronisable::getData(uint8_t*& mem, int32_t id, uint8_t mode){
    239241    if(mode==0x0)
    240242      mode=state_;
    241243    //if this tick is we dont synchronise, then abort now
    242244    if(!doSync(id, mode))
    243       return true;
     245      return 0;
    244246    uint32_t tempsize = 0;
    245247    if (this->classID==0)
     
    250252
    251253    assert(this->classID==this->getIdentifier()->getNetworkID());
    252     std::list<SynchronisableVariableBase*>::iterator i;
    253     uint32_t size;
    254     size=getSize(id, mode);
     254    std::vector<SynchronisableVariableBase*>::iterator i;
    255255
    256256    // start copy header
    257257    SynchronisableHeader header(mem);
    258     header.setDataSize( size );
     258    mem += SynchronisableHeader::getSize();
     259    // end copy header
     260
     261
     262    COUT(5) << "Synchronisable getting data from objectID: " << objectID << " classID: " << classID << std::endl;
     263    // copy to location
     264    for(i=syncList.begin(); i!=syncList.end(); ++i){
     265      tempsize += (*i)->getData( mem, mode );
     266      //tempsize += (*i)->getSize( mode );
     267    }
     268   
     269    tempsize += SynchronisableHeader::getSize();
    259270    header.setObjectID( this->objectID );
    260271    header.setCreatorID( this->creatorID );
    261272    header.setClassID( this->classID );
    262273    header.setDataAvailable( true );
    263     tempsize += SynchronisableHeader::getSize();
    264     mem += SynchronisableHeader::getSize();
    265     // end copy header
    266 
    267 
    268     COUT(5) << "Synchronisable getting data from objectID: " << objectID << " classID: " << classID << " length: " << size << std::endl;
    269     // copy to location
    270     for(i=syncList.begin(); i!=syncList.end(); ++i){
    271       (*i)->getData( mem, mode );
    272       tempsize += (*i)->getSize( mode );
    273     }
     274    header.setDataSize( tempsize );
     275   
     276#ifndef NDEBUG
     277    uint32_t size;
     278    size=getSize(id, mode);
    274279    assert(tempsize==size);
    275     return true;
     280#endif
     281    return tempsize;
    276282  }
    277283
     
    286292    if(mode==0x0)
    287293      mode=state_;
    288     std::list<SynchronisableVariableBase *>::iterator i;
     294    std::vector<SynchronisableVariableBase *>::iterator i;
    289295    if(syncList.empty()){
    290296      assert(0);
     
    325331  uint32_t Synchronisable::getSize(int32_t id, uint8_t mode){
    326332    int tsize=SynchronisableHeader::getSize();
    327     if(mode==0x0)
     333    if (mode==0x0)
    328334      mode=state_;
    329     if(!doSync(id, mode))
     335    if (!doSync(id, mode))
    330336      return 0;
    331     std::list<SynchronisableVariableBase*>::iterator i;
    332     for(i=syncList.begin(); i!=syncList.end(); i++){
     337    assert( mode==state_ );
     338    tsize += this->dataSize_;
     339    std::vector<SynchronisableVariableBase*>::iterator i;
     340    for(i=stringList.begin(); i!=stringList.end(); ++i){
    333341      tsize += (*i)->getSize( mode );
    334342    }
  • code/branches/netp2/src/network/synchronisable/Synchronisable.h

    r2826 r2836  
    3333
    3434#include <list>
     35#include <vector>
    3536#include <map>
    3637#include <queue>
    3738#include <cassert>
     39#include <string>
    3840#include "util/Math.h"
    3941#include "util/mbool.h"
     
    139141    Synchronisable(BaseObject* creator);
    140142    template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false);
    141     template <class T> void unregisterVariable(T& var);
     143    //template <class T> void unregisterVariable(T& var);
    142144    void setObjectMode(uint8_t mode);
    143145    void setPriority(unsigned int freq){ objectFrequency_ = freq; }
     
    145147
    146148  private:
    147     bool getData(uint8_t*& men, int32_t id, uint8_t mode=0x0);
     149    uint32_t getData(uint8_t*& men, int32_t id, uint8_t mode=0x0);
    148150    uint32_t getSize(int32_t id, uint8_t mode=0x0);
    149151    bool updateData(uint8_t*& mem, uint8_t mode=0x0, bool forceCallback=false);
     
    155157    uint32_t classID;
    156158
    157     std::list<SynchronisableVariableBase*> syncList;
     159    std::vector<SynchronisableVariableBase*> syncList;
     160    std::vector<SynchronisableVariableBase*> stringList;
     161    uint32_t dataSize_; //size of all variables except strings
    158162    static uint8_t state_; // detemines wheter we are server (default) or client
    159163    bool backsync_; // if true the variables with mode > 1 will be synchronised to server (client -> server)
     
    164168  };
    165169
    166   template <class T> void Synchronisable::registerVariable(T& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
    167   {
    168     if (bidirectional)
    169       syncList.push_back(new SynchronisableVariableBidirectional<const T>(variable, mode, cb));
    170     else
    171       syncList.push_back(new SynchronisableVariable<const T>(variable, mode, cb));
    172   }
    173 
    174   template <class T> void Synchronisable::unregisterVariable(T& var){
    175     std::list<SynchronisableVariableBase*>::iterator it = syncList.begin();
    176     while(it!=syncList.end()){
    177       if( ((*it)->getReference()) == &var ){
    178         delete (*it);
    179         syncList.erase(it);
    180         return;
    181       }
    182       else
    183         it++;
    184     }
    185     bool unregistered_nonexistent_variable = false;
    186     assert(unregistered_nonexistent_variable); //if we reach this point something went wrong:
    187     // the variable has not been registered before
    188   }
    189 
    190170  // ================= Specialisation declarations
     171 
     172//   template <> _NetworkExport void Synchronisable::registerVariable( const std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional);
     173  template <> _NetworkExport void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional);
    191174  template <> _NetworkExport void Synchronisable::registerVariable( const ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    192175  template <> _NetworkExport void Synchronisable::registerVariable( ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
     
    200183  template <> _NetworkExport void Synchronisable::registerVariable( const Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    201184  template <> _NetworkExport void Synchronisable::registerVariable( Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
     185 
     186  template <class T> void Synchronisable::registerVariable(T& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
     187  {
     188    if (bidirectional)
     189      syncList.push_back(new SynchronisableVariableBidirectional<const T>(variable, mode, cb));
     190    else
     191      syncList.push_back(new SynchronisableVariable<const T>(variable, mode, cb));
     192    if ( this->state_ == mode )
     193      this->dataSize_ += syncList.back()->getSize(state_);
     194  }
     195 
     196
     197
     198//   template <class T> void Synchronisable::unregisterVariable(T& var){
     199//     std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin();
     200//     while(it!=syncList.end()){
     201//       if( ((*it)->getReference()) == &var ){
     202//         delete (*it);
     203//         syncList.erase(it);
     204//         return;
     205//       }
     206//       else
     207//         it++;
     208//     }
     209//     bool unregistered_nonexistent_variable = false;
     210//     assert(unregistered_nonexistent_variable); //if we reach this point something went wrong:
     211//     // the variable has not been registered before
     212//   }
     213
     214 
    202215}
    203216
  • code/branches/netp2/src/network/synchronisable/SynchronisableSpecialisations.cc

    r2662 r2836  
    2929
    3030#include "network/synchronisable/Synchronisable.h"
     31#include <string>
    3132
    3233// ================ template spezialisation
     
    3435 
    3536namespace orxonox{
     37 
     38//   template <> void Synchronisable::registerVariable( const std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
     39//   {
     40//     if (bidirectional)
     41//       syncList.push_back(new SynchronisableVariableBidirectional<const std::string>(variable, mode, cb));
     42//     else
     43//       syncList.push_back(new SynchronisableVariable<const std::string>(variable, mode, cb));
     44//     stringList.push_back(syncList.back());
     45//   }
     46 
     47  template <> void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
     48  {
     49    if (bidirectional)
     50      syncList.push_back(new SynchronisableVariableBidirectional<const std::string>(variable, mode, cb));
     51    else
     52      syncList.push_back(new SynchronisableVariable<const std::string>(variable, mode, cb));
     53    stringList.push_back(syncList.back());
     54  }
    3655 
    3756  template <> void Synchronisable::registerVariable( const ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
  • code/branches/netp2/src/network/synchronisable/SynchronisableVariable.h

    r2710 r2836  
    5656  {
    5757    public:
    58       virtual void getData(uint8_t*& mem, uint8_t mode)=0;
     58      virtual uint32_t getData(uint8_t*& mem, uint8_t mode)=0;
    5959      virtual void putData(uint8_t*& mem, uint8_t mode, bool forceCallback = false)=0;
    6060      virtual uint32_t getSize(uint8_t mode)=0;
     
    7474
    7575      virtual inline uint8_t getMode(){ return mode_; }
    76       virtual inline void getData(uint8_t*& mem, uint8_t mode);
     76      virtual inline uint32_t getData(uint8_t*& mem, uint8_t mode);
    7777      virtual inline void putData(uint8_t*& mem, uint8_t mode, bool forceCallback = false);
    7878      virtual inline uint32_t getSize(uint8_t mode);
    7979      virtual inline void* getReference(){ return (void *)&this->variable_; }
    8080    protected:
    81       bool checkEquality(uint8_t* mem);
    82       void setAndIncrease(uint8_t*& mem);
    83       void getAndIncrease(uint8_t*& mem);
    84       uint32_t returnSize();
     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();
    8585     
    8686      T& variable_;
     
    9797     
    9898      virtual inline uint8_t getMode(){ return 0x3; } //this basically is a hack ^^
    99       virtual void getData(uint8_t*& mem, uint8_t mode);
     99      virtual inline uint32_t getData(uint8_t*& mem, uint8_t mode);
    100100      virtual void putData(uint8_t*& mem, uint8_t mode, bool forceCallback = false);
    101       virtual uint32_t getSize(uint8_t mode);
     101      virtual inline uint32_t getSize(uint8_t mode);
    102102    private:
    103103      T varBuffer_;
     
    122122  }
    123123
    124   template <class T> void SynchronisableVariable<T>::getData(uint8_t*& mem, uint8_t mode)
     124  template <class T> inline uint32_t SynchronisableVariable<T>::getData(uint8_t*& mem, uint8_t mode)
    125125  {
    126126    if ( state_ == this->mode_ )
     127    {
    127128      getAndIncrease( mem );
     129      return returnSize();
     130    }
     131    else
     132      return 0;
    128133//   mem += SynchronisableVariable<T>::getSize();
    129134  }
     
    143148  // write the data
    144149    setAndIncrease( mem );
    145 //   mem += SynchronisableVariable<T>::getSize();
    146150  // now do a callback if neccessary
    147151    if ( callback )
    148152      NetworkCallbackManager::triggerCallback( this->callback_ );
    149       //this->callback_->call();
    150   }
    151 
    152   template <class T> uint32_t SynchronisableVariable<T>::getSize(uint8_t mode)
     153  }
     154
     155  template <class T> inline uint32_t SynchronisableVariable<T>::getSize(uint8_t mode)
    153156  {
    154157    if ( mode == this->mode_ )
     
    232235    }
    233236
    234     template <class T> void SynchronisableVariableBidirectional<T>::getData(uint8_t*& mem, uint8_t mode)
     237    template <class T> uint32_t SynchronisableVariableBidirectional<T>::getData(uint8_t*& mem, uint8_t mode)
    235238    {
    236239      if ( this->mode_ == mode )
     
    248251      SynchronisableVariable<T>::getAndIncrease( mem );
    249252//   mem += SynchronisableVariable<T>::getSize();
     253      return SynchronisableVariableBidirectional::getSize(mode);
    250254    }
    251255
     
    304308    }
    305309
    306     template <class T> uint32_t SynchronisableVariableBidirectional<T>::getSize(uint8_t mode)
     310    template <class T> inline uint32_t SynchronisableVariableBidirectional<T>::getSize(uint8_t mode)
    307311    {
    308312      return SynchronisableVariable<T>::returnSize() + sizeof(varReference_);
     
    312316}
    313317
     318#include "network/synchronisable/SynchronisableVariableSpecialisations.h"
    314319
    315320#endif
  • code/branches/netp2/src/orxonox/objects/controllers/AIController.cc

    r2662 r2836  
    101101    void AIController::tick(float dt)
    102102    {
    103         if (!this->isActive())
    104             return;
    105 
    106         if (this->target_)
    107             this->aimAtTarget();
    108 
    109         if (this->bHasTargetPosition_)
    110             this->moveToTargetPosition(dt);
    111 
    112         if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(500) && this->isLookingAtTarget(Ogre::Math::PI / 20.0))
    113             this->getControllableEntity()->fire(WeaponMode::fire);
     103        if(Core::isMaster())
     104        {
     105            if (!this->isActive())
     106                return;
     107   
     108            if (this->target_)
     109                this->aimAtTarget();
     110   
     111            if (this->bHasTargetPosition_)
     112                this->moveToTargetPosition(dt);
     113   
     114            if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(500) && this->isLookingAtTarget(Ogre::Math::PI / 20.0))
     115                this->getControllableEntity()->fire(WeaponMode::fire);
     116        }
    114117
    115118        SUPER(AIController, tick, dt);
  • code/branches/netp2/src/orxonox/objects/worldentities/pawns/Pawn.cc

    r2826 r2836  
    129129        this->firehack_ = 0x0;
    130130
    131         if (this->health_ <= 0)
     131        if (Core::isMaster())
     132          if (this->health_ <= 0)
    132133            this->death();
    133134    }
Note: See TracChangeset for help on using the changeset viewer.