Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6526 in orxonox.OLD for branches/network/src/lib/coord/p_node.cc


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

pnode can sync now

File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.