Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7444 in orxonox.OLD for branches/network/src/lib/coord


Ignore:
Timestamp:
Apr 29, 2006, 1:57:48 PM (19 years ago)
Author:
rennerc
Message:

new network system implemented. yet with a lot of empty function bodys

Location:
branches/network/src/lib/coord
Files:
2 edited

Legend:

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

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

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