Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6737 in orxonox.OLD


Ignore:
Timestamp:
Jan 25, 2006, 9:29:45 PM (18 years ago)
Author:
patrick
Message:

trunk: merged network back to trunk

Location:
trunk/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/network/converter.cc

    r6634 r6737  
    8888 * @remarks: The int is stored in big-endian
    8989 * @param x: The int which is to convert
    90  * @return: A byte-array that accords the given int value
     90 * @return: The number of written bytes
    9191 */
    9292int Converter::intToByteArray(int x, byte* a, int length)
     
    124124 * Converts a byte-array into an int
    125125 * @param a: The byte-array which is to convert
    126  * @return: An int that accords the given byte-array
     126 * @param x: The place where the result is stored
     127 * @return: The number of read bytes
    127128 */
    128129int Converter::byteArrayToInt(const byte* a, int* x)
     
    150151/*!
    151152 * Converts a float into a string containing its binary representation
     153 * @param x: The float which is to convert
     154 * @return: A string containing the float's binary representation
    152155 */
    153156char* Converter::floatToBinString(float x)
     
    331334 * Converts a float value into a byte-array and stores the result into a given byte-array
    332335 * @param x: The float which is to convert
    333  * @return: A byte-array which accords the given float
    334  */
    335 int Converter::_floatToByteArray(float x, byte* a, int length)
     336 * @param a: The byte array where the result is to store
     337 * @param length: The length of the array a
     338 * @return: The number of written bytes
     339 */
     340int Converter::floatToByteArray(float x, byte* a, int length)
    336341{
    337342  if (length < FLOATSIZE)
     
    398403
    399404
    400     if (mantisse != 0)
    401     {
     405    //if (mantisse != 0)
     406    //{
    402407      while (mantisse < expmult)
    403408      {
     
    406411      }
    407412
    408       mantisse -= expmult;
    409     }
     413      if (exponent >= 0)
     414        mantisse -= expmult;
     415      else
     416      {
     417        //Denormalized
     418        while (exponent < 0)
     419        {
     420          mantisse /= 2;
     421          exponent++;
     422        }
     423        printf("Conv: Denorm");
     424      }
     425    //}
    410426  }
    411427
     
    414430
    415431  int hx = mantisse + expmult * exponent;
    416   int result = intToByteArray(hx, a, length);
     432  //int result = intToByteArray(hx, a, length);
     433  intToByteArray(hx, a, length);
    417434  if (sgn == -1)
    418435    a[3] += sgnadd;
     
    424441//    result[3] += sgnadd;
    425442
    426   return result;
     443  //return result;
     444  return FLOATSIZE;
    427445}
    428446
     
    431449 * Converts a byte-array into a float value
    432450 * @param a: The byte-array which is to convert
    433  * @return: A float value which accords the given byte-array
    434  */
    435 int Converter::_byteArrayToFloat(const byte* a, float* x)
     451 * @param x: The place where the result is to store
     452 * @return: The number of read bytes
     453 */
     454int Converter::byteArrayToFloat(const byte* a, float* x)
    436455{
    437456    //handle 0
     
    459478    return FLOATSIZE;
    460479  }
    461 
    462   mantisse += expmult;
    463   exponent -= 128;
    464 
     480  else if (exponent == 0 && mantisse != 0)
     481  {
     482    exponent = -126;
     483    printf("ReConv: Denorm");
     484  }
     485  else
     486  {
     487    mantisse += expmult;
     488    exponent -= 128;
     489  }
    465490
    466491  int sgn;
     
    498523 * Converts a float value into a byte-array
    499524 * @param x: The float which is to convert
    500  * @return: A byte-array which accords the given float
    501  */
    502 int Converter::floatToByteArray(float x, byte* a, int length)
    503 {
    504   if ( length<4 )
     525 * @param a: The array where the result is to store
     526 * @param length: The length of the array a
     527 * @return: The number of written bytes
     528 */
     529int Converter::_floatToByteArray(float x, byte* a, int length)
     530{
     531  if ( length< FLOATSIZE )
    505532  {
    506533    PRINTF(1)("Byte Array to small\n");
     
    511538  for (int i = 0; i < 4; i++)
    512539    a[i] = p[i];
    513   return 4;
     540 
     541  return FLOATSIZE;
    514542}
    515543
     
    518546 * Converts a byte-array into a float value
    519547 * @param a: The byte-array which is to convert
    520  * @return: A float value which accords the given byte-array
    521  */
    522 int Converter::byteArrayToFloat(const byte* a, float* x)
     548 * @param x: The place where the result is to store
     549 * @return: The number of read bytes
     550 */
     551int Converter::_byteArrayToFloat(const byte* a, float* x)
    523552{
    524553  *x = *((float*)a);
    525554
    526   return 4;
    527 }
     555  return FLOATSIZE;
     556}
     557
     558
     559
     560
     561
     562
     563
     564
     565
    528566
    529567/**
     
    627665}
    628666
     667void Converter::ArrayfloatTest(float x)
     668{
     669  //float x = 8.0f;
     670  //float x = numeric_limits<float>::infinity();
     671
     672  printf("To Convert: %e\n", x);
     673  byte* res = new byte[4];
     674
     675  int wr = floatToByteArray(x, res, 4);
     676  for (int i = 0; i < 4; i++)
     677    printf("%i ", res[i]);
     678  printf("  written bytes: %i \n", wr);
     679
     680  float y;
     681  int rd = byteArrayToFloat(res, &y);
     682  printf("ReConvert: %e\n", y);
     683  printf("Read bytes: %i   ->  ", rd);
     684
     685  if (x == y)
     686    printf("equal\n");
     687  else
     688    printf("different\n");
     689}
     690
    629691void Converter::debug()
    630692{
    631693  printf("We rulez\n");
    632694
    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   */
     695  ArrayfloatTest(0.125f);
     696  ArrayfloatTest(64.0f);
     697  ArrayfloatTest(0.0f);
     698  ArrayfloatTest(5.00091e-29f);
    645699
    646700  //floatTest(-18.0098f);
     
    648702  //floatTest(-0.0f);
    649703  //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 }
     704 
     705 
     706  //floatTest(-45.7e-32f);
     707  //floatTest(45.7e-33f);
     708  //floatTest(-45.7e-34f);
     709  //floatTest(45.7e-35f);
     710}
  • trunk/src/lib/network/converter.h

    r6634 r6737  
    5050    static void debug();
    5151    static void floatTest(float x);
     52    static void ArrayfloatTest(float x);
    5253    static float getDenormConst();
    5354
  • trunk/src/lib/network/network_game_manager.cc

    r6695 r6737  
    3232#include "network_manager.h"
    3333
     34#include "class_list.h"
    3435
    3536/* include your own header */
     
    462463
    463464
     465
     466bool NetworkGameManager::signalLeftPlayer(int userID)
     467{
     468  const std::list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE);
     469  std::list<BaseObject*>::const_iterator it = playableList->begin();
     470
     471  for(; it != playableList->end(); it++)
     472  {
     473    if( dynamic_cast<Synchronizeable*>(*it)->getOwner() == userID )
     474    {
     475      PRINTF(0)("remove playable from %i\n", userID);
     476      this->removeEntity(dynamic_cast<Synchronizeable*>(*it)->getUniqueID());
     477      return true;
     478    }
     479  }
     480  return false;
     481}
     482
     483
    464484/**
    465485 * Creates a buffer for user n
     
    527547        PNode *p = dynamic_cast<PNode*>(b);
    528548        p->setAbsCoor(pos);
    529         //p->updateNode(0);
     549        p->updateNode(0);
    530550        pos += Vector(1000.0, 1000.0, 1000.0);
    531551      }
  • trunk/src/lib/network/network_game_manager.h

    r6695 r6737  
    9595    void sendEntityList(int userID);
    9696
     97    bool signalNewPlayer(int userId);
     98    bool signalLeftPlayer(int userID);
     99
    97100
    98101  private:
     
    133136    bool canCreateEntity(ClassID classID);
    134137
    135     bool signalNewPlayer(int userId);
    136 
    137138    void resizeBufferVector(int n);
    138139
  • trunk/src/lib/network/network_stream.cc

    r6695 r6737  
    390390      handshakes[i] = NULL;
    391391
     392
     393      NetworkGameManager::getInstance()->signalLeftPlayer(i);
     394
    392395      if ( i == networkSockets.size()-1 )
    393396      {
  • trunk/src/world_entities/space_ships/space_ship.cc

    r6724 r6737  
    289289  this->weaponAction();
    290290
    291   if( xMouse != 0 || yMouse != 0)
     291  if( ( xMouse != 0 || yMouse != 0 ) && this->getOwner()==this->getHostID() )
    292292   {
    293293    if (xMouse > controlVelocityX) xMouse = controlVelocityX;
     
    532532
    533533  byte b;
    534   SYNCHELP_READ_BYTE( b );
    535 
    536   if ( b == DATA_state /*&& (this->getHostID()!=this->getOwner() || sender==0)*/ )
    537   {
    538     PRINTF(0)("GOT STATE %d\n", this->getUniqueID());
    539     setRequestedSync( false );
    540     setIsOutOfSync( false );
    541     SYNCHELP_READ_FKT( WorldEntity::writeState );
    542     //SYNCHELP_READ_FLOAT( cycle );
    543 
    544     return SYNCHELP_READ_N;
    545   }
    546 
    547 
    548   if ( b == DATA_flags /*&& this->getHostID()!=this->getOwner()*/ )
    549   {
    550     int flags = 0;
    551     SYNCHELP_READ_INT( flags );
    552 
    553     bUp = (flags & MASK_bUp) != 0;
    554     bDown = (flags & MASK_bDown) != 0;
    555     bLeft = (flags & MASK_bLeft) != 0;
    556     bRight = (flags & MASK_bRight) != 0;
    557     bAscend = (flags & MASK_bAscend) != 0;
    558     bDescend = (flags & MASK_bDescend) != 0;
    559     bFire = (flags & MASK_bFire) != 0;
    560     bRollL = (flags & MASK_bRollL) != 0;
    561     bRollR = (flags & MASK_bRollR) != 0;
    562 
    563   }
     534
     535  do
     536  {
     537    SYNCHELP_READ_BYTE( b );
     538
     539    if ( b == DATA_state /*&& (this->getHostID()!=this->getOwner() || sender==0)*/ )
     540    {
     541     PRINTF(0)("GOT STATE %d\n", this->getUniqueID());
     542     setRequestedSync( false );
     543     setIsOutOfSync( false );
     544     SYNCHELP_READ_FKT( WorldEntity::writeState );
     545     //SYNCHELP_READ_FLOAT( cycle );
     546
     547      return SYNCHELP_READ_N;
     548    }
     549
     550
     551    //TODO: do not recieve data if you are the owner
     552    if ( b == DATA_flags /*&& this->getHostID()!=this->getOwner()*/ )
     553    {
     554      int flags = 0;
     555      SYNCHELP_READ_INT( flags );
     556
     557      //bUp = (flags & MASK_bUp) != 0;
     558      //bDown = (flags & MASK_bDown) != 0;
     559      //bLeft = (flags & MASK_bLeft) != 0;
     560      //bRight = (flags & MASK_bRight) != 0;
     561      //bAscend = (flags & MASK_bAscend) != 0;
     562      //bDescend = (flags & MASK_bDescend) != 0;
     563      //bFire = (flags & MASK_bFire) != 0;
     564      //bRollL = (flags & MASK_bRollL) != 0;
     565      //bRollR = (flags & MASK_bRollR) != 0;
     566
     567    }
     568
     569    //TODO: do not recieve data if you are the owner
     570    if ( b == DATA_mouse /*&& this->getHostID()!=this->getOwner()*/ )
     571    {
     572      float asdf;
     573      SYNCHELP_READ_FLOAT( asdf );
     574      SYNCHELP_READ_FLOAT( asdf );
     575      SYNCHELP_READ_FLOAT( asdf );
     576      SYNCHELP_READ_FLOAT( asdf );
     577      //SYNCHELP_READ_FLOAT( mouseDir.w );
     578      //SYNCHELP_READ_FLOAT( mouseDir.v.x );
     579      //SYNCHELP_READ_FLOAT( mouseDir.v.y );
     580      //SYNCHELP_READ_FLOAT( mouseDir.v.z );
     581    }
     582  } while( b != 0 );
    564583
    565584  /*if ( b == DATA_mouse && this->getHostID()!=this->getOwner() )
     
    638657      SYNCHELP_WRITE_INT( mask );
    639658    }
    640     else
    641     {
    642       SYNCHELP_WRITE_BYTE( 0 );
    643     }
    644 
    645     /*if ( oldxMouse != xMouse || oldyMouse != yMouse )
    646     {
    647       oldxMouse = xMouse;
    648       oldyMouse = yMouse;
     659#define __OFFSET_ROT 0.05
     660    if ( fabs( oldMouseDir.w - mouseDir.w ) > __OFFSET_ROT ||
     661         fabs( oldMouseDir.v.x - mouseDir.v.x ) > __OFFSET_ROT ||
     662         fabs( oldMouseDir.v.y - mouseDir.v.y ) > __OFFSET_ROT ||
     663         fabs( oldMouseDir.v.z - mouseDir.v.z ) > __OFFSET_ROT )
     664    {
     665      oldMouseDir = mouseDir;
     666
    649667      SYNCHELP_WRITE_BYTE( DATA_mouse );
    650       SYNCHELP_WRITE_FLOAT( xMouse );
    651       SYNCHELP_WRITE_FLOAT( yMouse );
    652       SYNCHELP_WRITE_FLOAT( mouseSensitivity );
    653       SYNCHELP_WRITE_FLOAT( cycle );
    654     }*/
    655   }
    656   else
    657   {
    658     SYNCHELP_WRITE_BYTE( 0 );
    659   }
     668      SYNCHELP_WRITE_FLOAT( mouseDir.w );
     669      SYNCHELP_WRITE_FLOAT( mouseDir.v.x );
     670      SYNCHELP_WRITE_FLOAT( mouseDir.v.y );
     671      SYNCHELP_WRITE_FLOAT( mouseDir.v.z );
     672    }
     673
     674  }
     675
     676  SYNCHELP_WRITE_BYTE( 0 );
     677
    660678
    661679  if ( this->getOwner() == this->getHostID() )
  • trunk/src/world_entities/space_ships/space_ship.h

    r6637 r6737  
    7272    Vector                velocity;           //!< the velocity of the player.
    7373    Quaternion            mouseDir;           //!< the direction where the player wants to fly
     74    Quaternion            oldMouseDir;        //!< the direction where the player wanted to fly
    7475    float                 shipInertia;        //!< the inertia of the ship(how fast the ship reacts to a mouse input)
    7576    Quaternion            rotQuat;
  • trunk/src/world_entities/weapons/weapon_manager.cc

    r6736 r6737  
    217217bool WeaponManager::addWeapon(Weapon* weapon, int configID, int slotID)
    218218{
    219   assert(weapon != NULL);
     219  //if ( weapon == NULL )
     220    return false;
    220221
    221222  if (unlikely(configID >= WM_MAX_CONFIGS || slotID >= (int)this->slotCount))
Note: See TracChangeset for help on using the changeset viewer.