Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7444 in orxonox.OLD for branches/network/src/world_entities


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

Location:
branches/network/src/world_entities
Files:
24 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}
  • branches/network/src/world_entities/environments/water.h

    r7125 r7444  
    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;
  • branches/network/src/world_entities/npcs/ground_turret.cc

    r7193 r7444  
    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 }
  • branches/network/src/world_entities/npcs/ground_turret.h

    r7102 r7444  
    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];
  • branches/network/src/world_entities/playable.cc

    r7356 r7444  
    6060
    6161  this->score = 0;
    62   this->oldScore = 0;
    6362
    6463  this->bDead = false;
     64 
     65  registerVar( new SynchronizeableInt( &score, &score, "score" ) );
    6566}
    6667
     
    480481
    481482
    482 #define DATA_FLAGS    1
    483 #define DATA_SCORE    2
    484 
    485 #define FLAGS_bFire   1
    486 
    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 
    557483
    558484/**
  • branches/network/src/world_entities/playable.h

    r7351 r7444  
    7979  virtual void tick(float dt);
    8080
    81   // NETWORK
    82   int       writeSync(const byte* data, int length, int sender);
    83   int       readSync(byte* data, int maxLength );
    84   bool      needsReadSync();
    85 
    86 
    8781  // Transformations:
    8882  static Playable::Playmode stringToPlaymode(const std::string& playmode);
     
    111105  int                   oldFlags;           //!< Used for synchronisation
    112106
    113   int                   score;
    114   int                   oldScore;
     107  int                   score;              //!< players score
    115108
    116109  bool                  bDead;
  • branches/network/src/world_entities/power_ups/laser_power_up.cc

    r7193 r7444  
    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 
  • branches/network/src/world_entities/power_ups/laser_power_up.h

    r6512 r7444  
    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();
  • branches/network/src/world_entities/power_ups/param_power_up.cc

    r7221 r7444  
    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 
  • branches/network/src/world_entities/power_ups/param_power_up.h

    r7221 r7444  
    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();
  • branches/network/src/world_entities/power_ups/power_up.cc

    r7221 r7444  
    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 
  • branches/network/src/world_entities/power_ups/power_up.h

    r7221 r7444  
    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);
  • branches/network/src/world_entities/power_ups/turret_power_up.cc

    r7193 r7444  
    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 }
  • branches/network/src/world_entities/power_ups/turret_power_up.h

    r7065 r7444  
    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();
  • branches/network/src/world_entities/power_ups/weapon_power_up.cc

    r7370 r7444  
    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 }
  • branches/network/src/world_entities/power_ups/weapon_power_up.h

    r7221 r7444  
    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
  • branches/network/src/world_entities/skybox.cc

    r7328 r7444  
    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
     
    292295}
    293296
    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 }
     297void SkyBox::varChangeHandler( std::list< int > & id )
     298{
     299#warning implement this
     300}
  • branches/network/src/world_entities/skybox.h

    r7328 r7444  
    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};
  • branches/network/src/world_entities/space_ships/space_ship.cc

    r7346 r7444  
    9494  if (root != NULL)
    9595    this->loadParams(root);
    96   else
    97   {
    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     else
    106     {
    107       this->loadModel( "models/ships/fighter.obj" );
    108       this->toList(OM_GROUP_01);
    109     }
    110   }
    11196
    11297}
     
    235220  this->burstSystem->setColor(0.5, .5,.5,.8,.8);
    236221  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" ) );
    238234}
    239235
     
    307303    if ( isServer() )
    308304    {
    309       networkCollisionList.push_back( entity->getHealth() );
    310       doCollideNetwork( entity->getHealth() );
     305      //TODO handle this
    311306    }
    312307  }
     
    510505
    511506
    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  
    4646    virtual int       readBytes(byte* data, int maxLength, int * reciever);
    4747
    48     //HACK HACK HACK HACK make this private or remove it
    49     void doCollideNetwork( float energy );
    50     std::list<float>        networkCollisionList;
    51 
    5248  private:
    5349    void init();
  • branches/network/src/world_entities/terrain.cc

    r7221 r7444  
    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{
  • branches/network/src/world_entities/terrain.h

    r7221 r7444  
    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);
  • branches/network/src/world_entities/world_entity.cc

    r7230 r7444  
    6565
    6666  this->toList(OM_NULL);
     67 
     68  modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName" ) );
     69  scaling_handle = registerVarId( new SynchronizeableFloat( &scaling, &scaling, "scaling" ) );
    6770}
    6871
     
    123126  this->modelLODName = fileName;
    124127  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 
    125138  if (!fileName.empty())
    126139  {
     
    504517
    505518
    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 */
     523void WorldEntity::varChangeHandler( std::list< int > & id )
     524{
     525#warning implement this
     526}
  • branches/network/src/world_entities/world_entity.h

    r7370 r7444  
    9696  GLGuiWidget* getHealthWidget();
    9797  bool hasHealthWidget() const { return this->healthWidget; };
     98 
     99  virtual void varChangeHandler( std::list<int> & id );
    98100
    99101protected:
     
    123125  ObjectManager::EntityList::iterator objectListIterator; //!< The iterator position of this Entity in the given list of the ObjectManager.
    124126
    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
    126135
    127136
Note: See TracChangeset for help on using the changeset viewer.