Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6861 in orxonox.OLD


Ignore:
Timestamp:
Jan 30, 2006, 10:24:20 AM (18 years ago)
Author:
rennerc
Message:

fire over network works again

Location:
branches/network/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/lib/network/synchronizeable.h

    r6815 r6861  
    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 ); \
  • branches/network/src/world_entities/playable.cc

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

    r6804 r6861  
    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};
  • branches/network/src/world_entities/space_ships/space_ship.cc

    r6820 r6861  
    128128
    129129  bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = false;
    130   bFire = false;
     130
    131131  xMouse = yMouse = 0;
    132132  yInvert = 1;
     
    517517#define MASK_bAscend    16
    518518#define MASK_bDescend   32
    519 #define MASK_bFire      64
    520 #define MASK_bRollL    128
    521 #define MASK_bRollR    256
     519#define MASK_bRollL     64
     520#define MASK_bRollR    128
    522521
    523522#define DATA_state       1
     
    526525#define DATA_sync        4
    527526#define DATA_velocity    5
     527#define DATA_playables   6
    528528
    529529int SpaceShip::writeBytes( const byte * data, int length, int sender )
     
    548548    if ( b == DATA_flags )
    549549    {
    550       int flags = 0;
    551       SYNCHELP_READ_INT( flags, NWT_SS_FLAGS );
    552 
    553       bUp = (flags & MASK_bUp) != 0;
    554       bDown = (flags & MASK_bDown) != 0;
    555       bLeft = (flags & MASK_bLeft) != 0;
    556       bRight = (flags & MASK_bRight) != 0;
    557       bAscend = (flags & MASK_bAscend) != 0;
    558       bDescend = (flags & MASK_bDescend) != 0;
    559       bFire = (flags & MASK_bFire) != 0;
    560       bRollL = (flags & MASK_bRollL) != 0;
    561       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      }
    562565     
    563566      continue;
     
    566569    if ( b == DATA_mouse )
    567570    {
    568       SYNCHELP_READ_FLOAT( mouseDir.w, NWT_SS_MOUSEDIRW );
    569       SYNCHELP_READ_FLOAT( mouseDir.v.x, NWT_SS_MOUSEDIRX );
    570       SYNCHELP_READ_FLOAT( mouseDir.v.y, NWT_SS_MOUSEDIRY );
    571       SYNCHELP_READ_FLOAT( mouseDir.v.z, NWT_SS_MOUSEDIRZ );
     571      if ( this->getOwner() != this->getHostID() )
     572      {
     573        SYNCHELP_READ_FLOAT( mouseDir.w, NWT_SS_MOUSEDIRW );
     574        SYNCHELP_READ_FLOAT( mouseDir.v.x, NWT_SS_MOUSEDIRX );
     575        SYNCHELP_READ_FLOAT( mouseDir.v.y, NWT_SS_MOUSEDIRY );
     576        SYNCHELP_READ_FLOAT( mouseDir.v.z, NWT_SS_MOUSEDIRZ );
     577      }
    572578     
    573579      continue;
     
    584590    if ( b == DATA_velocity )
    585591    {
    586       SYNCHELP_READ_FLOAT( velocity.x, NWT_SS_VELX );
    587       SYNCHELP_READ_FLOAT( velocity.y, NWT_SS_VELY );
    588       SYNCHELP_READ_FLOAT( velocity.z, NWT_SS_VELZ );
     592      if ( this->getOwner() != this->getHostID() )
     593      {
     594        SYNCHELP_READ_FLOAT( velocity.x, NWT_SS_VELX );
     595        SYNCHELP_READ_FLOAT( velocity.y, NWT_SS_VELY );
     596        SYNCHELP_READ_FLOAT( velocity.z, NWT_SS_VELZ );
     597      }
     598     
     599      continue;
     600    }
     601   
     602    if ( b == DATA_playables )
     603    {
     604      if ( this->getOwner() != this->getHostID() )
     605        SYNCHELP_READ_FKT( Playable::writeSync, NWT_SS_PL_SYNC );
    589606    }
    590607  }
     
    616633
    617634    SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_SS_WE_STATE );
    618     //SYNCHELP_WRITE_FLOAT( cycle );
    619635
    620636    return SYNCHELP_WRITE_N;
     
    631647  if ( this->getHostID()==this->getOwner() )
    632648  {
    633     int mask = 0;
     649    byte mask = 0;
    634650
    635651    if ( bUp )
     
    643659    if ( bAscend )
    644660      mask |= MASK_bAscend;
    645     if ( bFire )
    646       mask |= MASK_bFire;
    647661    if ( bRollL )
    648662      mask |= MASK_bRollL;
     
    651665
    652666
    653     //static float oldxMouse = xMouse + 1.0;
    654     //static float oldyMouse = yMouse + 1.0;
    655 
    656667    if ( mask != oldMask )
    657668    {
    658669      oldMask = mask;
    659670      SYNCHELP_WRITE_BYTE( DATA_flags, NWT_SS_B );
    660       SYNCHELP_WRITE_INT( mask, NWT_SS_FLAGS );
     671      SYNCHELP_WRITE_BYTE( mask, NWT_SS_FLAGS );
    661672    }
    662673#define __OFFSET_MDIR_W 0.01
     
    688699      SYNCHELP_WRITE_FLOAT( velocity.z, NWT_SS_VELZ );
    689700    }
     701   
     702    if ( Playable::needsReadSync() )
     703    {
     704      SYNCHELP_WRITE_BYTE( DATA_playables, NWT_SS_B );
     705      SYNCHELP_WRITE_FKT( Playable::readSync, NWT_SS_PL_SYNC );
     706    }
    690707
    691708  }
  • branches/network/src/world_entities/space_ships/space_ship.h

    r6815 r6861  
    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.