Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6498 in orxonox.OLD for trunk/src/world_entities/space_ships


Ignore:
Timestamp:
Jan 11, 2006, 9:58:22 PM (19 years ago)
Author:
patrick
Message:

trunk: merged the network branche into the trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/space_ships/space_ship.cc

    r6444 r6498  
    510510}
    511511
     512#define MASK_bUp         1
     513#define MASK_bDown       2
     514#define MASK_bLeft       4
     515#define MASK_bRight      8
     516#define MASK_bAscend    16
     517#define MASK_bDescend   32
     518#define MASK_bFire      64
     519#define MASK_bRollL    128
     520#define MASK_bRollR    256
     521
     522#define DATA_state       1
     523#define DATA_flags       2
     524#define DATA_mouse       3
    512525
    513526int SpaceShip::writeBytes( const byte * data, int length, int sender )
    514527{
    515   setRequestedSync( false );
    516   setIsOutOfSync( false );
    517 
    518528  SYNCHELP_READ_BEGIN();
    519529
    520   SYNCHELP_READ_FKT( WorldEntity::writeState );
     530  byte b;
     531  SYNCHELP_READ_BYTE( b );
     532
     533  if ( b == DATA_state && this->getHostID()!=this->getOwner() )
     534  {
     535    setRequestedSync( false );
     536    setIsOutOfSync( false );
     537    SYNCHELP_READ_FKT( WorldEntity::writeState );
     538    SYNCHELP_READ_FLOAT( cycle );
     539  }
     540
     541  if ( b == DATA_flags && this->getHostID()!=this->getOwner() )
     542  {
     543    int flags;
     544    SYNCHELP_READ_INT( flags );
     545
     546    bUp = flags & MASK_bUp != 0;
     547    bDown = flags & MASK_bDown != 0;
     548    bLeft = flags & MASK_bLeft != 0;
     549    bRight = flags & MASK_bRight != 0;
     550    bAscend = flags & MASK_bAscend != 0;
     551    bDescend = flags & MASK_bDescend != 0;
     552    bFire = flags & MASK_bFire != 0;
     553    bRollL = flags & MASK_bRollL != 0;
     554    bRollR = flags & MASK_bRollR != 0;
     555  }
     556
     557  if ( b == DATA_mouse && this->getHostID()!=this->getOwner() )
     558  {
     559    SYNCHELP_READ_FLOAT( xMouse );
     560    SYNCHELP_READ_FLOAT( yMouse );
     561    SYNCHELP_READ_FLOAT( mouseSensitivity );
     562    SYNCHELP_READ_FLOAT( cycle );
     563  }
    521564
    522565  return SYNCHELP_READ_N;
    523566}
    524567
     568
     569
    525570int SpaceShip::readBytes( byte * data, int maxLength, int * reciever )
    526571{
     572  SYNCHELP_WRITE_BEGIN();
     573
    527574  if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
    528575  {
     
    536583    *reciever = rec;
    537584
    538     SYNCHELP_WRITE_BEGIN();
     585    SYNCHELP_WRITE_BYTE( (byte)DATA_state );
    539586
    540587    SYNCHELP_WRITE_FKT( WorldEntity::readState );
     588    SYNCHELP_WRITE_FLOAT( cycle );
    541589
    542590    return SYNCHELP_WRITE_N;
    543591  }
    544592
     593
    545594  *reciever = 0;
    546   return 0;
    547 }
     595
     596  if ( this->getHostID()==this->getOwner() )
     597  {
     598    int mask = 0;
     599
     600    if ( bUp )
     601      mask |= MASK_bUp;
     602    if ( bDown )
     603      mask |= MASK_bDown;
     604    if ( bLeft )
     605      mask |= MASK_bLeft;
     606    if ( bRight )
     607      mask |= MASK_bRight;
     608    if ( bAscend )
     609      mask |= MASK_bAscend;
     610    if ( bFire )
     611      mask |= MASK_bFire;
     612    if ( bRollL )
     613      mask |= MASK_bRollL;
     614    if ( bRollR )
     615      mask |= MASK_bRollR;
     616
     617    static int oldMask = mask+1; //so it is different the first time!
     618    static float oldxMouse = xMouse + 1.0;
     619    static float oldyMouse = yMouse + 1.0;
     620
     621    if ( mask != oldMask )
     622    {
     623      oldMask = mask;
     624      SYNCHELP_WRITE_BYTE( DATA_flags );
     625      SYNCHELP_WRITE_INT( mask );
     626    }
     627
     628    if ( oldxMouse != xMouse || oldyMouse != yMouse )
     629    {
     630      oldxMouse = xMouse;
     631      oldyMouse = yMouse;
     632      SYNCHELP_WRITE_BYTE( DATA_mouse );
     633      SYNCHELP_WRITE_FLOAT( xMouse );
     634      SYNCHELP_WRITE_FLOAT( yMouse );
     635      SYNCHELP_WRITE_FLOAT( mouseSensitivity );
     636      SYNCHELP_WRITE_FLOAT( cycle );
     637    }
     638  }
     639
     640  return SYNCHELP_WRITE_N;
     641}
Note: See TracChangeset for help on using the changeset viewer.