Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6686 in orxonox.OLD


Ignore:
Timestamp:
Jan 25, 2006, 11:05:01 AM (18 years ago)
Author:
patrick
Message:

network: water gets synced correctly now

Location:
branches/network/src/world_entities/environments
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/world_entities/environments/water.cc

    r6685 r6686  
    2828#include "skybox.h"
    2929
     30#include "network_game_manager.h"
    3031
    3132using namespace std;
     
    229230int Water::writeBytes( const byte * data, int length, int sender )
    230231{
    231 //   setRequestedSync( false );
    232 //   setIsOutOfSync( false );
    233 //
    234 //   SYNCHELP_READ_BEGIN();
    235 //
    236 //   SYNCHELP_READ_FKT( WorldEntity::writeState );
    237 //
    238 //   return SYNCHELP_READ_N;
     232  setRequestedSync( false );
     233  setIsOutOfSync( false );
     234
     235  SYNCHELP_READ_BEGIN();
     236
     237  SYNCHELP_READ_FKT( Water::writeState );
     238
     239  return SYNCHELP_READ_N;
    239240}
    240241
     
    248249int Water::readBytes( byte * data, int maxLength, int * reciever )
    249250{
    250 //   SYNCHELP_WRITE_BEGIN();
    251 //
    252 //   if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
    253 //   {
    254 //     (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
    255 //     setRequestedSync( true );
    256 //   }
    257 //
    258 //   int rec = this->getRequestSync();
    259 //   if ( rec > 0 )
    260 //   {
    261 //     *reciever = rec;
    262 //
    263 //     SYNCHELP_WRITE_FKT( WorldEntity::readState );
    264 //
    265 //   }
    266 //
    267 //   *reciever = 0;
    268 //   return SYNCHELP_WRITE_N;
    269 }
     251  SYNCHELP_WRITE_BEGIN();
     252
     253  if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
     254  {
     255    (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
     256    setRequestedSync( true );
     257  }
     258
     259  int rec = this->getRequestSync();
     260  if ( rec > 0 )
     261  {
     262    *reciever = rec;
     263    SYNCHELP_WRITE_FKT( Water::readState );
     264  }
     265
     266  *reciever = 0;
     267  return SYNCHELP_WRITE_N;
     268}
     269
     270
     271
     272/**
     273 * data copied in data will bee sent to another host
     274 * @param data pointer to data
     275 * @param maxLength max length of data
     276 * @return the number of bytes writen
     277 */
     278int Water::readState( byte * data, int maxLength )
     279{
     280  SYNCHELP_WRITE_BEGIN();
     281
     282  SYNCHELP_WRITE_FKT( WorldEntity::readState );
     283
     284  // sync the size
     285  SYNCHELP_WRITE_FLOAT( this->sizeX );
     286  SYNCHELP_WRITE_FLOAT( this->sizeY );
     287
     288  //sync resolution
     289  SYNCHELP_WRITE_INT( this->resX );
     290  SYNCHELP_WRITE_INT( this->resY );
     291
     292  //sync the height
     293  SYNCHELP_WRITE_FLOAT( this->height );
     294
     295  return SYNCHELP_WRITE_N;
     296}
     297
     298
     299/**
     300 * Writes data from network containing information about the state
     301 * @param data pointer to data
     302 * @param length length of data
     303 * @param sender hostID of sender
     304 */
     305int Water::writeState( const byte * data, int length, int sender )
     306{
     307  SYNCHELP_READ_BEGIN();
     308
     309  SYNCHELP_READ_FKT( WorldEntity::writeState );
     310
     311  float f1, f2;
     312  int i1, i2;
     313
     314  //read the size
     315  SYNCHELP_READ_FLOAT( f1 );
     316  SYNCHELP_READ_FLOAT( f2 );
     317  this->sizeX = f1;
     318  this->sizeY = f2;
     319  PRINTF(0)("Setting Water to size: %f x %f\n", f1, f2);
     320
     321  //read the resolution
     322  SYNCHELP_READ_INT( i1 );
     323  SYNCHELP_READ_INT( i2 );
     324  this->resX = i1;
     325  this->resY = i2;
     326  PRINTF(0)("Setting Water to resolution: %i x %i\n", i1, i2);
     327
     328  //read the height
     329  SYNCHELP_READ_FLOAT( f1 );
     330  this->height = f1;
     331
     332  this->rebuildGrid();
     333
     334  return SYNCHELP_READ_N;
     335}
     336
     337
  • branches/network/src/world_entities/environments/water.h

    r6685 r6686  
    3838   virtual int readBytes(byte* data, int maxLength, int * reciever);
    3939
     40   int writeState( const byte * data, int length, int sender );
     41   int readState( byte * data, int maxLength );
     42
    4043
    4144  private:
Note: See TracChangeset for help on using the changeset viewer.