Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Dec 23, 2005, 5:30:22 PM (18 years ago)
Author:
rennerc
Message:

converter: added functions for strings
network_protocol: length and id are now int
network_game_manager: fixed some more bugs :D
skybox: is loaded on client corectly now :)

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

Legend:

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

    r6142 r6273  
    2222#include "static_model.h"
    2323#include "material.h"
     24#include "network_game_manager.h"
     25#include "converter.h"
    2426
    2527using namespace std;
     
    210212  this->setModel(model);
    211213}
     214
     215void SkyBox::writeBytes( const byte * data, int length, int sender )
     216{
     217  setRequestedSync( false );
     218  setIsOutOfSync( false );
     219
     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);
     224
     225  this->setSize( size );
     226  this->setTexture( textureName );
     227  this->rebuild();
     228}
     229
     230int SkyBox::readBytes( byte * data, int maxLength, int * reciever )
     231{
     232  if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
     233  {
     234    PRINTF(0)("Requesting sync! %d\n", this->getUniqueID());
     235    (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
     236    setRequestedSync( true );
     237  }
     238
     239  int rec = this->getRequestSync();
     240  if ( rec > 0 )
     241  {
     242    PRINTF(0)("Serving client %d which requested sync %d size=%f texture=%s\n", rec, this->getUniqueID(), this->size, this->textureName);
     243    *reciever = rec;
     244
     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
     261  }
     262
     263  *reciever = 0;
     264  return 0;
     265}
     266
     267void SkyBox::writeDebug( ) const
     268{
     269}
     270
     271void SkyBox::readDebug( ) const
     272{
     273}
  • branches/network/src/world_entities/skybox.h

    r5511 r6273  
    3535  void setSize(float size);
    3636  /** assumes jpg as input-format */
    37   void setTexture(const char* name) { this->setTextureAndType (name, "jpg"); };
     37  void setTexture(const char* name) { strncpy(textureName, name, 1024); this->setTextureAndType (name, "jpg"); };
    3838
    3939  void setTextureAndType(const char* name, const char* extension);
     
    4141                   const char* right, const char* front, const char* back);
    4242
     43  virtual void      writeBytes(const byte* data, int length, int sender);
     44  virtual int       readBytes(byte* data, int maxLength, int * reciever);
     45  virtual void      writeDebug() const;
     46  virtual void      readDebug() const;
     47
    4348 private:
    4449  void rebuild();
    4550
    46   Material**      material;        //!< Materials for the SkyBox. sorted by number (0-5) top, bottom, left, right, front, back
    47   float           size;            //!< Size of the SkyBox. This should match the frustum maximum range.
     51  Material**      material;          //!< Materials for the SkyBox. sorted by number (0-5) top, bottom, left, right, front, back
     52  float           size;              //!< Size of the SkyBox. This should match the frustum maximum range.
     53  char            textureName[1024]; //!< Name of the Texture
    4854
    4955};
Note: See TracChangeset for help on using the changeset viewer.