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/environments/water.cc

    r7370 r7444  
    5959  // To test the Wave equation
    6060  //this->wave(5.0,4.0, 1, 10);
     61 
     62  height_handle = registerVarId( new SynchronizeableFloat( &height, &height, "height" ) );
     63  resX_handle = registerVarId( new SynchronizeableUInt( &resX, &resX, "resX" ) );
     64  resY_handle = registerVarId( new SynchronizeableUInt( &resY, &resY, "resY" ) );
     65  sizeX_handle = registerVarId( new SynchronizeableFloat( &sizeX, &sizeX, "sizeX" ) );
     66  sizeY_handle = registerVarId( new SynchronizeableFloat( &sizeY, &sizeY, "sizeY" ) );
    6167}
    6268
     
    291297
    292298
    293 /**
    294  * Writes data from network containing information about the state
    295  * @param data pointer to data
    296  * @param length length of data
    297  * @param sender hostID of sender
    298  */
    299 int Water::writeBytes( const byte * data, int length, int sender )
    300 {
    301   setRequestedSync( false );
    302   setIsOutOfSync( false );
    303 
    304   SYNCHELP_READ_BEGIN();
    305 
    306   SYNCHELP_READ_FKT( Water::writeState, NWT_WAT_STATE );
    307 
    308   return SYNCHELP_READ_N;
    309 }
    310 
    311 
    312 /**
    313  * data copied in data will bee sent to another host
    314  * @param data pointer to data
    315  * @param maxLength max length of data
    316  * @return the number of bytes writen
    317  */
    318 int Water::readBytes( byte * data, int maxLength, int * reciever )
    319 {
    320   SYNCHELP_WRITE_BEGIN();
    321 
    322   if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
    323   {
    324     (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
    325     setRequestedSync( true );
    326   }
    327 
    328   int rec = this->getRequestSync();
    329   if ( rec > 0 )
    330   {
    331     *reciever = rec;
    332     SYNCHELP_WRITE_FKT( Water::readState, NWT_WAT_STATE );
    333   }
    334 
    335   *reciever = 0;
    336   return SYNCHELP_WRITE_N;
    337 }
    338 
    339 
    340 
    341 /**
    342  * data copied in data will bee sent to another host
    343  * @param data pointer to data
    344  * @param maxLength max length of data
    345  * @return the number of bytes writen
    346  */
    347 int Water::readState( byte * data, int maxLength )
    348 {
    349   SYNCHELP_WRITE_BEGIN();
    350 
    351   SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_WAT_WE_STATE );
    352 
    353   // sync the size
    354   SYNCHELP_WRITE_FLOAT( this->sizeX, NWT_WAT_SIZEX );
    355   SYNCHELP_WRITE_FLOAT( this->sizeY, NWT_WAT_SIZEY );
    356 
    357   //sync resolution
    358   SYNCHELP_WRITE_INT( this->resX, NWT_WAT_RESX );
    359   SYNCHELP_WRITE_INT( this->resY, NWT_WAT_RESY );
    360 
    361   //sync the height
    362   SYNCHELP_WRITE_FLOAT( this->height, NWT_WAT_HEIGHT );
    363 
    364   return SYNCHELP_WRITE_N;
    365 }
    366 
    367 
    368 /**
    369  * Writes data from network containing information about the state
    370  * @param data pointer to data
    371  * @param length length of data
    372  * @param sender hostID of sender
    373  */
    374 int Water::writeState( const byte * data, int length, int sender )
    375 {
    376   SYNCHELP_READ_BEGIN();
    377 
    378   SYNCHELP_READ_FKT( WorldEntity::writeState, NWT_WAT_WE_STATE );
    379 
    380   float f1, f2;
    381   int i1, i2;
    382 
    383   //read the size
    384   SYNCHELP_READ_FLOAT( f1, NWT_WAT_SIZEX );
    385   SYNCHELP_READ_FLOAT( f2, NWT_WAT_SIZEY );
    386   this->sizeX = f1;
    387   this->sizeY = f2;
    388   PRINTF(0)("Setting Water to size: %f x %f\n", f1, f2);
    389 
    390   //read the resolution
    391   SYNCHELP_READ_INT( i1, NWT_WAT_RESX );
    392   SYNCHELP_READ_INT( i2, NWT_WAT_RESY );
    393   this->resX = i1;
    394   this->resY = i2;
    395   PRINTF(0)("Setting Water to resolution: %i x %i\n", i1, i2);
    396 
    397   //read the height
    398   SYNCHELP_READ_FLOAT( f1, NWT_WAT_HEIGHT );
    399   this->height = f1;
    400 
    401   this->rebuildGrid();
    402 
    403   return SYNCHELP_READ_N;
    404 }
    405 
    406 
     299
     300/**
     301 * function to handle changes in synced vars
     302 * @param id ids which have changed
     303 */
     304void Water::varChangeHandler( std::list< int > & id )
     305{
     306  if ( std::find( id.begin(), id.end(), height_handle ) != id.end() ||
     307       std::find( id.begin(), id.end(), resX_handle ) != id.end() ||
     308       std::find( id.begin(), id.end(), resY_handle ) != id.end() ||
     309       std::find( id.begin(), id.end(), sizeX_handle ) != id.end() ||
     310       std::find( id.begin(), id.end(), sizeY_handle ) != id.end()
     311     )
     312  {
     313    this->rebuildGrid();
     314  }
     315}
Note: See TracChangeset for help on using the changeset viewer.