Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7954 in orxonox.OLD for trunk/src/lib/coord


Ignore:
Timestamp:
May 29, 2006, 3:28:41 PM (19 years ago)
Author:
patrick
Message:

trunk: merged the network branche back to trunk.

Location:
trunk/src/lib/coord
Files:
2 edited

Legend:

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

    r7725 r7954  
    5353  if (parent != NULL)
    5454    parent->addChild(this);
     55
     56  this->relCoordinate_handle = this->registerVarId( new SynchronizeableVector( &relCoordinate, &relCoordinate_write, "coordinate" ) );
     57  this->relDirection_handle = this->registerVarId( new SynchronizeableQuaternion( &relDirection, &relDirection_write, "direction" ) );
    5558}
    5659
     
    10771080
    10781081/**
    1079  * Writes data from network containing information about the state
    1080  * @param data pointer to data
    1081  * @param length length of data
    1082  * @param sender hostID of sender
    1083  */
    1084 int PNode::writeState( const byte * data, int length, int sender )
    1085 {
    1086   SYNCHELP_READ_BEGIN();
    1087 
    1088   SYNCHELP_READ_FKT( BaseObject::writeState, NWT_PN_BO_WRITESTATE );
    1089 
    1090   //   char * parentName = NULL;
    1091   //   SYNCHELP_READ_STRINGM( parentName );
    1092   //
    1093   //   if ( strcmp(parentName, "")==0 )
    1094   //   {
    1095   //     setParent( (char*)NULL );
    1096   //   }
    1097   //   else
    1098   //   {
    1099   //     setParent( parentName );
    1100   //   }
    1101   //
    1102   //  delete[] parentName;
    1103 
    1104   int parentMode;
    1105   SYNCHELP_READ_INT( parentMode, NWT_PN_PARENTMODE );
    1106   this->setParentMode((PARENT_MODE)parentMode);
    1107 
    1108   float f1, f2, f3, f4;
    1109 
    1110   SYNCHELP_READ_FLOAT( f1, NWT_PN_COORX );
    1111   SYNCHELP_READ_FLOAT( f2, NWT_PN_COORY );
    1112   SYNCHELP_READ_FLOAT( f3, NWT_PN_COORZ );
    1113   this->setRelCoor( f1, f2, f3 );
    1114 
    1115 
    1116   SYNCHELP_READ_FLOAT( f1, NWT_PN_ROTV );
    1117   SYNCHELP_READ_FLOAT( f2, NWT_PN_ROTX );
    1118   SYNCHELP_READ_FLOAT( f3, NWT_PN_ROTY );
    1119   SYNCHELP_READ_FLOAT( f4, NWT_PN_ROTZ );
    1120   this->setRelDir( Quaternion( Vector(f2, f3, f4), f1 ) );
    1121 
    1122   //   int n;
    1123   //   char * childName;
    1124   //
    1125   //   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]);
    1126   //   SYNCHELP_READ_INT( n );
    1127   //   PRINTF(0)("read %s:n=%d\n", this->getName(), n);
    1128   //
    1129   //   for (int i = 0; i<n; i++)
    1130   //   {
    1131   //     SYNCHELP_READ_STRINGM( childName );
    1132   //     PRINTF(0)("RCVD CHILD = %s\n", childName);
    1133   //     addChild( childName );
    1134   //     delete childName;
    1135   //     childName = NULL;
    1136   //   }
    1137 
    1138   return SYNCHELP_READ_N;
    1139 }
    1140 
    1141 /**
    1142  * data copied in data will bee sent to another host
    1143  * @param data pointer to data
    1144  * @param maxLength max length of data
    1145  * @return the number of bytes writen
    1146  */
    1147 int PNode::readState( byte * data, int maxLength )
    1148 {
    1149   SYNCHELP_WRITE_BEGIN();
    1150 
    1151   SYNCHELP_WRITE_FKT( BaseObject::readState, NWT_PN_BO_WRITESTATE );
    1152 
    1153   //   if ( this->parent )
    1154   //   {
    1155   //     SYNCHELP_WRITE_STRING( parent->getName() );
    1156   //   }
    1157   //   else
    1158   //   {
    1159   //     SYNCHELP_WRITE_STRING( "" );
    1160   //   }
    1161 
    1162   SYNCHELP_WRITE_INT( this->parentMode, NWT_PN_PARENTMODE );
    1163 
    1164   SYNCHELP_WRITE_FLOAT( this->relCoordinate.x, NWT_PN_COORX );
    1165   SYNCHELP_WRITE_FLOAT( this->relCoordinate.y, NWT_PN_COORY );
    1166   SYNCHELP_WRITE_FLOAT( this->relCoordinate.z, NWT_PN_COORZ );
    1167 
    1168   SYNCHELP_WRITE_FLOAT( this->relDirection.w, NWT_PN_ROTV );
    1169   SYNCHELP_WRITE_FLOAT( this->relDirection.v.x, NWT_PN_ROTX );
    1170   SYNCHELP_WRITE_FLOAT( this->relDirection.v.y, NWT_PN_ROTY );
    1171   SYNCHELP_WRITE_FLOAT( this->relDirection.v.z, NWT_PN_ROTZ );
    1172 
    1173   //   int n = children.size();
    1174   //   //check if camera is in children
    1175   //   for (std::std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++)
    1176   //   {
    1177   //     if ( (*it)->isA(CL_CAMERA) )
    1178   //       n--;
    1179   //   }
    1180   //   PRINTF(0)("write %s:n=%d\n", this->getName(), n);
    1181   //   SYNCHELP_WRITE_INT( n );
    1182   //   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]);
    1183   //
    1184   //
    1185   //   for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++)
    1186   //   {
    1187   //     //dont add camera because there is only one camera attached to local player
    1188   //     if ( !(*it)->isA(CL_CAMERA) )
    1189   //     {
    1190   //       PRINTF(0)("SENDING CHILD: %s\n", (*it)->getName());
    1191   //       SYNCHELP_WRITE_STRING( (*it)->getName() );
    1192   //     }
    1193   //   }
    1194 
    1195   return SYNCHELP_WRITE_N;
    1196 }
    1197 
    1198 #define __FLAG_COOR 1
    1199 #define __FLAG_ROT  2
    1200 
    1201 #define __OFFSET_POS 1
    1202 #define __OFFSET_ROT 0.05
    1203 
    1204 /**
    1205  * Writes data from network containing information about the state which has changed
    1206  * @param data pointer to data
    1207  * @param length length of data
    1208  * @param sender hostID of sender
    1209  */
    1210 int PNode::writeSync( const byte * data, int length, int sender )
    1211 {
    1212   SYNCHELP_READ_BEGIN();
    1213 
    1214   if ( this->getHostID()==this->getOwner() )
    1215   {
    1216     return SYNCHELP_READ_N;
    1217   }
    1218 
    1219   byte flags = 0;
    1220   SYNCHELP_READ_BYTE( flags, NWT_PN_FLAGS );
    1221   //PRINTF(0)("%s::FLAGS = %d\n", this->getName(), flags);
    1222 
    1223   float f1, f2, f3, f4;
    1224 
    1225   if ( flags & __FLAG_COOR )
    1226   {
    1227     SYNCHELP_READ_FLOAT( f1, NWT_PN_SCOORX );
    1228     SYNCHELP_READ_FLOAT( f2, NWT_PN_SCOORY );
    1229     SYNCHELP_READ_FLOAT( f3, NWT_PN_SCOORZ );
    1230     PRINTF(0)("RCVD COOR: %f %f %f\n", f1, f2, f3);
    1231     this->setRelCoor( f1, f2, f3 );
    1232   }
    1233 
    1234   if ( flags & __FLAG_ROT )
    1235   {
    1236     SYNCHELP_READ_FLOAT( f1, NWT_PN_SROTV );
    1237     SYNCHELP_READ_FLOAT( f2, NWT_PN_SROTX );
    1238     SYNCHELP_READ_FLOAT( f3, NWT_PN_SROTY );
    1239     SYNCHELP_READ_FLOAT( f4, NWT_PN_SROTZ );
    1240     PRINTF(0)("RCVD QUAT: %f %f %f %f\n", f1, f2, f3, f4);
    1241     //this->setRelDir( Quaternion( Vector(f2, f3, f4), f1 ) );
    1242     Quaternion q;
    1243     q.w = f1;
    1244     q.v.x = f2;
    1245     q.v.y = f3;
    1246     q.v.z = f4;
    1247     this->setAbsDir( q );
    1248   }
    1249 
    1250   return SYNCHELP_READ_N;
    1251 }
    1252 
    1253 /**
    1254  * data copied in data will bee sent to another host
    1255  * @param data pointer to data
    1256  * @param maxLength max length of data
    1257  * @return the number of bytes writen
    1258  */
    1259 int PNode::readSync( byte * data, int maxLength )
    1260 {
    1261   //WARNING: if you change this file make sure you also change needsReadSync
    1262   SYNCHELP_WRITE_BEGIN();
    1263 
    1264   if ( this->getHostID()!=0 && this->getHostID()!=this->getOwner() )
    1265   {
    1266     return SYNCHELP_WRITE_N;
    1267   }
    1268 
    1269   byte flags = 0;
    1270   if ( fabs( coorx - relCoordinate.x ) > __OFFSET_POS*0.05*this->velocity.len() ||
    1271        fabs( coory - relCoordinate.y ) > __OFFSET_POS*0.05*this->velocity.len() ||
    1272        fabs( coorz - relCoordinate.z ) > __OFFSET_POS*0.05*this->velocity.len() )
    1273     flags |= __FLAG_COOR;
    1274 
    1275   if ( fabs( rotw - absDirection.w ) > __OFFSET_ROT ||
    1276        fabs( rotx - absDirection.v.x ) > __OFFSET_ROT ||
    1277        fabs( roty - absDirection.v.y ) > __OFFSET_ROT ||
    1278        fabs( rotz - absDirection.v.z ) > __OFFSET_ROT )
    1279     flags |= __FLAG_ROT;
    1280 
    1281 
    1282   SYNCHELP_WRITE_BYTE( flags, NWT_PN_FLAGS );
    1283   PRINTF(0)("FLAGS = %d\n", flags);
    1284 
    1285   if ( flags & __FLAG_COOR )
    1286   {
    1287 
    1288     PRINTF(0)("SEND COOR: %f %f %f\n", this->relCoordinate.x, this->relCoordinate.y, this->relCoordinate.z);
    1289 
    1290     SYNCHELP_WRITE_FLOAT( this->relCoordinate.x, NWT_PN_SCOORX );
    1291     SYNCHELP_WRITE_FLOAT( this->relCoordinate.y, NWT_PN_SCOORY );
    1292     SYNCHELP_WRITE_FLOAT( this->relCoordinate.z, NWT_PN_SCOORZ );
    1293 
    1294     coorx = relCoordinate.x;
    1295     coory = relCoordinate.y;
    1296     coorz = relCoordinate.z;
    1297   }
    1298 
    1299   if ( flags & __FLAG_ROT )
    1300   {
    1301 
    1302     PRINTF(0)("SEND QUAT: %f %f %f %f\n", this->absDirection.w, this->absDirection.v.x, this->absDirection.v.y, this->absDirection.v.z);
    1303 
    1304     SYNCHELP_WRITE_FLOAT( this->absDirection.w, NWT_PN_SROTV );
    1305     SYNCHELP_WRITE_FLOAT( this->absDirection.v.x, NWT_PN_SROTX );
    1306     SYNCHELP_WRITE_FLOAT( this->absDirection.v.y, NWT_PN_SROTY );
    1307     SYNCHELP_WRITE_FLOAT( this->absDirection.v.z, NWT_PN_SROTZ );
    1308 
    1309     rotw = absDirection.w;
    1310     rotx = absDirection.v.x;
    1311     roty = absDirection.v.y;
    1312     rotz = absDirection.v.z;
    1313   }
    1314 
    1315   return SYNCHELP_WRITE_N;
    1316 }
    1317 
    1318 bool PNode::needsReadSync( )
    1319 {
    1320   if ( fabs( coorx - relCoordinate.x ) > __OFFSET_POS*0.05*this->velocity.len() ||
    1321        fabs( coory - relCoordinate.y ) > __OFFSET_POS*0.05*this->velocity.len() ||
    1322        fabs( coorz - relCoordinate.z ) > __OFFSET_POS*0.05*this->velocity.len() )
    1323     return true;
    1324 
    1325   if ( fabs( rotw - absDirection.w ) > __OFFSET_ROT ||
    1326        fabs( rotx - absDirection.v.x ) > __OFFSET_ROT ||
    1327        fabs( roty - absDirection.v.y ) > __OFFSET_ROT ||
    1328        fabs( rotz - absDirection.v.z ) > __OFFSET_ROT )
    1329     return true;
    1330 
    1331   return false;
    1332 }
     1082 * handles changes in synchronizable variables
     1083 * @param id id's which changed
     1084 */
     1085void PNode::varChangeHandler( std::list< int > & id )
     1086{
     1087  if ( std::find( id.begin(), id.end(), relCoordinate_handle ) != id.end() )
     1088  {
     1089    setRelCoor( relCoordinate_write );
     1090  }
     1091
     1092  if ( std::find( id.begin(), id.end(), relDirection_handle ) != id.end() )
     1093  {
     1094    setRelDir( relDirection_write );
     1095  }
     1096}
     1097
     1098
  • trunk/src/lib/coord/p_node.h

    r7725 r7954  
    186186  float distance(const PNode* node) const { return (this->getAbsCoor() - node->getAbsCoor()).len(); };
    187187
    188   int       writeState(const byte* data, int length, int sender);
    189   int       readState(byte* data, int maxLength );
    190   int       writeSync(const byte* data, int length, int sender);
    191   int       readSync(byte* data, int maxLength );
    192   bool      needsReadSync();
    193 
    194188 private:
    195189  /** tells the child that the parent's Coordinate has changed */
     
    243237    float roty;
    244238    float rotz;
     239   
     240  private:
     241    int relCoordinate_handle;
     242    int relDirection_handle;
     243    Vector relCoordinate_write;
     244    Quaternion relDirection_write;
     245   
     246  public:
     247    virtual void varChangeHandler( std::list<int> & id );
    245248};
    246249
Note: See TracChangeset for help on using the changeset viewer.