Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6634 in orxonox.OLD for trunk/src/lib


Ignore:
Timestamp:
Jan 21, 2006, 1:18:19 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the network-branche back to the trunk

merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/network . -r6500:HEAD
minor conflicts in texture and one Makefile resolved to the trunk

also made a small patch to texture, so it Modulates with GL_REPEAT

Location:
trunk/src/lib
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/coord/p_node.cc

    r6624 r6634  
    505505{
    506506  PNode* childNode = dynamic_cast<PNode*>(ClassList::getObject(childName, CL_PARENT_NODE));
     507//  PRINTF(0)("Adding the Child: %s to: %s\n", childName, this->getName());
     508//  assert( childNode != NULL );
    507509  if (childNode != NULL)
     510  {
    508511    this->addChild(childNode);
     512  }
    509513}
    510514
     
    10691073  SYNCHELP_READ_FLOAT( f3 );
    10701074  this->setRelCoor( f1, f2, f3 );
    1071   //this->setRelCoor( 5, 0, 0 );
    1072 
    1073   /*SYNCHELP_READ_FLOAT( f1 );
    1074   SYNCHELP_READ_FLOAT( f2 );
    1075   SYNCHELP_READ_FLOAT( f3 );*/
    1076   //this->setAbsCoor( f1, f2, f3 );
     1075
    10771076
    10781077  SYNCHELP_READ_FLOAT( f1 );
     
    10821081  this->setRelDir( Quaternion( Vector(f2, f3, f4), f1 ) );
    10831082
    1084   /*SYNCHELP_READ_FLOAT( f1 );
    1085   SYNCHELP_READ_FLOAT( f2 );
    1086   SYNCHELP_READ_FLOAT( f3 );
    1087   SYNCHELP_READ_FLOAT( f4 );*/
    1088   //this->setAbsDir( Quaternion( Vector(f2, f3, f4), f1 ) );
    1089 
    10901083  int n;
    10911084  char * childName;
    10921085
     1086  PRINTF(0)("JKLO %d %d %d %d\n", data[__synchelp_read_i], data[__synchelp_read_i+1], data[__synchelp_read_i+2], data[__synchelp_read_i+3]);
    10931087  SYNCHELP_READ_INT( n );
     1088  PRINTF(0)("read %s:n=%d\n", this->getName(), n);
    10941089
    10951090  for (int i = 0; i<n; i++)
    10961091  {
    10971092    SYNCHELP_READ_STRINGM( childName );
    1098     //PRINTF(0)("childname = %s\n", childName);
     1093    PRINTF(0)("RCVD CHILD = %s\n", childName);
    10991094    addChild( childName );
    11001095    delete childName;
     
    11321127  SYNCHELP_WRITE_FLOAT( this->relCoordinate.z );
    11331128
    1134   //PRINTF(0)("%s, %f, %f, %f\n", getClassName(), relCoordinate.x, relCoordinate.y, relCoordinate.z);
    1135 
    1136   /*SYNCHELP_WRITE_FLOAT( this->absCoordinate.x );
    1137   SYNCHELP_WRITE_FLOAT( this->absCoordinate.y );
    1138   SYNCHELP_WRITE_FLOAT( this->absCoordinate.z );*/
    1139 
    1140   //PRINTF(0)("%s, %f, %f, %f\n", getClassName(), absCoordinate.x, absCoordinate.y, absCoordinate.z);
    1141 
    11421129  SYNCHELP_WRITE_FLOAT( this->relDirection.w );
    11431130  SYNCHELP_WRITE_FLOAT( this->relDirection.v.x );
     
    11451132  SYNCHELP_WRITE_FLOAT( this->relDirection.v.z );
    11461133
    1147   /*SYNCHELP_WRITE_FLOAT( this->absDirection.w );
    1148   SYNCHELP_WRITE_FLOAT( this->absDirection.v.x );
    1149   SYNCHELP_WRITE_FLOAT( this->absDirection.v.y );
    1150   SYNCHELP_WRITE_FLOAT( this->absDirection.v.z );*/
    1151 
    11521134  int n = children.size();
     1135
     1136  //check if camera is in children
     1137  for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++)
     1138  {
     1139    if ( (*it)->isA(CL_CAMERA) )
     1140      n--;
     1141  }
     1142  PRINTF(0)("write %s:n=%d\n", this->getName(), n);
    11531143  SYNCHELP_WRITE_INT( n );
     1144  PRINTF(0)("ASDF %d %d %d %d\n", data[__synchelp_write_i-4], data[__synchelp_write_i-3], data[__synchelp_write_i-2], data[__synchelp_write_i-1]);
    11541145
    11551146  for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++)
    11561147  {
    1157     SYNCHELP_WRITE_STRING( (*it)->getName() );
     1148    //dont add camera because there is only one camera attached to local player
     1149    if ( !(*it)->isA(CL_CAMERA) )
     1150    {
     1151      PRINTF(0)("SENDING CHILD: %s\n", (*it)->getName());
     1152      SYNCHELP_WRITE_STRING( (*it)->getName() );
     1153    }
    11581154  }
    11591155
    11601156  return SYNCHELP_WRITE_N;
    11611157}
     1158
     1159#define __FLAG_COOR 1
     1160#define __FLAG_ROT  2
     1161
     1162#define __OFFSET_POS 1
     1163#define __OFFSET_ROT 0.05
     1164
     1165/**
     1166 * Writes data from network containing information about the state which has changed
     1167 * @param data pointer to data
     1168 * @param length length of data
     1169 * @param sender hostID of sender
     1170 */
     1171int PNode::writeSync( const byte * data, int length, int sender )
     1172{
     1173  SYNCHELP_READ_BEGIN();
     1174
     1175  if ( this->getHostID()==this->getOwner() )
     1176  {
     1177    return SYNCHELP_READ_N;
     1178  }
     1179
     1180  byte flags = 0;
     1181  SYNCHELP_READ_BYTE( flags );
     1182  //PRINTF(0)("%s::FLAGS = %d\n", this->getName(), flags);
     1183
     1184  float f1, f2, f3, f4;
     1185
     1186  if ( flags & __FLAG_COOR )
     1187  {
     1188    SYNCHELP_READ_FLOAT( f1 );
     1189    SYNCHELP_READ_FLOAT( f2 );
     1190    SYNCHELP_READ_FLOAT( f3 );
     1191    PRINTF(0)("RCVD COOR: %f %f %f\n", f1, f2, f3);
     1192    this->setRelCoor( f1, f2, f3 );
     1193  }
     1194
     1195  if ( flags & __FLAG_ROT )
     1196  {
     1197    SYNCHELP_READ_FLOAT( f1 );
     1198    SYNCHELP_READ_FLOAT( f2 );
     1199    SYNCHELP_READ_FLOAT( f3 );
     1200    SYNCHELP_READ_FLOAT( f4 );
     1201    PRINTF(0)("RCVD QUAT: %f %f %f %f\n", f1, f2, f3, f4);
     1202    //this->setRelDir( Quaternion( Vector(f2, f3, f4), f1 ) );
     1203    Quaternion q;
     1204    q.w = f1;
     1205    q.v.x = f2;
     1206    q.v.y = f3;
     1207    q.v.z = f4;
     1208    this->setAbsDir( q );
     1209  }
     1210
     1211  return SYNCHELP_READ_N;
     1212}
     1213
     1214/**
     1215 * data copied in data will bee sent to another host
     1216 * @param data pointer to data
     1217 * @param maxLength max length of data
     1218 * @return the number of bytes writen
     1219 */
     1220int PNode::readSync( byte * data, int maxLength )
     1221{
     1222  SYNCHELP_WRITE_BEGIN();
     1223
     1224  if ( this->getHostID()!=this->getOwner() )
     1225  {
     1226    return SYNCHELP_WRITE_N;
     1227  }
     1228
     1229  byte flags = 0;
     1230  if ( fabs( coorx - relCoordinate.x ) > __OFFSET_POS ||
     1231       fabs( coory - relCoordinate.y ) > __OFFSET_POS ||
     1232       fabs( coorz - relCoordinate.z ) > __OFFSET_POS )
     1233    flags |= __FLAG_COOR;
     1234
     1235  if ( fabs( rotw - absDirection.w ) > __OFFSET_ROT ||
     1236       fabs( rotx - absDirection.v.x ) > __OFFSET_ROT ||
     1237       fabs( roty - absDirection.v.y ) > __OFFSET_ROT ||
     1238       fabs( rotz - absDirection.v.z ) > __OFFSET_ROT )
     1239    flags |= __FLAG_ROT;
     1240
     1241
     1242  SYNCHELP_WRITE_BYTE( flags );
     1243  //PRINTF(0)("FLAGS = %d\n", flags);
     1244
     1245  if ( flags & __FLAG_COOR )
     1246  {
     1247
     1248    PRINTF(0)("SEND COOR: %f %f %f\n", this->relCoordinate.x, this->relCoordinate.y, this->relCoordinate.z);
     1249
     1250    SYNCHELP_WRITE_FLOAT( this->relCoordinate.x );
     1251    SYNCHELP_WRITE_FLOAT( this->relCoordinate.y );
     1252    SYNCHELP_WRITE_FLOAT( this->relCoordinate.z );
     1253
     1254    coorx = relCoordinate.x;
     1255    coory = relCoordinate.y;
     1256    coorz = relCoordinate.z;
     1257  }
     1258
     1259  if ( flags & __FLAG_ROT )
     1260  {
     1261
     1262    PRINTF(0)("SEND QUAT: %f %f %f %f\n", this->absDirection.w, this->absDirection.v.x, this->absDirection.v.y, this->absDirection.v.z);
     1263
     1264    SYNCHELP_WRITE_FLOAT( this->absDirection.w );
     1265    SYNCHELP_WRITE_FLOAT( this->absDirection.v.x );
     1266    SYNCHELP_WRITE_FLOAT( this->absDirection.v.y );
     1267    SYNCHELP_WRITE_FLOAT( this->absDirection.v.z );
     1268
     1269    rotw = absDirection.w;
     1270    rotx = absDirection.v.x;
     1271    roty = absDirection.v.y;
     1272    rotz = absDirection.v.z;
     1273  }
     1274
     1275  return SYNCHELP_WRITE_N;
     1276}
  • trunk/src/lib/coord/p_node.h

    r6616 r6634  
    186186  int       writeState(const byte* data, int length, int sender);
    187187  int       readState(byte* data, int maxLength );
     188  int       writeSync(const byte* data, int length, int sender);
     189  int       readSync(byte* data, int maxLength );
    188190
    189191 private:
     
    229231
    230232  static PNode*      nullParent;         //!< The ROOT of the main PNode Tree.
     233
     234  private:
     235    float coorx;
     236    float coory;
     237    float coorz;
     238
     239    float rotw;
     240    float rotx;
     241    float roty;
     242    float rotz;
    231243};
    232244
  • trunk/src/lib/graphics/graphics_engine.cc

    r6523 r6634  
    274274    this->hwExtensions = new SubString((char*)glGetString(GL_EXTENSIONS), " \n\t,");
    275275
    276   PRINT(4)("Running on : %s %s %s\n", vendor, renderer, version);
     276  PRINT(4)("Running on : vendor: %s,  renderer: %s,  version:%s\n", vendor, renderer, version);
    277277  PRINT(4)("Extensions:\n");
    278278  if (this->hwExtensions != NULL)
  • trunk/src/lib/graphics/importer/texture.cc

    r6532 r6634  
    260260  glBindTexture(target, texture);
    261261
    262   glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
     262  glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT);
     263  glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_REPEAT);
     264
     265  glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR/*_MIPMAP_LINEAR*/);
    263266  glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    264267
    265 
    266   glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT);
    267   glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_REPEAT);
     268  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_PRIORITY, this->priority);
     269
    268270
    269271  /* control the mipmap levels */
    270 //   glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, 5);f
    271 //   glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0);
    272   glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_PRIORITY, this->priority);
     272  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, 5);
     273  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0);
    273274
    274275  /* build the Texture  OpenGL V >= 1.1 */
     
    295296    PRINTF(1)("Error while loading texture (mipmap generation), gluBuild2DMipmaps returned %i\n", errorCode);
    296297
     298  // Deselect newly built texture, as we do not want to display with this texture.
    297299  if (target == GL_TEXTURE_2D)
    298300    glBindTexture(target, 0);
     301
    299302  return texture;
    300303}
  • trunk/src/lib/lang/base_object.cc

    r6517 r6634  
    224224  SYNCHELP_WRITE_BEGIN();
    225225
     226  //PRINTF(0)("objectname = %s\n", this->objectName);
    226227  SYNCHELP_WRITE_STRING( this->objectName );
    227228
  • trunk/src/lib/network/converter.cc

    r6341 r6634  
    2222/* include your own header */
    2323#include "converter.h"
     24#include "shell_command.h"
     25
     26#include <limits>
     27
     28SHELL_COMMAND_STATIC(debug, Converter, Converter::debug);
    2429
    2530
     
    182187const int expmult = 8388608; //2^23
    183188
     189float Converter::getDenormConst()
     190{
     191  const int exp = 126;
     192  float result = 1.0f;
     193  for (int i = 0; i < exp; i++)
     194    result /= 2.0f;
     195  return result;
     196}
     197
    184198/*!
    185199 * Converts a float value into a byte-array
     
    189203byte* Converter::floatToByteArray(float x)
    190204{
     205  byte* result = new byte[4];
     206  floatToByteArray(x, result, 4);
     207  return result;
     208  /*
    191209  int mantisse = 0;
    192210  int exponent = 128;
     
    201219    sgn = 1;
    202220
    203   float sub = 1;
    204   while (sub < x)
    205   {
    206     sub *= 2;
     221  if (x == 0)
     222  {
     223    exponent = 255;
     224    mantisse = 0;
     225  }
     226  else
     227  {
     228    //if (x < getDenormConst())
     229    //  printf("Denormalisiert!\n");
     230    //printf("DenormConst = %e", getDenormConst());
     231
     232    float sub = 1;
     233    while (sub < x)
     234    {
     235      sub *= 2;
     236      exponent++;
     237    }
     238
     239    while (x > 0)
     240    {
     241      if (x >= sub)
     242      {
     243        mantisse += 1;
     244        x -= sub;
     245      }
     246
     247      mantisse *= 2;
     248      exponent--;
     249      sub /= 2;
     250    }
    207251    exponent++;
    208   }
    209 
    210   while (x > 0)
    211   {
    212     if (x >= sub)
    213     {
    214       mantisse += 1;
    215       x -= sub;
    216     }
    217 
    218     mantisse *= 2;
    219     exponent--;
    220     sub /= 2;
    221   }
    222   exponent++;
    223   mantisse /= 2;
    224   while (mantisse < expmult)
    225   {
    226     mantisse *= 2;
    227     exponent--;
    228   }
    229 
    230   //printf("mantisse = %i exponent = %i \n", mantisse, exponent);
    231 
    232   mantisse -= expmult;
     252    mantisse /= 2;
     253
     254    printf("Conv:        mantisse = %i exponent = %i \n", mantisse, exponent);
     255
     256
     257    if (mantisse != 0)
     258    {
     259      while (mantisse < expmult)
     260      {
     261        mantisse *= 2;
     262        exponent--;
     263      }
     264
     265      mantisse -= expmult;
     266    }
     267  }
     268
     269  printf("Conv: mantisse = %i exponent = %i \n", mantisse, exponent);
     270
    233271
    234272  int hx = mantisse + expmult * exponent;
     
    238276
    239277  return result;
     278  */
    240279}
    241280
     
    248287float Converter::byteArrayToFloat(byte* a)
    249288{
     289  byte* h = new byte[4];
     290  float result = 0.0f;
     291  byteArrayToFloat(a, &result);
     292  return result;
     293  /*
     294  int hexp = a[2] + a[3] * 256;
     295  int exponent = (hexp / 128) % 256;
     296
    250297  int hmant = a[0] + a[1] * 256 + a[2] * 65536;
    251298  int mantisse = hmant % expmult;
     299  if (mantisse == 0 && exponent == 255)
     300    return 0;
     301
    252302  mantisse += expmult;
    253 
    254   int hexp = a[2] + a[3] * 256;
    255   int exponent = (hexp / 128) % 256 - 128;
     303  exponent -= 128;
     304
    256305
    257306  int sgn;
     
    261310    sgn = 1;
    262311
    263   //printf("mantisse = %i exponent = %i \n", mantisse, exponent);
     312  printf("ReConv: mantisse = %i exponent = %i \n", mantisse, exponent);
    264313
    265314  float emult = 1;
     
    276325
    277326  return result;
    278 }
    279 
    280 /*!
    281  * Converts a float value into a byte-array
    282  * @param x: The float which is to convert
    283  * @return: A byte-array which accords the given float
    284  */
    285 byte* Converter::_floatToByteArray(float x)
    286 {
    287   byte* p = (byte*)&x;
    288   byte* result = new byte[4];
    289   for (int i = 0; i < 4; i++)
    290     result[i] = p[i];
    291   return result;
    292 }
    293 
    294 
    295 /*!
    296  * Converts a byte-array into a float value
    297  * @param a: The byte-array which is to convert
    298  * @return: A float value which accords the given byte-array
    299  */
    300 float Converter::_byteArrayToFloat(byte* a)
    301 {
    302   float* p = (float*)a;
    303   float result = *p;
    304   return result;
     327  */
    305328}
    306329
     
    310333 * @return: A byte-array which accords the given float
    311334 */
    312 int Converter::floatToByteArray(float x, byte* a, int length)
     335int Converter::_floatToByteArray(float x, byte* a, int length)
    313336{
    314337  if (length < FLOATSIZE)
     
    319342
    320343  //handle 0 else function will loop for ever
    321   if ( x == 0 )
     344  /*if ( x == 0 )
    322345  {
    323346    for ( int i = 0; i<FLOATSIZE; i++)
    324347      a[i] = 0;
    325348    return FLOATSIZE;
    326   }
     349}*/
    327350
    328351  int mantisse = 0;
     
    338361    sgn = 1;
    339362
    340   float sub = 1;
    341   while (sub < x)
    342   {
    343     sub *= 2;
     363  if (x == 0)
     364  {
     365    exponent = 255;
     366    mantisse = 0;
     367  }
     368  else
     369  {
     370    //if (x < getDenormConst())
     371    //  printf("Denormalisiert!\n");
     372    //printf("DenormConst = %e", getDenormConst());
     373
     374    float sub = 1;
     375    while (sub < x)
     376    {
     377      sub *= 2;
     378      exponent++;
     379    }
     380
     381    while (x > 0)
     382    {
     383      if (x >= sub)
     384      {
     385        mantisse += 1;
     386        x -= sub;
     387      }
     388
     389      mantisse *= 2;
     390      exponent--;
     391      sub /= 2;
     392    }
    344393    exponent++;
    345   }
    346 
    347   while (x > 0)
    348   {
    349     if (x >= sub)
    350     {
    351       mantisse += 1;
    352       x -= sub;
    353     }
    354 
    355     mantisse *= 2;
    356     exponent--;
    357     sub /= 2;
    358   }
    359   exponent++;
    360   mantisse /= 2;
    361   while (mantisse < expmult)
    362   {
    363     mantisse *= 2;
    364     exponent--;
    365   }
    366 
    367   //printf("mantisse = %i exponent = %i \n", mantisse, exponent);
    368 
    369   mantisse -= expmult;
     394    mantisse /= 2;
     395
     396
     397///    printf("Conv:        mantisse = %i exponent = %i \n", mantisse, exponent);
     398
     399
     400    if (mantisse != 0)
     401    {
     402      while (mantisse < expmult)
     403      {
     404        mantisse *= 2;
     405        exponent--;
     406      }
     407
     408      mantisse -= expmult;
     409    }
     410  }
     411
     412///  printf("Conv: mantisse = %i exponent = %i \n", mantisse, exponent);
     413
    370414
    371415  int hx = mantisse + expmult * exponent;
     
    374418    a[3] += sgnadd;
    375419
     420
     421//  int hx = mantisse + expmult * exponent;
     422//  byte* result = intToByteArray(hx);
     423//  if (sgn == -1)
     424//    result[3] += sgnadd;
     425
    376426  return result;
    377427}
     
    383433 * @return: A float value which accords the given byte-array
    384434 */
    385 int Converter::byteArrayToFloat(const byte* a, float* x)
    386 {
    387   //handle 0
    388   for (int i = 0; i<FLOATSIZE; i++)
     435int Converter::_byteArrayToFloat(const byte* a, float* x)
     436{
     437    //handle 0
     438  /*for (int i = 0; i<FLOATSIZE; i++)
    389439  {
    390440    if (a[i]!=0)
     
    395445      return FLOATSIZE;
    396446    }
    397   }
    398 
     447}*/
     448
     449  int hexp = a[2] + a[3] * 256;
     450  int exponent = (hexp / 128) % 256;
    399451
    400452  int hmant = a[0] + a[1] * 256 + a[2] * 65536;
    401453  int mantisse = hmant % expmult;
     454
     455  //handle 0
     456  if (mantisse == 0 && exponent == 255)
     457  {
     458    *x = 0;
     459    return FLOATSIZE;
     460  }
     461
    402462  mantisse += expmult;
    403 
    404   int hexp = a[2] + a[3] * 256;
    405   int exponent = (hexp / 128) % 256 - 128;
     463  exponent -= 128;
     464
    406465
    407466  int sgn;
     
    411470    sgn = 1;
    412471
    413   //printf("mantisse = %i exponent = %i \n", mantisse, exponent);
     472///  printf("ReConv: mantisse = %i exponent = %i \n", mantisse, exponent);
    414473
    415474  float emult = 1;
     
    421480      emult /= 2;
    422481
     482  /*
     483  float result = mantisse * emult;
     484  if (sgn == -1)
     485    result = -result;
     486
     487  return result;
     488  */
     489
    423490  *x = mantisse * emult;
    424491  if (sgn == -1)
     
    426493
    427494  return FLOATSIZE;
     495}
     496
     497/*!
     498 * Converts a float value into a byte-array
     499 * @param x: The float which is to convert
     500 * @return: A byte-array which accords the given float
     501 */
     502int Converter::floatToByteArray(float x, byte* a, int length)
     503{
     504  if ( length<4 )
     505  {
     506    PRINTF(1)("Byte Array to small\n");
     507    return 0;
     508  }
     509  byte* p = (byte*)&x;
     510
     511  for (int i = 0; i < 4; i++)
     512    a[i] = p[i];
     513  return 4;
     514}
     515
     516
     517/*!
     518 * Converts a byte-array into a float value
     519 * @param a: The byte-array which is to convert
     520 * @return: A float value which accords the given byte-array
     521 */
     522int Converter::byteArrayToFloat(const byte* a, float* x)
     523{
     524  *x = *((float*)a);
     525
     526  return 4;
    428527}
    429528
     
    504603}
    505604
     605
     606
     607
     608void Converter::floatTest(float x)
     609{
     610  //float x = 8.0f;
     611  //float x = numeric_limits<float>::infinity();
     612
     613  printf("To Convert: %e\n", x);
     614
     615  byte* res = floatToByteArray(x);
     616  for (int i = 0; i < 4; i++)
     617    printf("%i ", res[i]);
     618  printf("\n");
     619
     620  float y = byteArrayToFloat(res);
     621  printf("ReConvert: %e\n", y);
     622
     623  if (x == y)
     624    printf("equal\n");
     625  else
     626    printf("different\n");
     627}
     628
     629void Converter::debug()
     630{
     631  printf("We rulez\n");
     632
     633  //Denormalized?
     634  //floatTest(-9.87624e-38f);
     635  //floatTest(-9.87624e-37f);
     636  //floatTest(-9.87624e-36f);
     637  //floatTest(-9.87624e-35f);
     638
     639  /*
     640  floatTest(14.7f);
     641  floatTest(12.07e15f);
     642  floatTest(0.0f);
     643  floatTest(5.67e-15f);
     644  */
     645
     646  //floatTest(-18.0098f);
     647  //floatTest(-24.07e23f);
     648  //floatTest(-0.0f);
     649  //floatTest(-5.67e-29f);
     650  floatTest(-45.7e-32f);
     651  floatTest(45.7e-33f);
     652  floatTest(-45.7e-34f);
     653  floatTest(45.7e-35f);
     654}
  • trunk/src/lib/network/converter.h

    r6341 r6634  
    99/* include this file, it contains some default definitions */
    1010#include "netdefs.h"
     11
    1112
    1213/* include base_object.h since all classes are derived from this one */
     
    2122 * a class that can convert int to byte-array and vice versa
    2223 */
    23 class Converter: public BaseObject
     24class Converter : public BaseObject
    2425{
    2526  public:
     
    4344    static float byteArrayToFloat(byte* a);
    4445
    45     static byte* _floatToByteArray(float x);
    46     static float _byteArrayToFloat(byte* a);
     46    static int _floatToByteArray(float x, byte* a, int length);
     47    static int _byteArrayToFloat(const byte* a, float* x);
     48
     49
     50    static void debug();
     51    static void floatTest(float x);
     52    static float getDenormConst();
     53
     54
    4755  private:
    4856    Converter();
     
    5058};
    5159
     60#undef byte
     61
    5262#endif /*_CONVERTER*/
  • trunk/src/lib/network/network_game_manager.cc

    r6498 r6634  
    5252  this->setClassID(CL_NETWORK_GAME_MANAGER, "NetworkGameManager");
    5353
    54   allOutBuffer.length = 0;
    55 
    56   allOutBuffer.maxLength = 10*1024;
    57 
    58   allOutBuffer.buffer = new byte[10*1024];
    59 
    6054  newUniqueID = MAX_CONNECTIONS + 2;
    6155
     
    7468  }
    7569
    76   if ( allOutBuffer.buffer )
    77     delete allOutBuffer.buffer;
    7870}
    7971
     
    10799      if ( b == CREATE_ENTITY )
    108100      {
     101        PRINTF(0)("CREATE_ENTITY\n");
    109102        if ( !handleCreateEntity( i, data, length, sender ) )
    110103          return i;
     
    137130    }
    138131
     132    if ( b == REQUEST_ENTITY_LIST )
     133    {
     134      sendEntityList( sender );
     135      continue;
     136    }
     137
    139138    if ( b == REQUEST_SYNC )
    140139    {
    141140      if ( !handleRequestSync( i, data, length, sender ) )
    142141        return i;
    143       continue;
    144     }
    145 
    146     if ( b == REQUEST_ENTITY_LIST )
    147     {
    148       sendEntityList( sender );
    149142      continue;
    150143    }
     
    188181  }
    189182
    190   *reciever = 0;
    191   int nbytes = allOutBuffer.length;
    192   allOutBuffer.length = 0;
    193 
    194   if ( nbytes <=0 )
    195     return 0;
    196 
    197   if ( nbytes > maxLength )
    198   {
    199     PRINTF(1)("OutBuffer.length (%d) > (%d) networkStreamBuffer.length\n", nbytes, maxLength);
    200     return 0;
    201   }
    202 
    203   memcpy( data, allOutBuffer.buffer, nbytes );
    204   return nbytes;
     183  return 0;
    205184}
    206185
     
    221200int NetworkGameManager::createEntity( ClassID classID, int owner )
    222201{
    223 
    224202  if ( this->isServer() )
    225203  {
     
    254232      return NULL;
    255233    }
    256     newUniqueID++;
    257234
    258235    BaseObject * b = Factory::fabricate( element );
     
    268245    {
    269246      Synchronizeable * s = dynamic_cast<Synchronizeable*>(b);
    270       s->setUniqueID( newUniqueID );
     247      s->setUniqueID( newUniqueID++ );
    271248      s->setOwner( 0 );
    272249      this->networkStream->connectSynchronizeable( *s );
     
    313290void NetworkGameManager::requestCreateEntity(ClassID classID)
    314291{
    315   if ( !writeToClientBuffer( allOutBuffer, (byte)REQUEST_CREATE ) )
    316     return;
    317   if ( !writeToClientBuffer( allOutBuffer, (int)classID ) )
    318     return;
     292  for ( int i = 0; i<outBuffer.size(); i++)
     293  {
     294    if ( !this->networkStream->isUserIdActive( i ) )
     295      continue;
     296
     297    if ( !writeToClientBuffer( outBuffer[i], (byte)REQUEST_CREATE ) )
     298      return;
     299    if ( !writeToClientBuffer( outBuffer[i], (int)classID ) )
     300      return;
     301  }
    319302}
    320303
     
    325308void NetworkGameManager::requestRemoveEntity(int uniqueID)
    326309{
    327   if ( !writeToClientBuffer( allOutBuffer, (byte)REQUEST_REMOVE ) )
    328     return;
    329   if ( !writeToClientBuffer( allOutBuffer, uniqueID ) )
    330     return;
     310  for ( int i = 0; i<outBuffer.size(); i++)
     311  {
     312    if ( !this->networkStream->isUserIdActive( i ) )
     313      continue;
     314
     315    if ( !writeToClientBuffer( outBuffer[i], (byte)REQUEST_REMOVE ) )
     316      return;
     317    if ( !writeToClientBuffer( outBuffer[i], uniqueID ) )
     318      return;
     319  }
    331320}
    332321
     
    338327int NetworkGameManager::executeCreateEntity(ClassID classID, int uniqueID, int owner)
    339328{
    340   if ( !writeToClientBuffer( allOutBuffer, (byte)CREATE_ENTITY ) )
    341     return -1;
    342   if ( !writeToClientBuffer( allOutBuffer, (int)classID ) )
    343     return -1;
    344   if ( !writeToClientBuffer( allOutBuffer, uniqueID ) )
    345     return -1;
    346   if ( !writeToClientBuffer( allOutBuffer, owner ) )
    347     return -1;
     329  for ( int i = 0; i<outBuffer.size(); i++)
     330  {
     331    if ( !this->networkStream->isUserIdActive( i ) )
     332      continue;
     333
     334    if ( !writeToClientBuffer( outBuffer[i], (byte)CREATE_ENTITY ) )
     335      return -1;
     336    if ( !writeToClientBuffer( outBuffer[i], (int)classID ) )
     337      return -1;
     338    if ( !writeToClientBuffer( outBuffer[i], uniqueID ) )
     339      return -1;
     340    if ( !writeToClientBuffer( outBuffer[i], owner ) )
     341      return -1;
     342  }
    348343
    349344  doCreateEntity( classID, uniqueID, owner );
     
    359354void NetworkGameManager::executeRemoveEntity(int uniqueID)
    360355{
    361   if ( !writeToClientBuffer( allOutBuffer, (byte)REMOVE_ENTITY ) )
    362     return;
    363   if ( !writeToClientBuffer( allOutBuffer, uniqueID ) )
    364     return;
     356  for ( int i = 0; i<outBuffer.size(); i++)
     357  {
     358    if ( !this->networkStream->isUserIdActive( i ) )
     359      continue;
     360
     361    if ( !writeToClientBuffer( outBuffer[i], (byte)REMOVE_ENTITY ) )
     362      return;
     363    if ( !writeToClientBuffer( outBuffer[i], uniqueID ) )
     364      return;
     365  }
    365366
    366367  doRemoveEntity(uniqueID);
     
    406407  while ( it != e )
    407408  {
    408 
     409    PRINTF(5)("SENDING ENTITY %s id %d\n", (*it)->getClassName(), (*it)->getUniqueID() );
    409410    if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getLeafClassID()) ) )
    410411      return;
     
    426427bool NetworkGameManager::signalNewPlayer(int userId)
    427428{
     429  if ( userId >= outBuffer.size() )
     430    resizeBufferVector( userId );
    428431
    429432  /* create new playable for Player*/
     
    483486
    484487    //HACK: hack to prevent collision
    485     if ( b->isA(CL_WORLD_ENTITY) )
     488    if ( b->isA(CL_WORLD_ENTITY) && !b->isA(CL_PLAYABLE) )
    486489    {
    487490      if ( NetworkManager::getInstance()->getHostID()!=0 )
     
    489492        static Vector pos = Vector(1000.0, 1000.0, 1000.0);
    490493        PNode *p = dynamic_cast<PNode*>(b);
    491         p->setRelCoor(pos);
    492         p->updateNode(0);
     494        p->setAbsCoor(pos);
     495        //p->updateNode(0);
    493496        pos += Vector(1000.0, 1000.0, 1000.0);
    494497      }
     
    596599
    597600  Playable *p = NULL;
     601  Synchronizeable *s = NULL;
    598602
    599603  for ( ; it !=networkStream->getSyncEnd(); it++ )
     
    601605    if ( (*it)->getUniqueID()==uniqueID )
    602606    {
     607      if ( (*it)->isA( CL_SYNCHRONIZEABLE ) )
     608      {
     609        s = dynamic_cast<Synchronizeable*>(*it);
     610      }
    603611      if ( (*it)->isA( CL_PLAYABLE ) )
    604612      {
     
    614622  Player* player = State::getPlayer();
    615623  assert(p != NULL);
     624  assert(s != NULL);
    616625  assert(player != NULL);
     626
     627  s->setIsOutOfSync( true );
     628
     629  PRINTF(0)("uniqueID = %d\n", s->getUniqueID());
    617630
    618631  player->setControllable(p);
     
    871884void NetworkGameManager::sync( int uniqueID, int owner )
    872885{
    873   if ( owner==this->getHostID() )
    874     return;
     886  /*if ( owner==this->getHostID() )
     887  return;*/
    875888
    876889  if ( !isServer() )
  • trunk/src/lib/network/network_game_manager.h

    r6498 r6634  
    122122  private:
    123123    std::vector<clientBuffer>     outBuffer;
    124     clientBuffer                  allOutBuffer;
     124    //clientBuffer                  allOutBuffer;
    125125    static NetworkGameManager*    singletonRef;
    126126
  • trunk/src/lib/network/network_socket.cc

    r6341 r6634  
    398398bool NetworkSocket::writePacket( byte * data, int length )
    399399{
    400   PRINTF(5)("NetworkSocket::writePacket()\n");
     400  PRINTF(5)("NetworkSocket::writePacket() size=%d\n", length);
     401
     402  if ( length > 1024 )
     403  PRINTF(2)("WARNING SENDING BIG PACKET SIZE = %d\n", length);
    401404
    402405  byte blen[INTSIZE];
  • trunk/src/lib/network/network_stream.cc

    r6498 r6634  
    7878  this->connectionMonitor = new ConnectionMonitor();
    7979  this->networkSockets.push_back( NULL );
     80  this->networkSockets[0] = NULL; //TODO: remove this
    8081  this->handshakes.push_back( NULL );
    8182  this->bActive = true;
     
    266267            if ( networkSockets[i] != NULL )
    267268            {
    268               PRINTF(5)("write %d bytes to socket %d\n", dataLength, reciever);
     269              PRINTF(5)("write %d bytes to socket %d\n", dataLength, i);
    269270              networkSockets[i]->writePacket(downBuffer, dataLength);
    270271            }
     
    310311            if ( (*it)->writeBytes(upBuffer+sizeof(header), dataLength, i) != header.length )
    311312            {
    312               PRINTF(1)("%s did not read all the data!\n", (*it)->getClassName());
     313              PRINTF(1)("%s did not read all the data id = %d!\n", (*it)->getClassName(), (*it)->getUniqueID());
    313314              break;
    314315            }
  • trunk/src/lib/network/network_stream.h

    r6341 r6634  
    5555    inline int getSyncCount(){ return synchronizeables.size(); }
    5656
     57    inline bool isUserIdActive( int userID ) { if (userID>=networkSockets.size()) return false; else return networkSockets[userID]!=NULL; }
     58
    5759  private:
    5860    NetworkProtocol*       networkProtocol;
  • trunk/src/lib/sound/sound_source.h

    r5930 r6634  
    4444    ALuint                 sourceID;              //!< The ID of the Source
    4545    const SoundBuffer*     buffer;                //!< The buffer to play in this source.
    46     const PNode*           sourceNode;            //!< The SourceNode represente the position/velocity... of this source.
     46    const PNode*           sourceNode;            //!< The SourceNode representing the position/velocity... of this source.
    4747};
    4848#endif /* _SOUND_SOURCE_H */
Note: See TracChangeset for help on using the changeset viewer.