Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6419 in orxonox.OLD


Ignore:
Timestamp:
Jan 6, 2006, 6:19:30 PM (18 years ago)
Author:
rennerc
Message:

some more entities should sync now

Location:
branches/network/src
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/lib/network/network_game_manager.cc

    r6414 r6419  
    2323#include "network_stream.h"
    2424#include "converter.h"
     25
    2526#include "p_node.h"
     27
    2628
    2729/* include your own header */
     
    392394  //PRINTF(0)("SendEntityList: n = %d\n", networkStream->getSyncCount()-2 );
    393395
     396  int n = 0;
     397
    394398  while ( it != e )
    395399  {
     
    404408    if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getOwner()) ) )
    405409      return;
     410
     411
     412    PRINTF(0)("id = %x %s %s\n", (int)((*it)->getLeafClassID()), (*it)->getClassName(), (*it)->getName());
     413
     414
     415    /*if ( (*it)->isA(CL_WORLD_ENTITY) )
     416    {
     417      n = dynamic_cast<WorldEntity*>((*it))->readState( outBuffer[userID].buffer, outBuffer[userID].maxLength-outBuffer[userID].length );
     418      if ( n = 0 )
     419      {
     420        PRINTF(2)("n = 0\n");
     421      }
     422      outBuffer[userID].length += n;
     423  }*/
    406424
    407425    it++;
     
    437455 * @param owner: owner of this synchronizealbe
    438456 */
    439 void NetworkGameManager::doCreateEntity( ClassID classID, int uniqueID, int owner )
     457BaseObject* NetworkGameManager::doCreateEntity( ClassID classID, int uniqueID, int owner )
    440458{
    441459  BaseObject * b = Factory::fabricate( classID );
     
    444462  {
    445463    PRINTF(1)("Could not fabricate Object with classID %x\n", classID);
    446     return;
     464    return NULL;
    447465  }
    448466
     
    456474      s->setIsOutOfSync( true );
    457475    PRINTF(0)("Fabricated %s with id %d\n", s->getClassName(), s->getUniqueID());
     476    return b;
    458477  }
    459478  else
     
    462481    delete b;
    463482  }
     483  return NULL;
    464484}
    465485
     
    696716    i += Converter::byteArrayToInt( &data[i], &owner );
    697717
     718    PRINTF(0)("before fabricate\n");
    698719    if ( classID != CL_NETWORK_GAME_MANAGER && classID != CL_HANDSHAKE )
    699       doCreateEntity( (ClassID)classID, uniqueID, owner );
    700 
    701   }
     720    {
     721      BaseObject* b = doCreateEntity( (ClassID)classID, uniqueID, owner );
     722
     723      /*if ( b != NULL )
     724      {
     725        if ( b->isA(CL_WORLD_ENTITY) )
     726        {
     727          int n = dynamic_cast<WorldEntity*>(b)->writeState( data, length, sender );
     728
     729          i += n;
     730        }
     731    }*/
     732    }
     733
     734  }
     735
    702736  PNode::getNullParent()->debugNode( 0 );
     737
    703738  return true;
    704739}
  • branches/network/src/lib/network/network_game_manager.h

    r6412 r6419  
    9494    void executeRequestSync( int uniqueID, int user );
    9595
    96     void doCreateEntity(ClassID classID, int uniqueID, int owner);
     96    BaseObject* doCreateEntity(ClassID classID, int uniqueID, int owner);
    9797    void doRemoveEntity(int uniqueID);
    9898    void doRequestSync(int uniqueID, int userID);
  • branches/network/src/subprojects/network/network_unit_test.cc

    r6341 r6419  
    136136
    137137  /* create a server stream */
    138   nm->createServer(*serverSync, port);
     138  nm->createServer(port);
    139139
    140140  /* esatblish a connection */
     
    289289  printf("%f = ", f);
    290290  printf(s); printf("\n");
    291  
     291
    292292  byte* res = Converter::floatToByteArray(f);
    293293  printf("Byte Array: ");
     
    295295    printf("%i  ", res[i]);
    296296  printf("\n");
    297  
     297
    298298  float b = Converter::byteArrayToFloat(res);
    299299  printf("ReConvert: %f \n", b);
     
    305305  printf("### %f = ", f);
    306306  printf(s); printf("\n");
    307  
     307
    308308  byte* res = Converter::_floatToByteArray(f);
    309309  printf("Byte Array: ");
     
    311311    printf("%i  ", res[i]);
    312312  printf("\n");
    313  
     313
    314314  float b = Converter::_byteArrayToFloat(res);
    315315  printf("ReConvert: %f \n", b);
     
    324324    printf("%i  ", res[i]);
    325325  printf("\n");
    326  
     326
    327327  int z = Converter::byteArrayToInt(res);
    328  
     328
    329329  printf("ReConvert: %i\n", z);
    330330
    331  
     331
    332332  //float a = 5.4f;
    333333  //float b = 2.0f;
    334334  //printf("%f mod %f = %f", a, b, a % b);
    335  
    336   printf("\n");
    337  
     335
     336  printf("\n");
     337
    338338  */
    339339  /*
    340340  float y;
    341341  char* s;
    342  
     342
    343343  y = 12.0f;
    344344  s = Converter::floatToBinString(y);
    345345  printf("%f = ", y);
    346346  printf(s); printf("\n");
    347  
     347
    348348  y = 24549026.0f;
    349349  s = Converter::floatToBinString(y);
    350350  printf("%f = ", y);
    351351  printf(s); printf("\n");
    352  
     352
    353353  y = 12.4e20f;
    354354  s = Converter::floatToBinString(y);
    355355  printf("%f = ", y);
    356356  printf(s); printf("\n");
    357  
     357
    358358  y = 4.7824f;
    359359  s = Converter::floatToBinString(y);
    360360  printf("%f = ", y);
    361361  printf(s); printf("\n");
    362  
     362
    363363  y = -4.7824f;
    364364  s = Converter::floatToBinString(y);
    365365  printf("%f = ", y);
    366366  printf(s); printf("\n");
    367  
     367
    368368  y = -14.35e14f;
    369369  s = Converter::floatToBinString(y);
     
    371371  printf(s); printf("\n");
    372372                                                            */
    373  
    374  
     373
     374
    375375  /*
    376376  float a = 12.3f;
    377  
     377
    378378  char* s = Converter::floatToBinString(a);
    379379  printf("%f = ", a);
    380380  printf(s); printf("\n");
    381  
     381
    382382  byte* res = Converter::floatToByteArray(a);
    383383  printf("Byte Array: \n");
     
    385385    printf("%i  ", res[i]);
    386386  printf("\n");
    387  
     387
    388388  float b = Converter::byteArrayToFloat(res);
    389389  printf("ReConvert: %f \n", b);
     
    392392//  testFloatConverter(134.26455646546548741661675165f); printf("\n");
    393393 // testFloatConverter(35.67e14f); printf("\n");
    394  
     394
    395395  testFloatConverter(12.3e-7f); printf("\n");
    396396  testFloatConverter(134.26455646546548741661675165f); printf("\n");
    397397  testFloatConverter(35.67e14f); printf("\n");
    398  
     398
    399399  return 0;
    400400}
  • branches/network/src/world_entities/power_ups/laser_power_up.cc

    r6222 r6419  
    1919#include "factory.h"
    2020#include "state.h"
     21#include "network_game_manager.h"
    2122
    2223#include "primitive_model.h"
     
    118119}
    119120
     121int LaserPowerUp::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 );
     129
     130  return SYNCHELP_READ_N;
     131}
     132
     133
     134
     135int LaserPowerUp::readBytes( byte * data, int maxLength, int * reciever )
     136{
     137  if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
     138  {
     139    (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
     140    setRequestedSync( true );
     141  }
     142
     143  int rec = this->getRequestSync();
     144  if ( rec > 0 )
     145  {
     146    *reciever = rec;
     147
     148    SYNCHELP_WRITE_BEGIN();
     149
     150    SYNCHELP_WRITE_FKT( PowerUp::readState );
     151
     152    return SYNCHELP_WRITE_N;
     153  }
     154
     155  *reciever = 0;
     156  return 0;
     157}
     158
  • branches/network/src/world_entities/power_ups/laser_power_up.h

    r5511 r6419  
    2323  virtual void draw() const;
    2424
     25  virtual int writeBytes(const byte* data, int length, int sender);
     26  virtual int readBytes(byte* data, int maxLength, int * reciever );
     27
    2528  private:
    2629   void init();
  • branches/network/src/world_entities/power_ups/param_power_up.cc

    r6414 r6419  
    6464  static_cast<PowerUp*>(this)->loadParams(root);
    6565  LoadParam(root, "type", this, ParamPowerUp, setType);
    66   if(root!=NULL && root->FirstChildElement("value") != NULL) {
     66
     67  if( root != NULL && root->FirstChildElement("value") != NULL) {
     68
    6769    LoadParam(root, "value", this, ParamPowerUp, setValue);
    6870  }
  • branches/network/src/world_entities/power_ups/power_up.cc

    r6413 r6419  
    5454void PowerUp::collidesWith (WorldEntity* entity, const Vector& location)
    5555{
    56  if(entity->isA(CL_EXTENDABLE))
     56  if(entity->isA(CL_EXTENDABLE))
    5757  {
    5858    if(dynamic_cast<Extendable*>(entity)->pickup(this))
     
    9696}
    9797
     98/**
     99 * data copied in data will bee sent to another host
     100 * @param data pointer to data
     101 * @param maxLength max length of data
     102 * @return the number of bytes writen
     103 */
     104int PowerUp::readState( byte * data, int maxLength )
     105{
     106  SYNCHELP_WRITE_BEGIN();
     107  SYNCHELP_WRITE_FKT( WorldEntity::readState );
     108  return SYNCHELP_WRITE_N;
     109}
     110
     111/**
     112 * Writes data from network containing information about the state
     113 * @param data pointer to data
     114 * @param length length of data
     115 * @param sender hostID of sender
     116 */
     117int PowerUp::writeState( const byte * data, int length, int sender )
     118{
     119  SYNCHELP_READ_BEGIN();
     120  SYNCHELP_READ_FKT( WorldEntity::writeState );
     121  return SYNCHELP_READ_N;
     122}
     123
  • branches/network/src/world_entities/power_ups/power_up.h

    r6282 r6419  
    2626  void setRespawnType(const char* type);
    2727
     28  int       writeState(const byte* data, int length, int sender);
     29  int       readState(byte* data, int maxLength );
     30
    2831protected:
    2932  PowerUp(float r, float g, float b);
  • branches/network/src/world_entities/power_ups/turret_power_up.cc

    r6222 r6419  
    1818#include "turret_power_up.h"
    1919#include "factory.h"
     20#include "network_game_manager.h"
    2021#include "state.h"
    2122
     
    118119}
    119120
     121int TurretPowerUp::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 );
     129
     130  return SYNCHELP_READ_N;
     131}
     132
     133
     134
     135int TurretPowerUp::readBytes( byte * data, int maxLength, int * reciever )
     136{
     137  if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
     138  {
     139    (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
     140    setRequestedSync( true );
     141  }
     142
     143  int rec = this->getRequestSync();
     144  if ( rec > 0 )
     145  {
     146    *reciever = rec;
     147
     148    SYNCHELP_WRITE_BEGIN();
     149
     150    SYNCHELP_WRITE_FKT( PowerUp::readState );
     151
     152    return SYNCHELP_WRITE_N;
     153  }
     154
     155  *reciever = 0;
     156  return 0;
     157}
  • branches/network/src/world_entities/power_ups/turret_power_up.h

    r5511 r6419  
    2323  virtual void draw() const;
    2424
     25  virtual int writeBytes(const byte* data, int length, int sender);
     26  virtual int readBytes(byte* data, int maxLength, int * reciever );
     27
    2528  private:
    2629   void init();
  • branches/network/src/world_entities/power_ups/weapon_power_up.cc

    r6243 r6419  
    2020#include "state.h"
    2121#include "list.h"
     22#include "network_game_manager.h"
    2223
    2324#include "primitive_model.h"
     
    8586  this->weapon = dynamic_cast<Weapon*>(Factory::fabricate(name));
    8687}
     88
     89int WeaponPowerUp::writeBytes( const byte * data, int length, int sender )
     90{
     91  setRequestedSync( false );
     92  setIsOutOfSync( false );
     93
     94  SYNCHELP_READ_BEGIN();
     95
     96  SYNCHELP_READ_FKT( PowerUp::writeState );
     97
     98  //TODO: sync weapon class ( see loadParams )
     99
     100  return SYNCHELP_READ_N;
     101}
     102
     103
     104
     105int WeaponPowerUp::readBytes( byte * data, int maxLength, int * reciever )
     106{
     107  if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
     108  {
     109    (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
     110    setRequestedSync( true );
     111  }
     112
     113  int rec = this->getRequestSync();
     114  if ( rec > 0 )
     115  {
     116    *reciever = rec;
     117
     118    SYNCHELP_WRITE_BEGIN();
     119
     120    SYNCHELP_WRITE_FKT( PowerUp::readState );
     121
     122    //TODO: sync weapon class ( see loadParams )
     123
     124    return SYNCHELP_WRITE_N;
     125  }
     126
     127  *reciever = 0;
     128  return 0;
     129}
  • branches/network/src/world_entities/power_ups/weapon_power_up.h

    r6113 r6419  
    2222  void setWeaponClass(const char* name);
    2323
     24  virtual int writeBytes(const byte* data, int length, int sender);
     25  virtual int readBytes(byte* data, int maxLength, int * reciever );
     26
    2427protected:
    2528  virtual void respawn();
  • branches/network/src/world_entities/world_entity.cc

    r6418 r6419  
    106106void WorldEntity::loadModel(const char* fileName, float scaling, unsigned int modelNumber)
    107107{
     108  this->scaling = scaling;
    108109  if ( fileName != NULL && strcmp(fileName, "") )
    109110  {
Note: See TracChangeset for help on using the changeset viewer.