Changeset 7444 in orxonox.OLD for branches/network/src/world_entities
- Timestamp:
- Apr 29, 2006, 1:57:48 PM (19 years ago)
- Location:
- branches/network/src/world_entities
- Files:
-
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/world_entities/environments/water.cc
r7370 r7444 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 } -
branches/network/src/world_entities/environments/water.h
r7125 r7444 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; -
branches/network/src/world_entities/npcs/ground_turret.cc
r7193 r7444 180 180 Explosion::explode(this, Vector(10,10,10)); 181 181 } 182 183 /**184 * Writes data from network containing information about the state185 * @param data pointer to data186 * @param length length of data187 * @param sender hostID of sender188 */189 int GroundTurret::writeBytes( const byte * data, int length, int sender )190 {191 setRequestedSync( false );192 setIsOutOfSync( false );193 194 SYNCHELP_READ_BEGIN();195 196 SYNCHELP_READ_FKT( WorldEntity::writeState, NWT_GT_WE_STATE );197 198 return SYNCHELP_READ_N;199 }200 201 /**202 * data copied in data will bee sent to another host203 * @param data pointer to data204 * @param maxLength max length of data205 * @return the number of bytes writen206 */207 int GroundTurret::readBytes( byte * data, int maxLength, int * reciever )208 {209 SYNCHELP_WRITE_BEGIN();210 211 if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )212 {213 (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );214 setRequestedSync( true );215 }216 217 int rec = this->getRequestSync();218 if ( rec > 0 )219 {220 *reciever = rec;221 222 SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_GT_WE_STATE );223 224 }225 226 *reciever = 0;227 return SYNCHELP_WRITE_N;228 } -
branches/network/src/world_entities/npcs/ground_turret.h
r7102 r7444 30 30 virtual void tick(float time); 31 31 32 virtual int writeBytes(const byte* data, int length, int sender);33 virtual int readBytes(byte* data, int maxLength, int * reciever);34 35 32 private: 36 33 PNode weaponHolder[2]; -
branches/network/src/world_entities/playable.cc
r7356 r7444 60 60 61 61 this->score = 0; 62 this->oldScore = 0;63 62 64 63 this->bDead = false; 64 65 registerVar( new SynchronizeableInt( &score, &score, "score" ) ); 65 66 } 66 67 … … 480 481 481 482 482 #define DATA_FLAGS 1483 #define DATA_SCORE 2484 485 #define FLAGS_bFire 1486 487 int Playable::writeSync( const byte * data, int length, int sender )488 {489 SYNCHELP_READ_BEGIN();490 491 byte b;492 SYNCHELP_READ_BYTE( b, NWT_PL_B );493 494 byte flags;495 496 if ( b == DATA_FLAGS )497 {498 SYNCHELP_READ_BYTE( flags, NWT_PL_FLAGS );499 500 bFire = (flags & FLAGS_bFire) != 0;501 502 return SYNCHELP_READ_N;503 }504 505 if ( b == DATA_SCORE )506 {507 int newScore;508 SYNCHELP_READ_BYTE( newScore, NWT_PL_SCORE );509 setScore( newScore );510 511 return SYNCHELP_READ_N;512 }513 514 return SYNCHELP_READ_N;515 }516 517 int Playable::readSync( byte * data, int maxLength )518 {519 SYNCHELP_WRITE_BEGIN();520 521 if ( score != oldScore && isServer() )522 {523 SYNCHELP_WRITE_BYTE( DATA_SCORE, NWT_PL_B);524 SYNCHELP_WRITE_INT( score, NWT_PL_SCORE );525 oldScore = score;526 527 return SYNCHELP_WRITE_N;528 }529 530 byte flags = 0;531 532 if ( bFire )533 flags |= FLAGS_bFire;534 535 536 SYNCHELP_WRITE_BYTE( DATA_FLAGS, NWT_PL_B);537 SYNCHELP_WRITE_BYTE( flags, NWT_PL_FLAGS );538 oldFlags = flags;539 540 541 return SYNCHELP_WRITE_N;542 }543 544 bool Playable::needsReadSync( )545 {546 if ( score != oldScore && isServer() )547 return true;548 549 byte flags = 0;550 551 if ( bFire )552 flags |= FLAGS_bFire;553 554 return flags!=oldFlags;555 }556 557 483 558 484 /** -
branches/network/src/world_entities/playable.h
r7351 r7444 79 79 virtual void tick(float dt); 80 80 81 // NETWORK82 int writeSync(const byte* data, int length, int sender);83 int readSync(byte* data, int maxLength );84 bool needsReadSync();85 86 87 81 // Transformations: 88 82 static Playable::Playmode stringToPlaymode(const std::string& playmode); … … 111 105 int oldFlags; //!< Used for synchronisation 112 106 113 int score; 114 int oldScore; 107 int score; //!< players score 115 108 116 109 bool bDead; -
branches/network/src/world_entities/power_ups/laser_power_up.cc
r7193 r7444 120 120 } 121 121 122 int LaserPowerUp::writeBytes( const byte * data, int length, int sender )123 {124 setRequestedSync( false );125 setIsOutOfSync( false );126 122 127 SYNCHELP_READ_BEGIN();128 129 SYNCHELP_READ_FKT( PowerUp::writeState, NWT_LPU_WE_STATE );130 131 return SYNCHELP_READ_N;132 }133 134 135 136 int LaserPowerUp::readBytes( byte * data, int maxLength, int * reciever )137 {138 if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )139 {140 (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );141 setRequestedSync( true );142 }143 144 int rec = this->getRequestSync();145 if ( rec > 0 )146 {147 *reciever = rec;148 149 SYNCHELP_WRITE_BEGIN();150 151 SYNCHELP_WRITE_FKT( PowerUp::readState, NWT_LPU_WE_STATE );152 153 return SYNCHELP_WRITE_N;154 }155 156 *reciever = 0;157 return 0;158 }159 -
branches/network/src/world_entities/power_ups/laser_power_up.h
r6512 r7444 26 26 virtual void draw() const; 27 27 28 virtual int writeBytes(const byte* data, int length, int sender);29 virtual int readBytes(byte* data, int maxLength, int * reciever );30 31 28 private: 32 29 void init(); -
branches/network/src/world_entities/power_ups/param_power_up.cc
r7221 r7444 43 43 if( root != NULL) 44 44 this->loadParams(root); 45 46 registerVar( new SynchronizeableInt( (int*)&type, (int*)&type, "type" ) ); 47 registerVar( new SynchronizeableFloat( &value, &value, "value" ) ); 48 registerVar( new SynchronizeableFloat( &max_value, &max_value, "max_value" ) ); 49 registerVar( new SynchronizeableFloat( &min_value, &min_value, "min_value" ) ); 45 50 } 46 51 … … 119 124 } 120 125 121 int ParamPowerUp::writeBytes( const byte * data, int length, int sender )122 {123 setRequestedSync( false );124 setIsOutOfSync( false );125 126 SYNCHELP_READ_BEGIN();127 128 SYNCHELP_READ_FKT( PowerUp::writeState, NWT_PPU_WE_STATE );129 130 int i;131 SYNCHELP_READ_INT( i, NWT_PPU_TYPE );132 this->type = (EnumParamPowerUpType)i;133 SYNCHELP_READ_FLOAT( this->value, NWT_PPU_VALUE );134 135 if ( this->value != 0 )136 {137 SYNCHELP_READ_FLOAT( this->min_value, NWT_PPU_MINVALUE );138 SYNCHELP_READ_FLOAT( this->max_value, NWT_PPU_MAXVALUE );139 respawn();140 }141 142 return SYNCHELP_READ_N;143 }144 145 146 147 int ParamPowerUp::readBytes( byte * data, int maxLength, int * reciever )148 {149 if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )150 {151 (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );152 setRequestedSync( true );153 }154 155 int rec = this->getRequestSync();156 if ( rec > 0 )157 {158 *reciever = rec;159 160 SYNCHELP_WRITE_BEGIN();161 162 SYNCHELP_WRITE_FKT( PowerUp::readState, NWT_PPU_WE_STATE );163 164 int i = (int)this->type;165 SYNCHELP_WRITE_INT( i, NWT_PPU_TYPE );166 SYNCHELP_WRITE_FLOAT( this->value, NWT_PPU_VALUE );167 168 if ( this->value != 0 )169 {170 SYNCHELP_WRITE_FLOAT( this->min_value, NWT_PPU_MINVALUE );171 SYNCHELP_WRITE_FLOAT( this->max_value, NWT_PPU_MAXVALUE );172 }173 174 return SYNCHELP_WRITE_N;175 }176 177 *reciever = 0;178 return 0;179 }180 -
branches/network/src/world_entities/power_ups/param_power_up.h
r7221 r7444 32 32 float getValue(); 33 33 34 virtual int writeBytes(const byte* data, int length, int sender);35 virtual int readBytes(byte* data, int maxLength, int * reciever );36 37 34 protected: 38 35 virtual void respawn(); -
branches/network/src/world_entities/power_ups/power_up.cc
r7221 r7444 201 201 202 202 203 /********************************************************************************************204 NETWORK STUFF205 ********************************************************************************************/206 207 208 /**209 * data copied in data will bee sent to another host210 * @param data pointer to data211 * @param maxLength max length of data212 * @return the number of bytes writen213 */214 int PowerUp::readState( byte * data, int maxLength )215 {216 SYNCHELP_WRITE_BEGIN();217 SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_PU_WE_STATE );218 return SYNCHELP_WRITE_N;219 }220 221 222 /**223 * Writes data from network containing information about the state224 * @param data pointer to data225 * @param length length of data226 * @param sender hostID of sender227 */228 int PowerUp::writeState( const byte * data, int length, int sender )229 {230 SYNCHELP_READ_BEGIN();231 SYNCHELP_READ_FKT( WorldEntity::writeState, NWT_PU_WE_STATE );232 return SYNCHELP_READ_N;233 }234 -
branches/network/src/world_entities/power_ups/power_up.h
r7221 r7444 34 34 void setRespawnTime(const float respawn); 35 35 36 int writeState(const byte* data, int length, int sender);37 int readState(byte* data, int maxLength );38 39 36 protected: 40 37 PowerUp(float r, float g, float b); -
branches/network/src/world_entities/power_ups/turret_power_up.cc
r7193 r7444 115 115 glPopMatrix(); 116 116 } 117 118 119 120 121 /********************************************************************************************122 NETWORK STUFF123 ********************************************************************************************/124 125 126 int TurretPowerUp::writeBytes( const byte * data, int length, int sender )127 {128 setRequestedSync( false );129 setIsOutOfSync( false );130 131 SYNCHELP_READ_BEGIN();132 133 SYNCHELP_READ_FKT( PowerUp::writeState, NWT_TPU_WE_STATE );134 135 return SYNCHELP_READ_N;136 }137 138 139 int TurretPowerUp::readBytes( byte * data, int maxLength, int * reciever )140 {141 if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )142 {143 (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );144 setRequestedSync( true );145 }146 147 int rec = this->getRequestSync();148 if ( rec > 0 )149 {150 *reciever = rec;151 152 SYNCHELP_WRITE_BEGIN();153 154 SYNCHELP_WRITE_FKT( PowerUp::readState, NWT_TPU_WE_STATE );155 156 return SYNCHELP_WRITE_N;157 }158 159 *reciever = 0;160 return 0;161 } -
branches/network/src/world_entities/power_ups/turret_power_up.h
r7065 r7444 24 24 virtual void draw() const; 25 25 26 virtual int writeBytes(const byte* data, int length, int sender);27 virtual int readBytes(byte* data, int maxLength, int * reciever );28 29 26 private: 30 27 void init(); -
branches/network/src/world_entities/power_ups/weapon_power_up.cc
r7370 r7444 103 103 } 104 104 105 int WeaponPowerUp::writeBytes( const byte * data, int length, int sender )106 {107 setRequestedSync( false );108 setIsOutOfSync( false );109 110 SYNCHELP_READ_BEGIN();111 112 SYNCHELP_READ_FKT( PowerUp::writeState, NWT_WPU_WE_STATE );113 114 //TODO: sync weapon class ( see loadParams )115 116 return SYNCHELP_READ_N;117 }118 119 120 121 int WeaponPowerUp::readBytes( byte * data, int maxLength, int * reciever )122 {123 if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )124 {125 (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );126 setRequestedSync( true );127 }128 129 int rec = this->getRequestSync();130 if ( rec > 0 )131 {132 *reciever = rec;133 134 SYNCHELP_WRITE_BEGIN();135 136 SYNCHELP_WRITE_FKT( PowerUp::readState, NWT_WPU_WE_STATE );137 138 //TODO: sync weapon class ( see loadParams )139 140 return SYNCHELP_WRITE_N;141 }142 143 *reciever = 0;144 return 0;145 } -
branches/network/src/world_entities/power_ups/weapon_power_up.h
r7221 r7444 24 24 void setWeaponClass(const std::string& name); 25 25 26 virtual int writeBytes(const byte* data, int length, int sender);27 virtual int readBytes(byte* data, int maxLength, int * reciever );28 29 26 bool process(WeaponManager* manager); 30 27 -
branches/network/src/world_entities/skybox.cc
r7328 r7444 95 95 { 96 96 this->rebuild(); 97 98 textureName_handle = registerVarId( new SynchronizeableString( &textureName, &textureName, "textureName") ); 99 size_handle = registerVarId( new SynchronizeableFloat( &size, &size, "size" ) ); 97 100 } 98 101 … … 292 295 } 293 296 294 int SkyBox::writeBytes( const byte * data, int length, int sender ) 295 { 296 setRequestedSync( false ); 297 setIsOutOfSync( false ); 298 299 SYNCHELP_READ_BEGIN(); 300 301 SYNCHELP_READ_FKT( WorldEntity::writeState, NWT_SB_WE_STATE ); 302 303 SYNCHELP_READ_FLOAT( size, NWT_SB_SIZE ); 304 if ( !this->textureName.empty() ) 305 { 306 textureName = ""; 307 } 308 std::string texName; 309 SYNCHELP_READ_STRING( texName, NWT_SB_TEXTURENAME ); 310 311 this->setSize( size ); 312 this->setTextureAndType( texName, "jpg" ); 313 this->rebuild(); 314 315 return SYNCHELP_READ_N; 316 } 317 318 319 320 int SkyBox::readBytes( byte * data, int maxLength, int * reciever ) 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 333 SYNCHELP_WRITE_BEGIN(); 334 335 SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_SB_WE_STATE ); 336 337 SYNCHELP_WRITE_FLOAT(this->size, NWT_SB_SIZE); 338 SYNCHELP_WRITE_STRING(this->textureName, NWT_SB_TEXTURENAME); 339 340 return SYNCHELP_WRITE_N; 341 } 342 343 *reciever = 0; 344 return 0; 345 } 346 347 void SkyBox::writeDebug( ) const 348 { 349 } 350 351 void SkyBox::readDebug( ) const 352 { 353 } 297 void SkyBox::varChangeHandler( std::list< int > & id ) 298 { 299 #warning implement this 300 } -
branches/network/src/world_entities/skybox.h
r7328 r7444 58 58 static void disableCubeMap(); 59 59 60 virtual int writeBytes(const byte* data, int length, int sender); 61 virtual int readBytes(byte* data, int maxLength, int * reciever); 62 virtual void writeDebug() const; 63 virtual void readDebug() const; 60 virtual void varChangeHandler( std::list<int> & id ); 64 61 65 62 private: … … 72 69 float textureSize; //!< this is the length of a texture (assumes a square texture) 73 70 std::string textureName; //!< Name of the Texture 71 72 int textureName_handle; //!< used to notify about changes of textureName 73 int size_handle; //!< used to notify about changes of size 74 74 75 75 }; -
branches/network/src/world_entities/space_ships/space_ship.cc
r7346 r7444 94 94 if (root != NULL) 95 95 this->loadParams(root); 96 else97 {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 else106 {107 this->loadModel( "models/ships/fighter.obj" );108 this->toList(OM_GROUP_01);109 }110 }111 96 112 97 } … … 235 220 this->burstSystem->setColor(0.5, .5,.5,.8,.8); 236 221 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" ) ); 238 234 } 239 235 … … 307 303 if ( isServer() ) 308 304 { 309 networkCollisionList.push_back( entity->getHealth() ); 310 doCollideNetwork( entity->getHealth() ); 305 //TODO handle this 311 306 } 312 307 } … … 510 505 511 506 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 -
branches/network/src/world_entities/space_ships/space_ship.h
r7346 r7444 46 46 virtual int readBytes(byte* data, int maxLength, int * reciever); 47 47 48 //HACK HACK HACK HACK make this private or remove it49 void doCollideNetwork( float energy );50 std::list<float> networkCollisionList;51 52 48 private: 53 49 void init(); -
branches/network/src/world_entities/terrain.cc
r7221 r7444 423 423 } 424 424 425 int Terrain::writeBytes( const byte * data, int length, int sender )426 {427 setRequestedSync( false );428 setIsOutOfSync( false );429 430 SYNCHELP_READ_BEGIN();431 SYNCHELP_READ_FKT( WorldEntity::writeState, NWT_TER_WE_STATE );432 433 return SYNCHELP_READ_N;434 }435 436 int Terrain::readBytes( byte * data, int maxLength, int * reciever )437 {438 if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )439 {440 (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );441 setRequestedSync( true );442 }443 444 int rec = this->getRequestSync();445 if ( rec > 0 )446 {447 *reciever = rec;448 449 SYNCHELP_WRITE_BEGIN();450 SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_TER_WE_STATE );451 return SYNCHELP_WRITE_N;452 453 }454 455 *reciever = 0;456 return 0;457 }458 459 void Terrain::writeDebug( ) const460 {}461 462 void Terrain::readDebug( ) const463 {}464 465 425 float Terrain::getHeight(float x, float y) 466 426 { -
branches/network/src/world_entities/terrain.h
r7221 r7444 33 33 virtual ~Terrain(); 34 34 35 virtual int writeBytes(const byte* data, int length, int sender);36 virtual int readBytes(byte* data, int maxLength, int * reciever);37 virtual void writeDebug() const;38 virtual void readDebug() const;39 40 35 void init(); 41 36 virtual void loadParams(const TiXmlElement* root); -
branches/network/src/world_entities/world_entity.cc
r7230 r7444 65 65 66 66 this->toList(OM_NULL); 67 68 modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName" ) ); 69 scaling_handle = registerVarId( new SynchronizeableFloat( &scaling, &scaling, "scaling" ) ); 67 70 } 68 71 … … 123 126 this->modelLODName = fileName; 124 127 this->scaling = scaling; 128 129 std::string name = fileName; 130 131 if ( name.find( ResourceManager::getInstance()->getDataDir() ) == 0 ) 132 { 133 name.erase(ResourceManager::getInstance()->getDataDir().size()); 134 } 135 136 this->modelFileName = name; 137 125 138 if (!fileName.empty()) 126 139 { … … 504 517 505 518 506 507 508 /******************************************************************************************** 509 NETWORK STUFF 510 ********************************************************************************************/ 511 512 513 /** 514 * Writes data from network containing information about the state 515 * @param data pointer to data 516 * @param length length of data 517 * @param sender hostID of sender 518 */ 519 int WorldEntity::writeState( const byte * data, int length, int sender ) 520 { 521 std::string modelFileName; 522 SYNCHELP_READ_BEGIN(); 523 524 SYNCHELP_READ_FKT( PNode::writeState, NWT_WE_PN_WRITESTATE ); 525 526 SYNCHELP_READ_STRING( modelFileName, NWT_WE_PN_MODELFILENAME ); 527 SYNCHELP_READ_FLOAT( scaling, NWT_WE_PN_SCALING ); 528 //check if modelFileName is relative to datadir or absolute 529 530 531 PRINTF(0)("================ LOADING MODEL %s, %f\n", modelFileName.c_str(), scaling); 532 533 if ( modelFileName != "" ) 534 { 535 loadModel( modelFileName, scaling); 536 PRINTF(0)("modelfilename: %s\n", getModel( 0 )->getName()); 537 } 538 539 /*SYNCHELP_READ_STRINGM( modelFileName ); 540 541 if ( strcmp(modelFileName, "") ) 542 if ( strstr(modelFileName, ResourceManager::getInstance()->getDataDir()) ) 543 { 544 this->md2TextureFileName = new char[strlen(modelFileName)-strlen(ResourceManager::getInstance()->getDataDir())+1]; 545 strcpy((char*)this->md2TextureFileName, modelFileName+strlen(ResourceManager::getInstance()->getDataDir())); 546 } 547 else 548 { 549 this->md2TextureFileName = modelFileName; 550 } 551 */ 552 553 return SYNCHELP_READ_N; 554 } 555 556 557 /** 558 * data copied in data will bee sent to another host 559 * @param data pointer to data 560 * @param maxLength max length of data 561 * @return the number of bytes writen 562 */ 563 int WorldEntity::readState( byte * data, int maxLength ) 564 { 565 SYNCHELP_WRITE_BEGIN(); 566 567 SYNCHELP_WRITE_FKT( PNode::readState, NWT_WE_PN_WRITESTATE ); 568 569 if ( getModel(0) && getModel(0)->getName() != "" ) 570 { 571 std::string name = getModel( 0 )->getName(); 572 573 if ( name.find( ResourceManager::getInstance()->getDataDir() ) == 0 ) 574 { 575 name.erase(ResourceManager::getInstance()->getDataDir().size()); 576 } 577 578 SYNCHELP_WRITE_STRING( name, NWT_WE_PN_MODELFILENAME ); 579 } 580 else 581 { 582 SYNCHELP_WRITE_STRING("", NWT_WE_PN_MODELFILENAME); 583 } 584 585 SYNCHELP_WRITE_FLOAT( scaling, NWT_WE_PN_SCALING ); 586 /*if ( this->md2TextureFileName!=NULL && strcmp(this->md2TextureFileName, "") ) 587 { 588 SYNCHELP_WRITE_STRING(this->md2TextureFileName); 589 } 590 else 591 { 592 SYNCHELP_WRITE_STRING(""); 593 }*/ 594 595 return SYNCHELP_WRITE_N; 596 } 519 /** 520 * handler for changes on registred vars 521 * @param id id's which changed 522 */ 523 void WorldEntity::varChangeHandler( std::list< int > & id ) 524 { 525 #warning implement this 526 } -
branches/network/src/world_entities/world_entity.h
r7370 r7444 96 96 GLGuiWidget* getHealthWidget(); 97 97 bool hasHealthWidget() const { return this->healthWidget; }; 98 99 virtual void varChangeHandler( std::list<int> & id ); 98 100 99 101 protected: … … 123 125 ObjectManager::EntityList::iterator objectListIterator; //!< The iterator position of this Entity in the given list of the ObjectManager. 124 126 125 float scaling; 127 128 //network stuff 129 130 float scaling; //!< model's scaling factor 131 int scaling_handle; //!< handle for syncing var 132 133 std::string modelFileName; //!< model's file name 134 int modelFileName_handle; //!< handle for syncing var 126 135 127 136
Note: See TracChangeset
for help on using the changeset viewer.