Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Dec 24, 2005, 2:15:49 PM (19 years ago)
Author:
rennerc
Message:

synchronizeable: added macros to help write/read data

Location:
branches/network/src/world_entities
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/world_entities/skybox.cc

    r6273 r6275  
    218218  setIsOutOfSync( false );
    219219
    220   int flsize = Converter::byteArrayToFloat( data, &size );
    221   Converter::byteArrayToString( data+flsize, textureName, length-flsize );
    222 
    223   PRINT(0)("GOT DATA: size=%f texture=%s\n", size, textureName);
     220  /*int flsize = Converter::byteArrayToFloat( data, &size );
     221  Converter::byteArrayToString( data+flsize, textureName, length-flsize );*/
     222
     223  SYNCHELP_READ_BEGIN();
     224  SYNCHELP_READ_FLOAT(size);
     225  SYNCHELP_READ_STRING( textureName, 1024 );
     226
     227  //PRINT(0)("GOT DATA: size=%f texture=%s\n", size, textureName);
    224228
    225229  this->setSize( size );
     
    228232}
    229233
     234
     235
    230236int SkyBox::readBytes( byte * data, int maxLength, int * reciever )
    231237{
    232238  if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
    233239  {
    234     PRINTF(0)("Requesting sync! %d\n", this->getUniqueID());
     240    //PRINTF(0)("Requesting sync! %d\n", this->getUniqueID());
    235241    (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
    236242    setRequestedSync( true );
     
    240246  if ( rec > 0 )
    241247  {
    242     PRINTF(0)("Serving client %d which requested sync %d size=%f texture=%s\n", rec, this->getUniqueID(), this->size, this->textureName);
     248    //PRINTF(0)("Serving client %d which requested sync %d size=%f texture=%s\n", rec, this->getUniqueID(), this->size, this->textureName);
    243249    *reciever = rec;
    244250
    245     int flsize = Converter::floatToByteArray( this->size, data, maxLength );
    246 
    247     if ( flsize <= 0 )
    248     {
    249       PRINTF(1)("Byte array is too small (%d) to store float\n", maxLength );
    250       return 0;
    251     }
    252 
    253     if ( strlen(textureName)+INTSIZE+flsize > maxLength )
    254     {
    255       PRINTF(1)("Byte array is too small (%d) to store data\n", maxLength );
    256       return 0;
    257     }
    258 
    259     return flsize + Converter::stringToByteArray( textureName, data+flsize, strlen(textureName), maxLength-flsize );
    260 
     251    SYNCHELP_WRITE_BEGIN();
     252    SYNCHELP_WRITE_FLOAT(this->size);
     253    SYNCHELP_WRITE_STRING(this->textureName);
     254
     255    return SYNCHELP_WRITE_N;
    261256  }
    262257
  • branches/network/src/world_entities/terrain.cc

    r6142 r6275  
    2424#include "resource_manager.h"
    2525#include "model.h"
     26#include "network_game_manager.h"
     27
    2628
    2729#include "glincl.h"
     
    5759    {
    5860      this->loadModel(fileName);
     61      strncpy( terrainFile, fileName, 1024 );
    5962    }
    6063  else
     
    98101  this->ssp = NULL;
    99102  this->vegetation = NULL;
     103  strncpy( this->vegetationFile, "", 1024 );
     104  strncpy( this->terrainFile, "", 1024 );
    100105}
    101106
     
    111116void Terrain::loadVegetation(const char* vegetationFile)
    112117{
     118  PRINTF(0)("loadVegetation: %s\n", vegetationFile);
    113119  if (this->vegetation)
    114120    ResourceManager::getInstance()->unload(this->vegetation, RP_LEVEL);
     
    116122  {
    117123    PRINTF(4)("fetching %s\n", vegetationFile);
    118       this->vegetation = (Model*)ResourceManager::getInstance()->load(vegetationFile, OBJ, RP_CAMPAIGN);
     124    this->vegetation = (Model*)ResourceManager::getInstance()->load(vegetationFile, OBJ, RP_CAMPAIGN);
     125    strncpy( this->vegetationFile, vegetationFile, 1024);
    119126  }
    120127  else
     
    315322    }
    316323}
     324
     325void Terrain::writeBytes( const byte * data, int length, int sender )
     326{
     327  setRequestedSync( false );
     328  setIsOutOfSync( false );
     329
     330  int n = Converter::byteArrayToString( data, vegetationFile, length );
     331  Converter::byteArrayToString( data+n, terrainFile, length-n );
     332
     333  //PRINT(0)("GOT DATA: size=%f texture=%s\n", size, textureName);
     334
     335  if ( strcmp(vegetationFile, "") )
     336    this->loadVegetation( vegetationFile );
     337  if ( strcmp(terrainFile, "") )
     338    this->loadModel( terrainFile );
     339
     340}
     341
     342int Terrain::readBytes( byte * data, int maxLength, int * reciever )
     343{
     344  if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
     345  {
     346    //PRINTF(0)("Requesting sync! %d\n", this->getUniqueID());
     347    (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
     348    setRequestedSync( true );
     349  }
     350
     351  int rec = this->getRequestSync();
     352  if ( rec > 0 )
     353  {
     354    //PRINTF(0)("Serving client %d which requested sync %d size=%f texture=%s\n", rec, this->getUniqueID(), this->size, this->textureName);
     355    *reciever = rec;
     356
     357    if ( strlen(vegetationFile)+INTSIZE > maxLength )
     358    {
     359      PRINTF(1)("Byte array is too small (%d) to store data\n", maxLength );
     360      return 0;
     361    }
     362
     363    int n = Converter::stringToByteArray( vegetationFile, data, strlen(vegetationFile), maxLength );
     364
     365    return n + Converter::stringToByteArray( terrainFile, data+n, strlen(terrainFile), maxLength-n );
     366
     367  }
     368
     369  *reciever = 0;
     370  return 0;
     371}
     372
     373void Terrain::writeDebug( ) const
     374{
     375}
     376
     377void Terrain::readDebug( ) const
     378{
     379}
  • branches/network/src/world_entities/terrain.h

    r5500 r6275  
    3030  virtual ~Terrain();
    3131
     32  virtual void      writeBytes(const byte* data, int length, int sender);
     33  virtual int       readBytes(byte* data, int maxLength, int * reciever);
     34  virtual void      writeDebug() const;
     35  virtual void      readDebug() const;
     36
    3237  void init();
    3338  void loadParams(const TiXmlElement* root);
     
    4449   Model*              vegetation;
    4550   int                 objectList;
     51   char                vegetationFile[1024];
     52   char                terrainFile[1024];
    4653};
    4754
Note: See TracChangeset for help on using the changeset viewer.