Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 29, 2006, 1:57:48 PM (18 years ago)
Author:
rennerc
Message:

new network system implemented. yet with a lot of empty function bodys

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/world_entities/space_ships/space_ship.cc

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