Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6526 in orxonox.OLD


Ignore:
Timestamp:
Jan 18, 2006, 1:01:27 PM (18 years ago)
Author:
rennerc
Message:

pnode can sync now

Location:
branches/network/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/lib/coord/p_node.cc

    r6500 r6526  
    501501{
    502502  PNode* childNode = dynamic_cast<PNode*>(ClassList::getObject(childName, CL_PARENT_NODE));
     503//  PRINTF(0)("Adding the Child: %s to: %s\n", childName, this->getName());
     504//  assert( childNode != NULL );
    503505  if (childNode != NULL)
     506  {
    504507    this->addChild(childNode);
     508  }
    505509}
    506510
     
    10631067  SYNCHELP_READ_FLOAT( f3 );
    10641068  this->setRelCoor( f1, f2, f3 );
    1065   //this->setRelCoor( 5, 0, 0 );
    1066 
    1067   /*SYNCHELP_READ_FLOAT( f1 );
    1068   SYNCHELP_READ_FLOAT( f2 );
    1069   SYNCHELP_READ_FLOAT( f3 );*/
    1070   //this->setAbsCoor( f1, f2, f3 );
     1069
    10711070
    10721071  SYNCHELP_READ_FLOAT( f1 );
     
    10761075  this->setRelDir( Quaternion( Vector(f2, f3, f4), f1 ) );
    10771076
    1078   /*SYNCHELP_READ_FLOAT( f1 );
    1079   SYNCHELP_READ_FLOAT( f2 );
    1080   SYNCHELP_READ_FLOAT( f3 );
    1081   SYNCHELP_READ_FLOAT( f4 );*/
    1082   //this->setAbsDir( Quaternion( Vector(f2, f3, f4), f1 ) );
    1083 
    10841077  int n;
    10851078  char * childName;
     
    11261119  SYNCHELP_WRITE_FLOAT( this->relCoordinate.z );
    11271120
    1128   //PRINTF(0)("%s, %f, %f, %f\n", getClassName(), relCoordinate.x, relCoordinate.y, relCoordinate.z);
    1129 
    1130   /*SYNCHELP_WRITE_FLOAT( this->absCoordinate.x );
    1131   SYNCHELP_WRITE_FLOAT( this->absCoordinate.y );
    1132   SYNCHELP_WRITE_FLOAT( this->absCoordinate.z );*/
    1133 
    1134   //PRINTF(0)("%s, %f, %f, %f\n", getClassName(), absCoordinate.x, absCoordinate.y, absCoordinate.z);
    1135 
    11361121  SYNCHELP_WRITE_FLOAT( this->relDirection.w );
    11371122  SYNCHELP_WRITE_FLOAT( this->relDirection.v.x );
     
    11391124  SYNCHELP_WRITE_FLOAT( this->relDirection.v.z );
    11401125
    1141   /*SYNCHELP_WRITE_FLOAT( this->absDirection.w );
    1142   SYNCHELP_WRITE_FLOAT( this->absDirection.v.x );
    1143   SYNCHELP_WRITE_FLOAT( this->absDirection.v.y );
    1144   SYNCHELP_WRITE_FLOAT( this->absDirection.v.z );*/
    1145 
    11461126  int n = children.size();
     1127
     1128  //check if camera is in children
     1129  for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++)
     1130  {
     1131    if ( (*it)->isA(CL_CAMERA) )
     1132      n--;
     1133  }
    11471134  SYNCHELP_WRITE_INT( n );
    11481135
    11491136  for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++)
    11501137  {
    1151     SYNCHELP_WRITE_STRING( (*it)->getName() );
     1138    //dont add camera because there is only one camera attached to local player
     1139    if ( !(*it)->isA(CL_CAMERA) )
     1140      SYNCHELP_WRITE_STRING( (*it)->getName() );
    11521141  }
    11531142
    11541143  return SYNCHELP_WRITE_N;
    11551144}
     1145
     1146#define __FLAG_COOR 1
     1147#define __FLAG_ROT  2
     1148
     1149#define __OFFSET 1.0
     1150
     1151/**
     1152 * Writes data from network containing information about the state which has changed
     1153 * @param data pointer to data
     1154 * @param length length of data
     1155 * @param sender hostID of sender
     1156 */
     1157int PNode::writeSync( const byte * data, int length, int sender )
     1158{
     1159  SYNCHELP_READ_BEGIN();
     1160
     1161  if ( this->getHostID()==this->getOwner() )
     1162  {
     1163    return SYNCHELP_READ_N;
     1164  }
     1165
     1166  byte flags = 0;
     1167  SYNCHELP_READ_BYTE( flags );
     1168  //PRINTF(0)("%s::FLAGS = %d\n", this->getName(), flags);
     1169
     1170  float f1, f2, f3, f4;
     1171
     1172  if ( flags & __FLAG_COOR )
     1173  {
     1174    SYNCHELP_READ_FLOAT( f1 );
     1175    SYNCHELP_READ_FLOAT( f2 );
     1176    SYNCHELP_READ_FLOAT( f3 );
     1177    this->setRelCoor( f1, f2, f3 );
     1178  }
     1179
     1180  if ( flags & __FLAG_ROT )
     1181  {
     1182    SYNCHELP_READ_FLOAT( f1 );
     1183    SYNCHELP_READ_FLOAT( f2 );
     1184    SYNCHELP_READ_FLOAT( f3 );
     1185    SYNCHELP_READ_FLOAT( f4 );
     1186    this->setRelDir( Quaternion( Vector(f2, f3, f4), f1 ) );
     1187  }
     1188
     1189  return SYNCHELP_READ_N;
     1190}
     1191
     1192/**
     1193 * data copied in data will bee sent to another host
     1194 * @param data pointer to data
     1195 * @param maxLength max length of data
     1196 * @return the number of bytes writen
     1197 */
     1198int PNode::readSync( byte * data, int maxLength )
     1199{
     1200  SYNCHELP_WRITE_BEGIN();
     1201
     1202  if ( this->getHostID()!=this->getOwner() )
     1203  {
     1204    return SYNCHELP_WRITE_N;
     1205  }
     1206
     1207  static float coorx = relCoordinate.x + 1;
     1208  static float coory = relCoordinate.y + 1;
     1209  static float coorz = relCoordinate.z + 1;
     1210
     1211  static float rotw = relDirection.w + 1;
     1212  static float rotx = relDirection.v.x + 1;
     1213  static float roty = relDirection.v.y + 1;
     1214  static float rotz = relDirection.v.z + 1;
     1215
     1216  byte flags = 0;
     1217  if ( fabs( coorx - relCoordinate.x ) > __OFFSET ||
     1218       fabs( coory - relCoordinate.y ) > __OFFSET ||
     1219       fabs( coorz - relCoordinate.z ) > __OFFSET )
     1220    flags |= __FLAG_COOR;
     1221
     1222  if ( fabs( rotw - relDirection.w ) > __OFFSET ||
     1223       fabs( rotx - relDirection.v.x ) > __OFFSET ||
     1224       fabs( roty - relDirection.v.y ) > __OFFSET ||
     1225       fabs( rotz - relDirection.v.z ) > __OFFSET )
     1226    flags |= __FLAG_ROT;
     1227
     1228  SYNCHELP_WRITE_BYTE( flags );
     1229  //PRINTF(0)("FLAGS = %d\n", flags);
     1230
     1231  coorx = relCoordinate.x;
     1232  coory = relCoordinate.y;
     1233  coorz = relCoordinate.z;
     1234
     1235
     1236  rotw = relDirection.w;
     1237  rotx = relDirection.v.x;
     1238  roty = relDirection.v.y;
     1239  rotz = relDirection.v.z;
     1240
     1241
     1242  if ( flags & __FLAG_COOR )
     1243  {
     1244
     1245    PRINTF(0)("%f %f %f\n", coorx, coory, coorz);
     1246
     1247    SYNCHELP_WRITE_FLOAT( this->relCoordinate.x );
     1248    SYNCHELP_WRITE_FLOAT( this->relCoordinate.y );
     1249    SYNCHELP_WRITE_FLOAT( this->relCoordinate.z );
     1250  }
     1251
     1252  if ( flags & __FLAG_ROT )
     1253  {
     1254
     1255    PRINTF(0)("%f %f %f %f\n", rotw, rotx, roty, rotz);
     1256
     1257    SYNCHELP_WRITE_FLOAT( this->relDirection.w );
     1258    SYNCHELP_WRITE_FLOAT( this->relDirection.v.x );
     1259    SYNCHELP_WRITE_FLOAT( this->relDirection.v.y );
     1260    SYNCHELP_WRITE_FLOAT( this->relDirection.v.z );
     1261  }
     1262
     1263  return SYNCHELP_WRITE_N;
     1264}
  • branches/network/src/lib/coord/p_node.h

    r6500 r6526  
    185185  int       writeState(const byte* data, int length, int sender);
    186186  int       readState(byte* data, int maxLength );
     187  int       writeSync(const byte* data, int length, int sender);
     188  int       readSync(byte* data, int maxLength );
    187189
    188190 private:
  • branches/network/src/lib/network/network_game_manager.cc

    r6503 r6526  
    130130    }
    131131
     132    if ( b == REQUEST_ENTITY_LIST )
     133    {
     134      sendEntityList( sender );
     135      continue;
     136    }
     137
    132138    if ( b == REQUEST_SYNC )
    133139    {
    134140      if ( !handleRequestSync( i, data, length, sender ) )
    135141        return i;
    136       continue;
    137     }
    138 
    139     if ( b == REQUEST_ENTITY_LIST )
    140     {
    141       sendEntityList( sender );
    142142      continue;
    143143    }
     
    486486
    487487    //HACK: hack to prevent collision
    488     if ( b->isA(CL_WORLD_ENTITY) )
     488    if ( b->isA(CL_WORLD_ENTITY) /*&& !b->isA(CL_PLAYABLE)*/ )
    489489    {
    490490      if ( NetworkManager::getInstance()->getHostID()!=0 )
     
    492492        static Vector pos = Vector(1000.0, 1000.0, 1000.0);
    493493        PNode *p = dynamic_cast<PNode*>(b);
    494         p->setRelCoor(pos);
    495         p->updateNode(0);
     494        p->setAbsCoor(pos);
     495        //p->updateNode(0);
    496496        pos += Vector(1000.0, 1000.0, 1000.0);
    497497      }
     
    599599
    600600  Playable *p = NULL;
     601  Synchronizeable *s = NULL;
    601602
    602603  for ( ; it !=networkStream->getSyncEnd(); it++ )
     
    604605    if ( (*it)->getUniqueID()==uniqueID )
    605606    {
     607      if ( (*it)->isA( CL_SYNCHRONIZEABLE ) )
     608      {
     609        s = dynamic_cast<Synchronizeable*>(*it);
     610      }
    606611      if ( (*it)->isA( CL_PLAYABLE ) )
    607612      {
     
    617622  Player* player = State::getPlayer();
    618623  assert(p != NULL);
     624  assert(s != NULL);
    619625  assert(player != NULL);
     626
     627  s->setIsOutOfSync( true );
     628
     629  PRINTF(0)("uniqueID = %d\n", s->getUniqueID());
    620630
    621631  player->setControllable(p);
     
    874884void NetworkGameManager::sync( int uniqueID, int owner )
    875885{
    876   if ( owner==this->getHostID() )
    877     return;
     886  /*if ( owner==this->getHostID() )
     887  return;*/
    878888
    879889  if ( !isServer() )
  • branches/network/src/lib/network/network_stream.cc

    r6503 r6526  
    311311            if ( (*it)->writeBytes(upBuffer+sizeof(header), dataLength, i) != header.length )
    312312            {
    313               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());
    314314              break;
    315315            }
  • branches/network/src/story_entities/multi_player_world_data.cc

    r6500 r6526  
    263263
    264264
     265  Playable* pl = this->localPlayer->getControllable();
     266  PRINTF(0)("The current regisered playable is hid: %i\n", pl->getUniqueID());
     267
    265268
    266269  PNode* cam = State::getCameraTarget();
  • branches/network/src/world_entities/space_ships/space_ship.cc

    r6503 r6526  
    292292
    293293  //hoover effect
    294   cycle += time;
    295   this->shiftCoor(Vector(0,1,0)*cos(this->cycle*2.0)*0.02);
     294  //cycle += time;
     295  //this->shiftCoor(Vector(0,1,0)*cos(this->cycle*2.0)*0.02);
    296296
    297297  //readjust
     
    531531  SYNCHELP_READ_BYTE( b );
    532532
    533   if ( b == DATA_state && this->getHostID()!=this->getOwner() )
    534   {
     533  if ( b == DATA_state /*&& (this->getHostID()!=this->getOwner() || sender==0)*/ )
     534  {
     535    PRINTF(0)("GOT STATE %d\n", this->getUniqueID());
    535536    setRequestedSync( false );
    536537    setIsOutOfSync( false );
    537538    SYNCHELP_READ_FKT( WorldEntity::writeState );
    538     SYNCHELP_READ_FLOAT( cycle );
    539   }
    540 
    541   return SYNCHELP_READ_N;
    542 
    543   if ( b == DATA_flags && this->getHostID()!=this->getOwner() )
     539    //SYNCHELP_READ_FLOAT( cycle );
     540
     541    return SYNCHELP_READ_N;
     542  }
     543
     544
     545  if ( b == DATA_flags /*&& this->getHostID()!=this->getOwner()*/ )
    544546  {
    545547    int flags;
    546     SYNCHELP_READ_INT( flags );
    547 
    548     bUp = flags & MASK_bUp != 0;
    549     bDown = flags & MASK_bDown != 0;
    550     bLeft = flags & MASK_bLeft != 0;
    551     bRight = flags & MASK_bRight != 0;
    552     bAscend = flags & MASK_bAscend != 0;
    553     bDescend = flags & MASK_bDescend != 0;
    554     bFire = flags & MASK_bFire != 0;
    555     bRollL = flags & MASK_bRollL != 0;
    556     bRollR = flags & MASK_bRollR != 0;
    557   }
    558 
    559   if ( b == DATA_mouse && this->getHostID()!=this->getOwner() )
     548    //SYNCHELP_READ_INT( flags );
     549
     550    bUp = (flags & MASK_bUp) != 0;
     551    bDown = (flags & MASK_bDown) != 0;
     552    bLeft = (flags & MASK_bLeft) != 0;
     553    bRight = (flags & MASK_bRight) != 0;
     554    bAscend = (flags & MASK_bAscend) != 0;
     555    bDescend = (flags & MASK_bDescend) != 0;
     556    bFire = (flags & MASK_bFire) != 0;
     557    bRollL = (flags & MASK_bRollL) != 0;
     558    bRollR = (flags & MASK_bRollR) != 0;
     559
     560  }
     561
     562  /*if ( b == DATA_mouse && this->getHostID()!=this->getOwner() )
    560563  {
    561564    SYNCHELP_READ_FLOAT( xMouse );
     
    563566    SYNCHELP_READ_FLOAT( mouseSensitivity );
    564567    SYNCHELP_READ_FLOAT( cycle );
    565   }
     568}*/
     569
     570  SYNCHELP_READ_FKT( PNode::writeSync );
    566571
    567572  return SYNCHELP_READ_N;
     
    574579  SYNCHELP_WRITE_BEGIN();
    575580
    576   if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
     581  if ( isOutOfSync() && !requestedSync() /*&& this->getHostID()!=this->getOwner()*/ )
    577582  {
    578583    (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
    579584    setRequestedSync( true );
     585    PRINTF(0)("REQUESTED STATE %d\n", this->getUniqueID());
    580586  }
    581587
     
    585591    *reciever = rec;
    586592
     593    PRINTF(0)("SEND STATE %d %d\n", this->getUniqueID(), rec);
     594
    587595    SYNCHELP_WRITE_BYTE( (byte)DATA_state );
    588596
    589597    SYNCHELP_WRITE_FKT( WorldEntity::readState );
    590     SYNCHELP_WRITE_FLOAT( cycle );
     598    //SYNCHELP_WRITE_FLOAT( cycle );
    591599
    592600    return SYNCHELP_WRITE_N;
    593601  }
    594 
    595   return 0;
    596602
    597603  *reciever = 0;
     
    619625
    620626    static int oldMask = mask+1; //so it is different the first time!
    621     static float oldxMouse = xMouse + 1.0;
    622     static float oldyMouse = yMouse + 1.0;
     627    //static float oldxMouse = xMouse + 1.0;
     628    //static float oldyMouse = yMouse + 1.0;
    623629
    624630    if ( mask != oldMask )
     
    626632      oldMask = mask;
    627633      SYNCHELP_WRITE_BYTE( DATA_flags );
    628       SYNCHELP_WRITE_INT( mask );
    629     }
    630 
    631     if ( oldxMouse != xMouse || oldyMouse != yMouse )
     634      //SYNCHELP_WRITE_INT( mask );
     635    }
     636    else
     637    {
     638      SYNCHELP_WRITE_BYTE( 0 );
     639    }
     640
     641    /*if ( oldxMouse != xMouse || oldyMouse != yMouse )
    632642    {
    633643      oldxMouse = xMouse;
     
    638648      SYNCHELP_WRITE_FLOAT( mouseSensitivity );
    639649      SYNCHELP_WRITE_FLOAT( cycle );
    640     }
    641   }
     650    }*/
     651  }
     652  else
     653  {
     654    SYNCHELP_WRITE_BYTE( 0 );
     655  }
     656
     657  SYNCHELP_WRITE_FKT( PNode::readSync );
    642658
    643659  return SYNCHELP_WRITE_N;
Note: See TracChangeset for help on using the changeset viewer.