Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 29, 2006, 3:28:41 PM (18 years ago)
Author:
patrick
Message:

trunk: merged the network branche back to trunk.

File:
1 edited

Legend:

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

    r7868 r7954  
    9393  if (root != NULL)
    9494    this->loadParams(root);
    95   else
    96   {
    97     //this->loadModel("models/ships/reap_#.obj");
    98     //TODO HACK this is only for network multiplayer games.
    99     if( this->getOwner()%2 == 0)
    100     {
    101       this->loadModel("models/ships/reap_#.obj");
    102       this->toList(OM_GROUP_00);
    103     }
    104     else
    105     {
    106       this->loadModel( "models/ships/fighter.obj" );
    107       this->toList(OM_GROUP_01);
    108     }
    109   }
    11095
    11196}
     
    234219  this->burstSystem->setColor(0.5, .5,.5,.8,.8);
    235220  this->burstSystem->setColor(1.0, .8,.8,.8,.0);
    236 
     221 
     222  registerVar( new SynchronizeableVector( &velocity, &velocity, "velocity" ) );
     223  registerVar( new SynchronizeableQuaternion( &mouseDir, &mouseDir, "mousedir", PERMISSION_OWNER ) );
     224
     225  registerVar( new SynchronizeableBool( &bUp, &bUp, "bUp", PERMISSION_OWNER ) );
     226  registerVar( new SynchronizeableBool( &bDown, &bDown, "bDown", PERMISSION_OWNER ) );
     227  registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) );
     228  registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) );
     229  registerVar( new SynchronizeableBool( &bAscend, &bAscend, "bAscend", PERMISSION_OWNER ) );
     230  registerVar( new SynchronizeableBool( &bDescend, &bDescend, "bDescend", PERMISSION_OWNER ) );
     231  registerVar( new SynchronizeableBool( &bRollL, &bRollL, "bRollL", PERMISSION_OWNER ) );
     232  registerVar( new SynchronizeableBool( &bRollR, &bRollR, "bRollR", PERMISSION_OWNER ) );
    237233}
    238234
     
    306302    if ( isServer() )
    307303    {
    308       networkCollisionList.push_back( entity->getHealth() );
    309       doCollideNetwork( entity->getHealth() );
     304      //TODO handle this
    310305    }
    311306  }
     
    349344
    350345  // spaceship controlled movement
    351   if (this->getOwner() == this->getHostID())
     346  //if (this->getOwner() == this->getHostID())
    352347    this->calculateVelocity(time);
    353348
     
    509504
    510505
    511 #define MASK_bUp         1
    512 #define MASK_bDown       2
    513 #define MASK_bLeft       4
    514 #define MASK_bRight      8
    515 #define MASK_bAscend    16
    516 #define MASK_bDescend   32
    517 #define MASK_bRollL     64
    518 #define MASK_bRollR    128
    519 
    520 #define DATA_state       1
    521 #define DATA_flags       2
    522 #define DATA_mouse       3
    523 #define DATA_sync        4
    524 #define DATA_velocity    5
    525 #define DATA_playables   6
    526 #define DATA_collision   7
    527 
    528 int SpaceShip::writeBytes( const byte * data, int length, int sender )
    529 {
    530   SYNCHELP_READ_BEGIN();
    531 
    532   byte b;
    533 
    534   while ( SYNCHELP_READ_REMAINING()>0 )
    535   {
    536     SYNCHELP_READ_BYTE( b, NWT_SS_B );
    537 
    538     if ( b == DATA_state )
    539     {
    540       setRequestedSync( false );
    541       setIsOutOfSync( false );
    542       SYNCHELP_READ_FKT( WorldEntity::writeState, NWT_SS_WE_STATE );
    543 
    544       continue;
    545     }
    546 
    547     if ( b == DATA_flags )
    548     {
    549       if ( this->getOwner() != this->getHostID() )
    550       {
    551         byte flags = 0;
    552         SYNCHELP_READ_BYTE( flags, NWT_SS_FLAGS );
    553 
    554         bUp = (flags & MASK_bUp) != 0;
    555         bDown = (flags & MASK_bDown) != 0;
    556         bLeft = (flags & MASK_bLeft) != 0;
    557         bRight = (flags & MASK_bRight) != 0;
    558         bAscend = (flags & MASK_bAscend) != 0;
    559         bDescend = (flags & MASK_bDescend) != 0;
    560         bRollL = (flags & MASK_bRollL) != 0;
    561         bRollR = (flags & MASK_bRollR) != 0;
    562 
    563       }
    564       else
    565         assert(false);
    566 
    567       continue;
    568     }
    569 
    570     if ( b == DATA_mouse )
    571     {
    572       if ( this->getOwner() != this->getHostID() )
    573       {
    574         SYNCHELP_READ_FLOAT( mouseDir.w, NWT_SS_MOUSEDIRW );
    575         SYNCHELP_READ_FLOAT( mouseDir.v.x, NWT_SS_MOUSEDIRX );
    576         SYNCHELP_READ_FLOAT( mouseDir.v.y, NWT_SS_MOUSEDIRY );
    577         SYNCHELP_READ_FLOAT( mouseDir.v.z, NWT_SS_MOUSEDIRZ );
    578       }
    579       else
    580         assert(false);
    581 
    582       continue;
    583     }
    584 
    585     if ( b == DATA_sync )
    586     {
    587       if ( this->getOwner() != this->getHostID() )
    588       {
    589         SYNCHELP_READ_FKT( PNode::writeSync, NWT_SS_PN_SYNC );
    590       }
    591       else
    592         assert(false);
    593 
    594       continue;
    595     }
    596 
    597     if ( b == DATA_velocity )
    598     {
    599       if ( this->getOwner() != this->getHostID() )
    600       {
    601         SYNCHELP_READ_FLOAT( velocity.x, NWT_SS_VELX );
    602         SYNCHELP_READ_FLOAT( velocity.y, NWT_SS_VELY );
    603         SYNCHELP_READ_FLOAT( velocity.z, NWT_SS_VELZ );
    604       }
    605       else
    606         assert(false);
    607 
    608       continue;
    609     }
    610 
    611     if ( b == DATA_playables )
    612     {
    613       if ( this->getOwner() != this->getHostID() )
    614       {
    615         SYNCHELP_READ_FKT( Playable::writeSync, NWT_SS_PL_SYNC );
    616       }
    617       else
    618         assert(false);
    619     }
    620 
    621     if ( b == DATA_collision )
    622     {
    623       int n;
    624       float energy;
    625       SYNCHELP_READ_INT( n, NWT_SS_CO_N );
    626 
    627       for ( int i = 0; i<n; i++ )
    628       {
    629         SYNCHELP_READ_FLOAT( energy, NWT_SS_CO_CLID );
    630         doCollideNetwork( energy );
    631       }
    632     }
    633   }
    634 
    635   return SYNCHELP_READ_N;
    636 }
    637 
    638 
    639 
    640 int SpaceShip::readBytes( byte * data, int maxLength, int * reciever )
    641 {
    642   SYNCHELP_WRITE_BEGIN();
    643 
    644   if ( isOutOfSync() && !requestedSync() /*&& this->getHostID()!=this->getOwner()*/ )
    645   {
    646     (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
    647     setRequestedSync( true );
    648     PRINTF(0)("REQUESTED STATE %d\n", this->getUniqueID());
    649   }
    650 
    651   int rec = this->getRequestSync();
    652   if ( rec > 0 )
    653   {
    654     *reciever = rec;
    655 
    656     PRINTF(0)("SEND STATE %d %d\n", this->getUniqueID(), rec);
    657 
    658     SYNCHELP_WRITE_BYTE( (byte)DATA_state, NWT_SS_B );
    659 
    660     SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_SS_WE_STATE );
    661 
    662     return SYNCHELP_WRITE_N;
    663   }
    664 
    665   *reciever = 0 - this->getOwner();
    666   //TODO: implement with SYNCHELP_WRITE_SENT()
    667   bool sentSomething = false;
    668 
    669   if ( PNode::needsReadSync() && ( this->getHostID()==0 || this->getOwner() == this->getHostID() ) )
    670   {
    671     PRINTF(0)("sending PNode::readSync\n");
    672     SYNCHELP_WRITE_BYTE( DATA_sync, NWT_SS_B );
    673     SYNCHELP_WRITE_FKT( PNode::readSync, NWT_SS_PN_SYNC );
    674     sentSomething = true;
    675   }
    676 
    677   if ( this->getHostID()==0 || this->getHostID()==this->getOwner() )
    678   {
    679     byte mask = 0;
    680 
    681     if ( bUp )
    682       mask |= MASK_bUp;
    683     if ( bDown )
    684       mask |= MASK_bDown;
    685     if ( bLeft )
    686       mask |= MASK_bLeft;
    687     if ( bRight )
    688       mask |= MASK_bRight;
    689     if ( bAscend )
    690       mask |= MASK_bAscend;
    691     if ( bRollL )
    692       mask |= MASK_bRollL;
    693     if ( bRollR )
    694       mask |= MASK_bRollR;
    695 
    696 
    697     if ( mask != oldMask )
    698     {
    699       oldMask = mask;
    700       PRINTF(0)("sending mask\n");
    701       sentSomething = true;
    702       SYNCHELP_WRITE_BYTE( DATA_flags, NWT_SS_B );
    703       SYNCHELP_WRITE_BYTE( mask, NWT_SS_FLAGS );
    704     }
    705 #define __OFFSET_MDIR_W 0.01
    706 #define __OFFSET_MDIR_V 0.01
    707     if ( fabs( oldMouseDir.w - mouseDir.w ) > __OFFSET_MDIR_W ||
    708          fabs( oldMouseDir.v.x - mouseDir.v.x ) > __OFFSET_MDIR_V ||
    709          fabs( oldMouseDir.v.y - mouseDir.v.y ) > __OFFSET_MDIR_V ||
    710          fabs( oldMouseDir.v.z - mouseDir.v.z ) > __OFFSET_MDIR_V )
    711     {
    712       oldMouseDir = mouseDir;
    713 
    714       SYNCHELP_WRITE_BYTE( DATA_mouse, NWT_SS_B );
    715       PRINTF(0)("SENDING mousedir\n");
    716       sentSomething = true;
    717       SYNCHELP_WRITE_FLOAT( mouseDir.w, NWT_SS_MOUSEDIRW );
    718       SYNCHELP_WRITE_FLOAT( mouseDir.v.x, NWT_SS_MOUSEDIRX );
    719       SYNCHELP_WRITE_FLOAT( mouseDir.v.y, NWT_SS_MOUSEDIRY );
    720       SYNCHELP_WRITE_FLOAT( mouseDir.v.z, NWT_SS_MOUSEDIRZ );
    721     }
    722 #define __OFFSET_VEL 0.05
    723     if ( fabs( oldVelocity.x - velocity.x ) > __OFFSET_VEL*fabs(oldVelocity.x)+0.1 ||
    724          fabs( oldVelocity.y - velocity.y ) > __OFFSET_VEL*fabs(oldVelocity.y)+0.1 ||
    725          fabs( oldVelocity.z - velocity.z ) > __OFFSET_VEL*fabs(oldVelocity.z)+0.1 )
    726     {
    727       oldVelocity.x = velocity.x;
    728       oldVelocity.y = velocity.y;
    729       oldVelocity.z = velocity.z;
    730       PRINTF(0)("SENDING velocity\n");
    731       sentSomething = true;
    732       SYNCHELP_WRITE_BYTE( DATA_velocity, NWT_SS_B );
    733       SYNCHELP_WRITE_FLOAT( velocity.x, NWT_SS_VELX );
    734       SYNCHELP_WRITE_FLOAT( velocity.y, NWT_SS_VELY );
    735       SYNCHELP_WRITE_FLOAT( velocity.z, NWT_SS_VELZ );
    736     }
    737 
    738     while ( Playable::needsReadSync() )
    739     {
    740       sentSomething = true;
    741       PRINTF(0)("SYNCHELP_WRITE_FKT( Playable::readSync, NWT_SS_PL_SYNC )\n");
    742       SYNCHELP_WRITE_BYTE( DATA_playables, NWT_SS_B );
    743       SYNCHELP_WRITE_FKT( Playable::readSync, NWT_SS_PL_SYNC );
    744     }
    745 
    746   }
    747 
    748   if ( !sentSomething )
    749   {
    750     *reciever = 0;
    751 
    752     if ( networkCollisionList.size()>0 )
    753     {
    754       SYNCHELP_WRITE_BYTE( DATA_collision, NWT_SS_B );
    755 
    756       SYNCHELP_WRITE_INT( networkCollisionList.size(), NWT_SS_CO_N );
    757 
    758       for ( std::list<float>::iterator it = networkCollisionList.begin(); it!=networkCollisionList.end(); it++ )
    759       {
    760         SYNCHELP_WRITE_FLOAT( *it, NWT_SS_CO_CLID );
    761       }
    762 
    763       networkCollisionList.clear();
    764     }
    765   }
    766 
    767   return SYNCHELP_WRITE_N;
    768 }
    769 
    770 
    771 void SpaceShip::doCollideNetwork( float energy )
    772 {
    773   this->decreaseHealth( energy );
    774   if( this->getHealth() <= 0)
    775   {
    776     this->die();
    777   }
    778 }
    779 
    780 
    781 
     506
     507
Note: See TracChangeset for help on using the changeset viewer.