Changeset 7954 in orxonox.OLD for trunk/src/world_entities/environments
- Timestamp:
- May 29, 2006, 3:28:41 PM (19 years ago)
- Location:
- trunk/src/world_entities/environments
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/world_entities/environments/water.cc
r7370 r7954 59 59 // To test the Wave equation 60 60 //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" ) ); 61 67 } 62 68 … … 291 297 292 298 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 */ 304 void 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 316 WorldEntity::varChangeHandler( id ); 317 } -
trunk/src/world_entities/environments/water.h
r7125 r7954 38 38 void draw() const; 39 39 void tick(float dt); 40 41 virtual int writeBytes(const byte* data, int length, int sender); 42 virtual int readBytes(byte* data, int maxLength, int * reciever); 43 44 int writeState( const byte * data, int length, int sender ); 45 int readState( byte * data, int maxLength ); 40 41 virtual void varChangeHandler( std::list<int> & id ); 46 42 47 43 private: … … 56 52 Material waterMaterial; 57 53 Shader* waterShader; 54 58 55 float height; //!< The hight of the Water 56 int height_handle; //!< Handle to notify about changes of height 59 57 60 unsigned int resX, resY; 61 float sizeX, sizeY; 58 unsigned int resX, resY; //!< Grid resolution 59 int resX_handle; //!< Handle to notify about changes of resX 60 int resY_handle; //!< Handle to notify about changes of resY 61 float sizeX, sizeY; //!< waters size 62 int sizeX_handle; //!< Handle to notify about changes of sizeX 63 int sizeY_handle; //!< Handle to notify about changes of sizeY 62 64 63 65 float phase;
Note: See TracChangeset
for help on using the changeset viewer.