Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6868 in orxonox.OLD


Ignore:
Timestamp:
Jan 30, 2006, 4:41:19 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the Network back to the trunk.
merged with command
svn merge https://svn.orxonox.net/orxonox/branches/network . -r6817:HEAD
no conflicts

Location:
trunk/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/defs/debug.h

    r6834 r6868  
    3232
    3333#include <stdio.h>
     34#include <cassert>
    3435
    3536// DEFINE ERROR MODES
  • trunk/src/lib/network/network_game_manager.cc

    r6815 r6868  
    575575    if ( (*it)->getUniqueID() == uniqueID )
    576576    {
    577       delete *it;
     577      assert((*it)->isA(CL_WORLD_ENTITY));
     578      dynamic_cast<WorldEntity*>(*it)->toList(OM_DEAD);
    578579      break;
    579580    }
  • trunk/src/lib/network/network_stream.cc

    r6737 r6868  
    263263        if ( reciever!=0 )
    264264        {
    265           if ( networkSockets[reciever] != NULL )
    266           {
    267             PRINTF(5)("write %d bytes to socket %d\n", dataLength, reciever);
    268             networkSockets[reciever]->writePacket(downBuffer, dataLength);
     265          if ( reciever < 0)
     266          {
     267            for ( int i = 0; i<networkSockets.size(); i++)
     268            {
     269              if ( i!=-reciever && networkSockets[i] != NULL )
     270              {
     271                PRINTF(5)("write %d bytes to socket %d\n", dataLength, i);
     272                networkSockets[i]->writePacket(downBuffer, dataLength);
     273              }
     274            }
    269275          }
    270276          else
    271277          {
    272             PRINTF(1)("networkSockets[reciever] == NULL\n");
     278            if ( networkSockets[reciever] != NULL )
     279            {
     280              PRINTF(5)("write %d bytes to socket %d\n", dataLength, reciever);
     281              networkSockets[reciever]->writePacket(downBuffer, dataLength);
     282            }
     283            else
     284            {
     285              PRINTF(1)("networkSockets[reciever] == NULL\n");
     286            }
    273287          }
    274288        }
  • trunk/src/lib/network/synchronizeable.h

    r6815 r6868  
    3333  NWT_SS_VELY,
    3434  NWT_SS_VELZ,
     35  NWT_SS_PL_SYNC,
    3536 
    3637  NWT_HS_HOST_ID,
    3738  NWT_HS_NGM_ID,
     39 
     40  NWT_PL_FLAGS,
    3841 
    3942  NWT_PN_BO_WRITESTATE,
     
    101104 * with the same argument names!
    102105 *
     106 * id is one int out of that enum on top of this comment it is used to identify
     107 * read/write. when you read a value you have to use exactly the same as you used
     108 * to write or you will see an assertion failing.
     109 *
    103110 * SYNCHELP_WRITE_BEGIN()
    104  * SYNCHELP_WRITE_INT(i)
    105  * SYNCHELP_WRITE_FLOAT(f)
    106  * SYNCHELP_WRITE_BYTE(b)
    107  * SYNCHELP_WRITE_STRING(s)
     111 * SYNCHELP_WRITE_INT(i,id)
     112 * SYNCHELP_WRITE_FLOAT(f,id)
     113 * SYNCHELP_WRITE_BYTE(b,id)
     114 * SYNCHELP_WRITE_STRING(s,id)
    108115 * SYNCHELP_WRITE_N
    109116 *
    110117 * SYNCHELP_READ_BEGIN()
    111  * SYNCHELP_READ_INT(i)
    112  * SYNCHELP_READ_FLOAT(f)
    113  * SYNCHELP_READ_STRING(s,l) l = size of buffer s
    114  * SYNCHELP_READ_STRINGM(s)  allocates memory for string! you have to free this after
    115  * SYNCHELP_READ_BYTE(b)
     118 * SYNCHELP_READ_INT(i,id)
     119 * SYNCHELP_READ_FLOAT(f,id)
     120 * SYNCHELP_READ_STRING(s,l,id) l = size of buffer s
     121 * SYNCHELP_READ_STRINGM(s,id)  allocates memory for string! you have to delete this later
     122 * SYNCHELP_READ_BYTE(b,id)
     123 * SYNCHELP_READ_REMAINING() returns the remaining buffer size
     124 * SYNCHELP_READ_NEXTBYTE()  reads the next byte but it is not removed from the buffer
    116125 * SYNCHELP_READ_N
    117126 *
     
    122131 *  SYNCHELP_READ_FLOAT(size);
    123132 *  SYNCHELP_READ_STRING( textureName, 1024 ); //1024 is the length of textureName
     133 *  delete[] textureName;
     134 *  textureName = NULL;
     135 *  SYNCHELP_READ_STRINGM( texturename );      //this will call new char[strlen()+1]
    124136 *
    125137 * Example 2:
     
    130142 *
    131143 */
     144 
    132145#define SYNCHELP_WRITE_DEBUG(n) {\
    133146  __synchelp_write_n = Converter::intToByteArray( n, data+__synchelp_write_i, maxLength-__synchelp_write_i ); \
  • trunk/src/world_entities/playable.cc

    r6804 r6868  
    4040
    4141  this->bFire = false;
     42  this->oldFlags = 0;
    4243
    4344  this->setSynchronized(true);
     
    246247{
    247248}
     249
     250#define FLAGS_bFire   1
     251
     252int Playable::writeSync( const byte * data, int length, int sender )
     253{
     254  SYNCHELP_READ_BEGIN();
     255 
     256  byte flags;
     257 
     258  SYNCHELP_READ_BYTE( flags, NWT_PL_FLAGS );
     259 
     260  bFire = (flags & FLAGS_bFire) != 0;
     261 
     262  return SYNCHELP_READ_N;
     263}
     264
     265int Playable::readSync( byte * data, int maxLength )
     266{
     267  SYNCHELP_WRITE_BEGIN();
     268  byte flags = 0;
     269 
     270  if ( bFire )
     271    flags |= FLAGS_bFire;
     272 
     273
     274  SYNCHELP_WRITE_BYTE( flags, NWT_PL_FLAGS );
     275  oldFlags = flags;
     276
     277 
     278  return SYNCHELP_WRITE_N;
     279}
     280
     281bool Playable::needsReadSync( )
     282{
     283  byte flags = 0;
     284 
     285  if ( bFire )
     286    flags |= FLAGS_bFire;
     287 
     288  return flags!=oldFlags;
     289}
  • trunk/src/world_entities/playable.h

    r6804 r6868  
    5454    /** @return a List of Events in PEV_* sytle */
    5555    inline const std::list<int>& getEventList() { return this->events; };
     56   
     57    int       writeSync(const byte* data, int length, int sender);
     58    int       readSync(byte* data, int maxLength );
     59    bool      needsReadSync();
    5660
    5761  protected:
     
    6872
    6973    bool                  bFire;              //!< If the Ship is firing.
     74    int                   oldFlags;           //!< Used for synchronisation
    7075
    7176};
  • trunk/src/world_entities/space_ships/space_ship.cc

    r6825 r6868  
    9595  else
    9696  {
    97     this->loadModel("models/ships/reap_#.obj");
     97    //this->loadModel("models/ships/reap_#.obj");
     98    this->loadModel( "models/ships/fighter.obj" );
    9899  }
    99100
     
    127128
    128129  bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = false;
    129   bFire = false;
     130
    130131  xMouse = yMouse = 0;
    131132  yInvert = 1;
     
    516517#define MASK_bAscend    16
    517518#define MASK_bDescend   32
    518 #define MASK_bFire      64
    519 #define MASK_bRollL    128
    520 #define MASK_bRollR    256
     519#define MASK_bRollL     64
     520#define MASK_bRollR    128
    521521
    522522#define DATA_state       1
     
    525525#define DATA_sync        4
    526526#define DATA_velocity    5
     527#define DATA_playables   6
    527528
    528529int SpaceShip::writeBytes( const byte * data, int length, int sender )
     
    547548    if ( b == DATA_flags )
    548549    {
    549       int flags = 0;
    550       SYNCHELP_READ_INT( flags, NWT_SS_FLAGS );
    551 
    552       bUp = (flags & MASK_bUp) != 0;
    553       bDown = (flags & MASK_bDown) != 0;
    554       bLeft = (flags & MASK_bLeft) != 0;
    555       bRight = (flags & MASK_bRight) != 0;
    556       bAscend = (flags & MASK_bAscend) != 0;
    557       bDescend = (flags & MASK_bDescend) != 0;
    558       bFire = (flags & MASK_bFire) != 0;
    559       bRollL = (flags & MASK_bRollL) != 0;
    560       bRollR = (flags & MASK_bRollR) != 0;
     550      if ( this->getOwner() != this->getHostID() )
     551      {
     552        byte flags = 0;
     553        SYNCHELP_READ_BYTE( flags, NWT_SS_FLAGS );
     554
     555        bUp = (flags & MASK_bUp) != 0;
     556        bDown = (flags & MASK_bDown) != 0;
     557        bLeft = (flags & MASK_bLeft) != 0;
     558        bRight = (flags & MASK_bRight) != 0;
     559        bAscend = (flags & MASK_bAscend) != 0;
     560        bDescend = (flags & MASK_bDescend) != 0;
     561        bRollL = (flags & MASK_bRollL) != 0;
     562        bRollR = (flags & MASK_bRollR) != 0;
     563       
     564      }
     565      else
     566        assert(false);
    561567
    562568      continue;
     
    565571    if ( b == DATA_mouse )
    566572    {
    567       SYNCHELP_READ_FLOAT( mouseDir.w, NWT_SS_MOUSEDIRW );
    568       SYNCHELP_READ_FLOAT( mouseDir.v.x, NWT_SS_MOUSEDIRX );
    569       SYNCHELP_READ_FLOAT( mouseDir.v.y, NWT_SS_MOUSEDIRY );
    570       SYNCHELP_READ_FLOAT( mouseDir.v.z, NWT_SS_MOUSEDIRZ );
     573      if ( this->getOwner() != this->getHostID() )
     574      {
     575        SYNCHELP_READ_FLOAT( mouseDir.w, NWT_SS_MOUSEDIRW );
     576        SYNCHELP_READ_FLOAT( mouseDir.v.x, NWT_SS_MOUSEDIRX );
     577        SYNCHELP_READ_FLOAT( mouseDir.v.y, NWT_SS_MOUSEDIRY );
     578        SYNCHELP_READ_FLOAT( mouseDir.v.z, NWT_SS_MOUSEDIRZ );
     579      }
     580      else
     581        assert(false);
    571582
    572583      continue;
     
    576587    {
    577588      if ( this->getOwner() != this->getHostID() )
     589      {
    578590        SYNCHELP_READ_FKT( PNode::writeSync, NWT_SS_PN_SYNC );
     591      }
     592      else
     593        assert(false);
    579594
    580595      continue;
     
    583598    if ( b == DATA_velocity )
    584599    {
    585       SYNCHELP_READ_FLOAT( velocity.x, NWT_SS_VELX );
    586       SYNCHELP_READ_FLOAT( velocity.y, NWT_SS_VELY );
    587       SYNCHELP_READ_FLOAT( velocity.z, NWT_SS_VELZ );
     600      if ( this->getOwner() != this->getHostID() )
     601      {
     602        SYNCHELP_READ_FLOAT( velocity.x, NWT_SS_VELX );
     603        SYNCHELP_READ_FLOAT( velocity.y, NWT_SS_VELY );
     604        SYNCHELP_READ_FLOAT( velocity.z, NWT_SS_VELZ );
     605      }     
     606      else
     607        assert(false);
     608     
     609      continue;
     610    }
     611   
     612    if ( b == DATA_playables )
     613    {
     614      if ( this->getOwner() != this->getHostID() )
     615      {
     616        SYNCHELP_READ_FKT( Playable::writeSync, NWT_SS_PL_SYNC );
     617      }
     618      else
     619        assert(false);
    588620    }
    589621  }
     
    615647
    616648    SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_SS_WE_STATE );
    617     //SYNCHELP_WRITE_FLOAT( cycle );
    618649
    619650    return SYNCHELP_WRITE_N;
    620651  }
    621652
    622   *reciever = 0;
    623 
    624   if ( this->getOwner() == this->getHostID() && PNode::needsReadSync() )
     653  *reciever = -this->getOwner();
     654  bool sentSomething = false;
     655
     656  if ( ( this->getHostID()==0 || this->getOwner() == this->getHostID() ) && PNode::needsReadSync() )
    625657  {
    626658    SYNCHELP_WRITE_BYTE( DATA_sync, NWT_SS_B );
     
    628660  }
    629661
    630   if ( this->getHostID()==this->getOwner() )
    631   {
    632     int mask = 0;
     662  if ( this->getHostID()==0 || this->getHostID()==this->getOwner() )
     663  {
     664    byte mask = 0;
    633665
    634666    if ( bUp )
     
    642674    if ( bAscend )
    643675      mask |= MASK_bAscend;
    644     if ( bFire )
    645       mask |= MASK_bFire;
    646676    if ( bRollL )
    647677      mask |= MASK_bRollL;
     
    650680
    651681
    652     //static float oldxMouse = xMouse + 1.0;
    653     //static float oldyMouse = yMouse + 1.0;
    654 
    655682    if ( mask != oldMask )
    656683    {
    657684      oldMask = mask;
     685      sentSomething = true;
    658686      SYNCHELP_WRITE_BYTE( DATA_flags, NWT_SS_B );
    659       SYNCHELP_WRITE_INT( mask, NWT_SS_FLAGS );
     687      SYNCHELP_WRITE_BYTE( mask, NWT_SS_FLAGS );
    660688    }
    661689#define __OFFSET_MDIR_W 0.01
     
    670698      SYNCHELP_WRITE_BYTE( DATA_mouse, NWT_SS_B );
    671699      PRINTF(0)("SENDING mousedir\n");
     700      sentSomething = true;
    672701      SYNCHELP_WRITE_FLOAT( mouseDir.w, NWT_SS_MOUSEDIRW );
    673702      SYNCHELP_WRITE_FLOAT( mouseDir.v.x, NWT_SS_MOUSEDIRX );
     
    681710    {
    682711      oldVelocity = velocity;
    683       PRINTF(0)("SENDING velocity\n");
    684       SYNCHELP_WRITE_BYTE( DATA_velocity, NWT_SS_B );
    685       SYNCHELP_WRITE_FLOAT( velocity.x, NWT_SS_VELX );
    686       SYNCHELP_WRITE_FLOAT( velocity.y, NWT_SS_VELY );
    687       SYNCHELP_WRITE_FLOAT( velocity.z, NWT_SS_VELZ );
    688     }
    689 
    690   }
     712      //PRINTF(0)("SENDING velocity\n");
     713      //SYNCHELP_WRITE_BYTE( DATA_velocity, NWT_SS_B );
     714      //SYNCHELP_WRITE_FLOAT( velocity.x, NWT_SS_VELX );
     715      //SYNCHELP_WRITE_FLOAT( velocity.y, NWT_SS_VELY );
     716      //SYNCHELP_WRITE_FLOAT( velocity.z, NWT_SS_VELZ );
     717    }
     718   
     719    if ( Playable::needsReadSync() )
     720    {
     721      sentSomething = true;
     722      SYNCHELP_WRITE_BYTE( DATA_playables, NWT_SS_B );
     723      SYNCHELP_WRITE_FKT( Playable::readSync, NWT_SS_PL_SYNC );
     724    }
     725
     726  }
     727 
     728  if ( !sentSomething )
     729    reciever = 0;
    691730
    692731  return SYNCHELP_WRITE_N;
  • trunk/src/world_entities/space_ships/space_ship.h

    r6815 r6868  
    5656    bool                  bAscend;            //!< ascend button pressed.
    5757    bool                  bDescend;           //!< descend button presses.
    58     bool                  bFire;              //!< fire button pressed.
     58//    bool                  bFire;              //!< fire button pressed.(moved to playable)
    5959    bool                  bRollL;             //!< rolling button pressed (left)
    6060    bool                  bRollR;             //!< rolling button pressed (right)
     
    8080    float                 airViscosity;
    8181
    82     int oldMask;
     82    byte                  oldMask;            //!< used for synchronisation
    8383
    8484    ParticleEmitter*      burstEmitter;
Note: See TracChangeset for help on using the changeset viewer.