Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7954 in orxonox.OLD for trunk/src/world_entities


Ignore:
Timestamp:
May 29, 2006, 3:28:41 PM (19 years ago)
Author:
patrick
Message:

trunk: merged the network branche back to trunk.

Location:
trunk/src/world_entities
Files:
25 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/environments/water.cc

    r7370 r7954  
    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 
     316  WorldEntity::varChangeHandler( id );
     317}
  • trunk/src/world_entities/environments/water.h

    r7125 r7954  
    3838   void draw() const;
    3939   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 );
    4642
    4743  private:
     
    5652    Material        waterMaterial;
    5753    Shader*         waterShader;
     54   
    5855    float           height;          //!< The hight of the Water
     56    int             height_handle;   //!< Handle to notify about changes of height
    5957
    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
    6264
    6365    float phase;
  • trunk/src/world_entities/npcs/ground_turret.cc

    r7193 r7954  
    180180  Explosion::explode(this, Vector(10,10,10));
    181181}
    182 
    183 /**
    184  * Writes data from network containing information about the state
    185  * @param data pointer to data
    186  * @param length length of data
    187  * @param sender hostID of sender
    188  */
    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 host
    203  * @param data pointer to data
    204  * @param maxLength max length of data
    205  * @return the number of bytes writen
    206  */
    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 }
  • trunk/src/world_entities/npcs/ground_turret.h

    r7102 r7954  
    3030  virtual void tick(float time);
    3131
    32   virtual int writeBytes(const byte* data, int length, int sender);
    33   virtual int readBytes(byte* data, int maxLength, int * reciever);
    34 
    3532 private:
    3633   PNode  weaponHolder[2];
  • trunk/src/world_entities/playable.cc

    r7868 r7954  
    6262
    6363  this->score = 0;
    64   this->oldScore = 0;
    6564  this->collider = NULL;
    6665
    6766  this->bDead = false;
     67
     68  registerVar( new SynchronizeableInt( &score, &score, "score" ) );
     69  registerVar( new SynchronizeableBool( &bFire, &bFire, "bFire", PERMISSION_OWNER));
    6870}
    6971
     
    484486
    485487
    486 #define DATA_FLAGS    1
    487 #define DATA_SCORE    2
    488 
    489 #define FLAGS_bFire   1
    490 
    491 int Playable::writeSync( const byte * data, int length, int sender )
    492 {
    493   SYNCHELP_READ_BEGIN();
    494 
    495   byte b;
    496   SYNCHELP_READ_BYTE( b, NWT_PL_B );
    497 
    498   byte flags;
    499 
    500   if ( b == DATA_FLAGS )
    501   {
    502     SYNCHELP_READ_BYTE( flags, NWT_PL_FLAGS );
    503 
    504     bFire = (flags & FLAGS_bFire) != 0;
    505 
    506     return SYNCHELP_READ_N;
    507   }
    508 
    509   if ( b == DATA_SCORE )
    510   {
    511     int newScore;
    512     SYNCHELP_READ_BYTE( newScore, NWT_PL_SCORE );
    513     setScore( newScore );
    514 
    515     return SYNCHELP_READ_N;
    516   }
    517 
    518   return SYNCHELP_READ_N;
    519 }
    520 
    521 int Playable::readSync( byte * data, int maxLength )
    522 {
    523   SYNCHELP_WRITE_BEGIN();
    524 
    525   if ( score != oldScore && isServer() )
    526   {
    527     SYNCHELP_WRITE_BYTE( DATA_SCORE, NWT_PL_B);
    528     SYNCHELP_WRITE_INT( score, NWT_PL_SCORE );
    529     oldScore = score;
    530 
    531     return SYNCHELP_WRITE_N;
    532   }
    533 
    534   byte flags = 0;
    535 
    536   if ( bFire )
    537     flags |= FLAGS_bFire;
    538 
    539 
    540   SYNCHELP_WRITE_BYTE( DATA_FLAGS, NWT_PL_B);
    541   SYNCHELP_WRITE_BYTE( flags, NWT_PL_FLAGS );
    542   oldFlags = flags;
    543 
    544 
    545   return SYNCHELP_WRITE_N;
    546 }
    547 
    548 bool Playable::needsReadSync( )
    549 {
    550   if ( score != oldScore && isServer() )
    551     return true;
    552 
    553   byte flags = 0;
    554 
    555   if ( bFire )
    556     flags |= FLAGS_bFire;
    557 
    558   return flags!=oldFlags;
    559 }
    560 
    561488
    562489/**
  • trunk/src/world_entities/playable.h

    r7412 r7954  
    8181  virtual void tick(float dt);
    8282
    83   // NETWORK
    84   int       writeSync(const byte* data, int length, int sender);
    85   int       readSync(byte* data, int maxLength );
    86   bool      needsReadSync();
    87 
    88 
    8983  // Transformations:
    9084  static Playable::Playmode stringToPlaymode(const std::string& playmode);
     
    115109  int                   oldFlags;           //!< Used for synchronisation
    116110
    117   int                   score;
    118   int                   oldScore;
     111  int                   score;              //!< players score
    119112
    120113  bool                  bDead;
  • trunk/src/world_entities/power_ups/laser_power_up.cc

    r7193 r7954  
    120120}
    121121
    122 int LaserPowerUp::writeBytes( const byte * data, int length, int sender )
    123 {
    124   setRequestedSync( false );
    125   setIsOutOfSync( false );
    126122
    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 
  • trunk/src/world_entities/power_ups/laser_power_up.h

    r6512 r7954  
    2626  virtual void draw() const;
    2727
    28   virtual int writeBytes(const byte* data, int length, int sender);
    29   virtual int readBytes(byte* data, int maxLength, int * reciever );
    30 
    3128  private:
    3229   void init();
  • trunk/src/world_entities/power_ups/param_power_up.cc

    r7221 r7954  
    4343  if( root != NULL)
    4444    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" ) );
    4550}
    4651
     
    119124}
    120125
    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 
  • trunk/src/world_entities/power_ups/param_power_up.h

    r7221 r7954  
    3232  float getValue();
    3333
    34   virtual int writeBytes(const byte* data, int length, int sender);
    35   virtual int readBytes(byte* data, int maxLength, int * reciever );
    36 
    3734protected:
    3835  virtual void respawn();
  • trunk/src/world_entities/power_ups/power_up.cc

    r7460 r7954  
    201201
    202202
    203 /********************************************************************************************
    204  NETWORK STUFF
    205  ********************************************************************************************/
    206 
    207 
    208 /**
    209  * data copied in data will bee sent to another host
    210  * @param data pointer to data
    211  * @param maxLength max length of data
    212  * @return the number of bytes writen
    213  */
    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 state
    224  * @param data pointer to data
    225  * @param length length of data
    226  * @param sender hostID of sender
    227  */
    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 
  • trunk/src/world_entities/power_ups/power_up.h

    r7460 r7954  
    3434  void setRespawnTime(const float respawn);
    3535
    36   int       writeState(const byte* data, int length, int sender);
    37   int       readState(byte* data, int maxLength );
    38 
    3936protected:
    4037  PowerUp(float r, float g, float b);
  • trunk/src/world_entities/power_ups/turret_power_up.cc

    r7193 r7954  
    115115  glPopMatrix();
    116116}
    117 
    118 
    119 
    120 
    121 /********************************************************************************************
    122  NETWORK STUFF
    123  ********************************************************************************************/
    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 }
  • trunk/src/world_entities/power_ups/turret_power_up.h

    r7065 r7954  
    2424  virtual void draw() const;
    2525
    26   virtual int writeBytes(const byte* data, int length, int sender);
    27   virtual int readBytes(byte* data, int maxLength, int * reciever );
    28 
    2926  private:
    3027   void init();
  • trunk/src/world_entities/power_ups/weapon_power_up.cc

    r7370 r7954  
    103103}
    104104
    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 }
  • trunk/src/world_entities/power_ups/weapon_power_up.h

    r7221 r7954  
    2424  void setWeaponClass(const std::string& name);
    2525
    26   virtual int writeBytes(const byte* data, int length, int sender);
    27   virtual int readBytes(byte* data, int maxLength, int * reciever );
    28 
    2926  bool process(WeaponManager* manager);
    3027
  • trunk/src/world_entities/skybox.cc

    r7919 r7954  
    9595{
    9696  this->rebuild();
     97 
     98  textureName_handle = registerVarId( new SynchronizeableString( &textureName, &textureName, "textureName") );
     99  size_handle = registerVarId( new SynchronizeableFloat( &size, &size, "size" ) );
    97100}
    98101
     
    290293}
    291294
    292 int SkyBox::writeBytes( const byte * data, int length, int sender )
    293 {
    294   setRequestedSync( false );
    295   setIsOutOfSync( false );
    296 
    297   SYNCHELP_READ_BEGIN();
    298 
    299   SYNCHELP_READ_FKT( WorldEntity::writeState, NWT_SB_WE_STATE );
    300 
    301   SYNCHELP_READ_FLOAT( size, NWT_SB_SIZE );
    302   if ( !this->textureName.empty() )
     295void SkyBox::varChangeHandler( std::list< int > & id )
     296{
     297  bool somethinChanged = false;
     298 
     299  if ( std::find( id.begin(), id.end(), textureName_handle ) != id.end() )
    303300  {
    304     textureName = "";
     301    somethinChanged = true;
     302    setTexture( textureName );
    305303  }
    306   std::string texName;
    307   SYNCHELP_READ_STRING( texName, NWT_SB_TEXTURENAME );
    308 
    309   this->setSize( size );
    310   this->setTextureAndType( texName, "jpg" );
    311   this->rebuild();
    312 
    313   return SYNCHELP_READ_N;
    314 }
    315 
    316 
    317 
    318 int SkyBox::readBytes( byte * data, int maxLength, int * reciever )
    319 {
    320   if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
     304 
     305  if ( std::find( id.begin(), id.end(), size_handle ) != id.end() )
    321306  {
    322     (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
    323     setRequestedSync( true );
     307    somethinChanged = true;
    324308  }
    325 
    326   int rec = this->getRequestSync();
    327   if ( rec > 0 )
    328   {
    329     *reciever = rec;
    330 
    331     SYNCHELP_WRITE_BEGIN();
    332 
    333     SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_SB_WE_STATE );
    334 
    335     SYNCHELP_WRITE_FLOAT(this->size, NWT_SB_SIZE);
    336     SYNCHELP_WRITE_STRING(this->textureName, NWT_SB_TEXTURENAME);
    337 
    338     return SYNCHELP_WRITE_N;
    339   }
    340 
    341   *reciever = 0;
    342   return 0;
    343 }
    344 
    345 void SkyBox::writeDebug( ) const
    346 {
    347 }
    348 
    349 void SkyBox::readDebug( ) const
    350 {
    351 }
     309 
     310  rebuild();
     311 
     312  WorldEntity::varChangeHandler( id );
     313}
  • trunk/src/world_entities/skybox.h

    r7328 r7954  
    5858  static void disableCubeMap();
    5959
    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 );
    6461
    6562 private:
     
    7269  float           textureSize;     //!< this is the length of a texture (assumes a square texture)
    7370  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
    7474
    7575};
  • trunk/src/world_entities/space_ships/hover.cc

    r7868 r7954  
    175175  this->getWeaponManager().getFixedTarget()->setParent(&this->cameraNode);
    176176  this->getWeaponManager().getFixedTarget()->setRelCoor(1000,0,0);
     177 
     178  // NETWORK THINGS
     179 
     180  registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) );
     181  registerVar( new SynchronizeableBool( &bBackward, &bBackward, "bBackward", PERMISSION_OWNER ) );
     182  registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) );
     183  registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) );
     184  registerVar( new SynchronizeableBool( &bAscend, &bAscend, "bAscend", PERMISSION_OWNER ) );
     185  registerVar( new SynchronizeableBool( &bDescend, &bDescend, "bDescend", PERMISSION_OWNER ) );
     186 
     187  registerVar( new SynchronizeableFloat( &rotation, &rotation, "rotation", PERMISSION_OWNER ) );
    177188}
    178189
  • trunk/src/world_entities/space_ships/space_ship.cc

    r7868 r7954  
    9393  if (root != NULL)
    9494    this->loadParams(root);
    95   else
    96   {
    97     //this->loadModel("models/ships/reap_#.obj");
    98     //TODO HACK this is only for network multiplayer games.
    99     if( this->getOwner()%2 == 0)
    100     {
    101       this->loadModel("models/ships/reap_#.obj");
    102       this->toList(OM_GROUP_00);
    103     }
    104     else
    105     {
    106       this->loadModel( "models/ships/fighter.obj" );
    107       this->toList(OM_GROUP_01);
    108     }
    109   }
    11095
    11196}
     
    234219  this->burstSystem->setColor(0.5, .5,.5,.8,.8);
    235220  this->burstSystem->setColor(1.0, .8,.8,.8,.0);
    236 
     221 
     222  registerVar( new SynchronizeableVector( &velocity, &velocity, "velocity" ) );
     223  registerVar( new SynchronizeableQuaternion( &mouseDir, &mouseDir, "mousedir", PERMISSION_OWNER ) );
     224
     225  registerVar( new SynchronizeableBool( &bUp, &bUp, "bUp", PERMISSION_OWNER ) );
     226  registerVar( new SynchronizeableBool( &bDown, &bDown, "bDown", PERMISSION_OWNER ) );
     227  registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) );
     228  registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) );
     229  registerVar( new SynchronizeableBool( &bAscend, &bAscend, "bAscend", PERMISSION_OWNER ) );
     230  registerVar( new SynchronizeableBool( &bDescend, &bDescend, "bDescend", PERMISSION_OWNER ) );
     231  registerVar( new SynchronizeableBool( &bRollL, &bRollL, "bRollL", PERMISSION_OWNER ) );
     232  registerVar( new SynchronizeableBool( &bRollR, &bRollR, "bRollR", PERMISSION_OWNER ) );
    237233}
    238234
     
    306302    if ( isServer() )
    307303    {
    308       networkCollisionList.push_back( entity->getHealth() );
    309       doCollideNetwork( entity->getHealth() );
     304      //TODO handle this
    310305    }
    311306  }
     
    349344
    350345  // spaceship controlled movement
    351   if (this->getOwner() == this->getHostID())
     346  //if (this->getOwner() == this->getHostID())
    352347    this->calculateVelocity(time);
    353348
     
    509504
    510505
    511 #define MASK_bUp         1
    512 #define MASK_bDown       2
    513 #define MASK_bLeft       4
    514 #define MASK_bRight      8
    515 #define MASK_bAscend    16
    516 #define MASK_bDescend   32
    517 #define MASK_bRollL     64
    518 #define MASK_bRollR    128
    519 
    520 #define DATA_state       1
    521 #define DATA_flags       2
    522 #define DATA_mouse       3
    523 #define DATA_sync        4
    524 #define DATA_velocity    5
    525 #define DATA_playables   6
    526 #define DATA_collision   7
    527 
    528 int SpaceShip::writeBytes( const byte * data, int length, int sender )
    529 {
    530   SYNCHELP_READ_BEGIN();
    531 
    532   byte b;
    533 
    534   while ( SYNCHELP_READ_REMAINING()>0 )
    535   {
    536     SYNCHELP_READ_BYTE( b, NWT_SS_B );
    537 
    538     if ( b == DATA_state )
    539     {
    540       setRequestedSync( false );
    541       setIsOutOfSync( false );
    542       SYNCHELP_READ_FKT( WorldEntity::writeState, NWT_SS_WE_STATE );
    543 
    544       continue;
    545     }
    546 
    547     if ( b == DATA_flags )
    548     {
    549       if ( this->getOwner() != this->getHostID() )
    550       {
    551         byte flags = 0;
    552         SYNCHELP_READ_BYTE( flags, NWT_SS_FLAGS );
    553 
    554         bUp = (flags & MASK_bUp) != 0;
    555         bDown = (flags & MASK_bDown) != 0;
    556         bLeft = (flags & MASK_bLeft) != 0;
    557         bRight = (flags & MASK_bRight) != 0;
    558         bAscend = (flags & MASK_bAscend) != 0;
    559         bDescend = (flags & MASK_bDescend) != 0;
    560         bRollL = (flags & MASK_bRollL) != 0;
    561         bRollR = (flags & MASK_bRollR) != 0;
    562 
    563       }
    564       else
    565         assert(false);
    566 
    567       continue;
    568     }
    569 
    570     if ( b == DATA_mouse )
    571     {
    572       if ( this->getOwner() != this->getHostID() )
    573       {
    574         SYNCHELP_READ_FLOAT( mouseDir.w, NWT_SS_MOUSEDIRW );
    575         SYNCHELP_READ_FLOAT( mouseDir.v.x, NWT_SS_MOUSEDIRX );
    576         SYNCHELP_READ_FLOAT( mouseDir.v.y, NWT_SS_MOUSEDIRY );
    577         SYNCHELP_READ_FLOAT( mouseDir.v.z, NWT_SS_MOUSEDIRZ );
    578       }
    579       else
    580         assert(false);
    581 
    582       continue;
    583     }
    584 
    585     if ( b == DATA_sync )
    586     {
    587       if ( this->getOwner() != this->getHostID() )
    588       {
    589         SYNCHELP_READ_FKT( PNode::writeSync, NWT_SS_PN_SYNC );
    590       }
    591       else
    592         assert(false);
    593 
    594       continue;
    595     }
    596 
    597     if ( b == DATA_velocity )
    598     {
    599       if ( this->getOwner() != this->getHostID() )
    600       {
    601         SYNCHELP_READ_FLOAT( velocity.x, NWT_SS_VELX );
    602         SYNCHELP_READ_FLOAT( velocity.y, NWT_SS_VELY );
    603         SYNCHELP_READ_FLOAT( velocity.z, NWT_SS_VELZ );
    604       }
    605       else
    606         assert(false);
    607 
    608       continue;
    609     }
    610 
    611     if ( b == DATA_playables )
    612     {
    613       if ( this->getOwner() != this->getHostID() )
    614       {
    615         SYNCHELP_READ_FKT( Playable::writeSync, NWT_SS_PL_SYNC );
    616       }
    617       else
    618         assert(false);
    619     }
    620 
    621     if ( b == DATA_collision )
    622     {
    623       int n;
    624       float energy;
    625       SYNCHELP_READ_INT( n, NWT_SS_CO_N );
    626 
    627       for ( int i = 0; i<n; i++ )
    628       {
    629         SYNCHELP_READ_FLOAT( energy, NWT_SS_CO_CLID );
    630         doCollideNetwork( energy );
    631       }
    632     }
    633   }
    634 
    635   return SYNCHELP_READ_N;
    636 }
    637 
    638 
    639 
    640 int SpaceShip::readBytes( byte * data, int maxLength, int * reciever )
    641 {
    642   SYNCHELP_WRITE_BEGIN();
    643 
    644   if ( isOutOfSync() && !requestedSync() /*&& this->getHostID()!=this->getOwner()*/ )
    645   {
    646     (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
    647     setRequestedSync( true );
    648     PRINTF(0)("REQUESTED STATE %d\n", this->getUniqueID());
    649   }
    650 
    651   int rec = this->getRequestSync();
    652   if ( rec > 0 )
    653   {
    654     *reciever = rec;
    655 
    656     PRINTF(0)("SEND STATE %d %d\n", this->getUniqueID(), rec);
    657 
    658     SYNCHELP_WRITE_BYTE( (byte)DATA_state, NWT_SS_B );
    659 
    660     SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_SS_WE_STATE );
    661 
    662     return SYNCHELP_WRITE_N;
    663   }
    664 
    665   *reciever = 0 - this->getOwner();
    666   //TODO: implement with SYNCHELP_WRITE_SENT()
    667   bool sentSomething = false;
    668 
    669   if ( PNode::needsReadSync() && ( this->getHostID()==0 || this->getOwner() == this->getHostID() ) )
    670   {
    671     PRINTF(0)("sending PNode::readSync\n");
    672     SYNCHELP_WRITE_BYTE( DATA_sync, NWT_SS_B );
    673     SYNCHELP_WRITE_FKT( PNode::readSync, NWT_SS_PN_SYNC );
    674     sentSomething = true;
    675   }
    676 
    677   if ( this->getHostID()==0 || this->getHostID()==this->getOwner() )
    678   {
    679     byte mask = 0;
    680 
    681     if ( bUp )
    682       mask |= MASK_bUp;
    683     if ( bDown )
    684       mask |= MASK_bDown;
    685     if ( bLeft )
    686       mask |= MASK_bLeft;
    687     if ( bRight )
    688       mask |= MASK_bRight;
    689     if ( bAscend )
    690       mask |= MASK_bAscend;
    691     if ( bRollL )
    692       mask |= MASK_bRollL;
    693     if ( bRollR )
    694       mask |= MASK_bRollR;
    695 
    696 
    697     if ( mask != oldMask )
    698     {
    699       oldMask = mask;
    700       PRINTF(0)("sending mask\n");
    701       sentSomething = true;
    702       SYNCHELP_WRITE_BYTE( DATA_flags, NWT_SS_B );
    703       SYNCHELP_WRITE_BYTE( mask, NWT_SS_FLAGS );
    704     }
    705 #define __OFFSET_MDIR_W 0.01
    706 #define __OFFSET_MDIR_V 0.01
    707     if ( fabs( oldMouseDir.w - mouseDir.w ) > __OFFSET_MDIR_W ||
    708          fabs( oldMouseDir.v.x - mouseDir.v.x ) > __OFFSET_MDIR_V ||
    709          fabs( oldMouseDir.v.y - mouseDir.v.y ) > __OFFSET_MDIR_V ||
    710          fabs( oldMouseDir.v.z - mouseDir.v.z ) > __OFFSET_MDIR_V )
    711     {
    712       oldMouseDir = mouseDir;
    713 
    714       SYNCHELP_WRITE_BYTE( DATA_mouse, NWT_SS_B );
    715       PRINTF(0)("SENDING mousedir\n");
    716       sentSomething = true;
    717       SYNCHELP_WRITE_FLOAT( mouseDir.w, NWT_SS_MOUSEDIRW );
    718       SYNCHELP_WRITE_FLOAT( mouseDir.v.x, NWT_SS_MOUSEDIRX );
    719       SYNCHELP_WRITE_FLOAT( mouseDir.v.y, NWT_SS_MOUSEDIRY );
    720       SYNCHELP_WRITE_FLOAT( mouseDir.v.z, NWT_SS_MOUSEDIRZ );
    721     }
    722 #define __OFFSET_VEL 0.05
    723     if ( fabs( oldVelocity.x - velocity.x ) > __OFFSET_VEL*fabs(oldVelocity.x)+0.1 ||
    724          fabs( oldVelocity.y - velocity.y ) > __OFFSET_VEL*fabs(oldVelocity.y)+0.1 ||
    725          fabs( oldVelocity.z - velocity.z ) > __OFFSET_VEL*fabs(oldVelocity.z)+0.1 )
    726     {
    727       oldVelocity.x = velocity.x;
    728       oldVelocity.y = velocity.y;
    729       oldVelocity.z = velocity.z;
    730       PRINTF(0)("SENDING velocity\n");
    731       sentSomething = true;
    732       SYNCHELP_WRITE_BYTE( DATA_velocity, NWT_SS_B );
    733       SYNCHELP_WRITE_FLOAT( velocity.x, NWT_SS_VELX );
    734       SYNCHELP_WRITE_FLOAT( velocity.y, NWT_SS_VELY );
    735       SYNCHELP_WRITE_FLOAT( velocity.z, NWT_SS_VELZ );
    736     }
    737 
    738     while ( Playable::needsReadSync() )
    739     {
    740       sentSomething = true;
    741       PRINTF(0)("SYNCHELP_WRITE_FKT( Playable::readSync, NWT_SS_PL_SYNC )\n");
    742       SYNCHELP_WRITE_BYTE( DATA_playables, NWT_SS_B );
    743       SYNCHELP_WRITE_FKT( Playable::readSync, NWT_SS_PL_SYNC );
    744     }
    745 
    746   }
    747 
    748   if ( !sentSomething )
    749   {
    750     *reciever = 0;
    751 
    752     if ( networkCollisionList.size()>0 )
    753     {
    754       SYNCHELP_WRITE_BYTE( DATA_collision, NWT_SS_B );
    755 
    756       SYNCHELP_WRITE_INT( networkCollisionList.size(), NWT_SS_CO_N );
    757 
    758       for ( std::list<float>::iterator it = networkCollisionList.begin(); it!=networkCollisionList.end(); it++ )
    759       {
    760         SYNCHELP_WRITE_FLOAT( *it, NWT_SS_CO_CLID );
    761       }
    762 
    763       networkCollisionList.clear();
    764     }
    765   }
    766 
    767   return SYNCHELP_WRITE_N;
    768 }
    769 
    770 
    771 void SpaceShip::doCollideNetwork( float energy )
    772 {
    773   this->decreaseHealth( energy );
    774   if( this->getHealth() <= 0)
    775   {
    776     this->die();
    777   }
    778 }
    779 
    780 
    781 
     506
     507
  • trunk/src/world_entities/space_ships/space_ship.h

    r7346 r7954  
    4343    virtual void process(const Event &event);
    4444
    45     virtual int       writeBytes(const byte* data, int length, int sender);
    46     virtual int       readBytes(byte* data, int maxLength, int * reciever);
    47 
    48     //HACK HACK HACK HACK make this private or remove it
    49     void doCollideNetwork( float energy );
    50     std::list<float>        networkCollisionList;
    51 
    5245  private:
    5346    void init();
  • trunk/src/world_entities/terrain.cc

    r7221 r7954  
    423423}
    424424
    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( ) const
    460   {}
    461 
    462 void Terrain::readDebug( ) const
    463   {}
    464 
    465425float Terrain::getHeight(float x, float y)
    466426{
  • trunk/src/world_entities/terrain.h

    r7221 r7954  
    3333  virtual ~Terrain();
    3434
    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 
    4035  void init();
    4136  virtual void loadParams(const TiXmlElement* root);
  • trunk/src/world_entities/world_entity.cc

    r7927 r7954  
    7070  this->toList(OM_NULL);
    7171
    72   //this->collisionHandles = new *CollisionHandle[CREngine::CR_NUMBER]();
     72  modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName" ) );
     73  scaling_handle = registerVarId( new SynchronizeableFloat( &scaling, &scaling, "scaling" ) );
    7374}
    7475
     
    132133  this->modelLODName = fileName;
    133134  this->scaling = scaling;
     135
     136  std::string name = fileName;
     137
     138  if (  name.find( ResourceManager::getInstance()->getDataDir() ) == 0 )
     139  {
     140    name.erase(ResourceManager::getInstance()->getDataDir().size());
     141  }
     142
     143  this->modelFileName = name;
     144
    134145  if (!fileName.empty())
    135146  {
     
    524535
    525536
    526 
    527 
    528 /********************************************************************************************
    529  NETWORK STUFF
    530  ********************************************************************************************/
    531 
    532 
    533 /**
    534  * Writes data from network containing information about the state
    535  * @param data pointer to data
    536  * @param length length of data
    537  * @param sender hostID of sender
    538  */
    539 int WorldEntity::writeState( const byte * data, int length, int sender )
    540 {
    541   std::string modelFileName;
    542   SYNCHELP_READ_BEGIN();
    543 
    544   SYNCHELP_READ_FKT( PNode::writeState, NWT_WE_PN_WRITESTATE );
    545 
    546   SYNCHELP_READ_STRING( modelFileName, NWT_WE_PN_MODELFILENAME );
    547   SYNCHELP_READ_FLOAT( scaling, NWT_WE_PN_SCALING );
    548   //check if modelFileName is relative to datadir or absolute
    549 
    550 
    551   PRINTF(0)("================ LOADING MODEL %s, %f\n", modelFileName.c_str(), scaling);
    552 
    553   if ( modelFileName != "" )
    554   {
    555     loadModel( modelFileName, scaling);
    556     PRINTF(0)("modelfilename: %s\n", getModel( 0 )->getName());
    557   }
    558 
    559   /*SYNCHELP_READ_STRINGM( modelFileName );
    560 
    561   if ( strcmp(modelFileName, "") )
    562     if ( strstr(modelFileName, ResourceManager::getInstance()->getDataDir()) )
    563     {
    564       this->md2TextureFileName = new char[strlen(modelFileName)-strlen(ResourceManager::getInstance()->getDataDir())+1];
    565       strcpy((char*)this->md2TextureFileName, modelFileName+strlen(ResourceManager::getInstance()->getDataDir()));
    566     }
    567     else
    568     {
    569       this->md2TextureFileName = modelFileName;
    570     }
    571   */
    572 
    573   return SYNCHELP_READ_N;
    574 }
    575 
    576 
    577 /**
    578  * data copied in data will bee sent to another host
    579  * @param data pointer to data
    580  * @param maxLength max length of data
    581  * @return the number of bytes writen
    582  */
    583 int WorldEntity::readState( byte * data, int maxLength )
    584 {
    585   SYNCHELP_WRITE_BEGIN();
    586 
    587   SYNCHELP_WRITE_FKT( PNode::readState, NWT_WE_PN_WRITESTATE );
    588 
    589   if ( getModel(0) && getModel(0)->getName() != "" )
    590   {
    591     std::string name = getModel( 0 )->getName();
    592 
    593     if (  name.find( ResourceManager::getInstance()->getDataDir() ) == 0 )
    594     {
    595       name.erase(ResourceManager::getInstance()->getDataDir().size());
    596     }
    597 
    598     SYNCHELP_WRITE_STRING( name, NWT_WE_PN_MODELFILENAME );
    599   }
    600   else
    601   {
    602     SYNCHELP_WRITE_STRING("", NWT_WE_PN_MODELFILENAME);
    603   }
    604 
    605   SYNCHELP_WRITE_FLOAT( scaling, NWT_WE_PN_SCALING );
    606   /*if ( this->md2TextureFileName!=NULL && strcmp(this->md2TextureFileName, "") )
    607   {
    608     SYNCHELP_WRITE_STRING(this->md2TextureFileName);
    609   }
    610   else
    611   {
    612     SYNCHELP_WRITE_STRING("");
    613   }*/
    614 
    615   return SYNCHELP_WRITE_N;
    616 }
     537/**
     538 * handler for changes on registred vars
     539 * @param id id's which changed
     540 */
     541void WorldEntity::varChangeHandler( std::list< int > & id )
     542{
     543  if ( std::find( id.begin(), id.end(), modelFileName_handle ) != id.end() ||
     544       std::find( id.begin(), id.end(), scaling_handle ) != id.end()
     545     )
     546  {
     547    loadModel( modelFileName, scaling );
     548  }
     549
     550  PNode::varChangeHandler( id );
     551}
     552
  • trunk/src/world_entities/world_entity.h

    r7927 r7954  
    9999  OrxGui::GLGuiWidget* getHealthWidget();
    100100  bool hasHealthWidget() const { return this->healthWidget; };
     101 
     102  virtual void varChangeHandler( std::list<int> & id );
    101103
    102104  /* --- Misc Stuff Block --- */
     
    133135  ObjectManager::EntityList::iterator objectListIterator; //!< The iterator position of this Entity in the given list of the ObjectManager.
    134136
    135   float                   scaling;
     137 
     138  //network stuff
     139 
     140  float       scaling;                         //!< model's scaling factor
     141  int         scaling_handle;                  //!< handle for syncing var
     142 
     143  std::string modelFileName;                  //!< model's file name
     144  int         modelFileName_handle;           //!< handle for syncing var
    136145  CollisionHandle**       collisionHandles;
    137146
Note: See TracChangeset for help on using the changeset viewer.