Example #1
0
void CFellow::UpdateFellow(CFellow *pCFellow)
{
    char                                fellowName[256] = {'\0'};
    RTI::ULong                          fellowColor     = 0;
    RTI::ULong                          fellowPortrait  = 0;
    RTI::AttributeHandleValuePairSet    *theAttrs = NULL;

    try
    {
        theAttrs = RTI::AttributeSetFactory::create(3);
        if (pCFellow->GetFellowNameUpdate())
        {
            strcpy(fellowName, pCFellow->GetFellowName());
            theAttrs->add(pCFellow->GetFellowNameRtiId(), (char*)fellowName,
                sizeof(fellowName));
            pCFellow->SetFellowNameUpdate(RTI::RTI_FALSE);
        }
        if (pCFellow->GetFellowColorUpdate())
        {
            fellowColor = pCFellow->GetFellowColor();
            theAttrs->add(pCFellow->GetFellowColorRtiId(), (char*)&fellowColor,
                sizeof(fellowColor));
            pCFellow->SetFellowColorUpdate(RTI::RTI_FALSE);
        }
        if (pCFellow->GetFellowPortraitUpdate())
        {
            fellowPortrait = pCFellow->GetFellowPortrait();
            theAttrs->add(pCFellow->GetFellowPortraitRtiId(), (char*)&fellowPortrait,
                sizeof(fellowPortrait));
            pCFellow->SetFellowPortraitUpdate(RTI::RTI_FALSE);
        }
        if (theAttrs->size())
        {
            ms_rtiAmb->updateAttributeValues(pCFellow->GetInstanceId(),
                *theAttrs, "FellowUpdate");
            //ms_rtiAmb->tick(0.1, 2.0);
        }
        if (theAttrs)
        {
            theAttrs->empty();
            delete theAttrs;
        }
    }
    catch (RTI::Exception& e)
    {
        AfxMessageBox((CString)e._name);
    }
}
Example #2
0
//-----------------------------------------------------------------
//
// METHOD:
//     void Country::Update( const AttributeHandleValuePairSet& theAttributes )
//
// PURPOSE:
//     Update the new attribute values.  If this is being called
//     then this object is either a remote object that was
//     discovered or it has some attributes that are owned by
//     another federate.
//
//     Note: This version does not implement any ownership
//           transfer - the above was a generic statement.
//
// RETURN VALUES:
//     None. 
//
// HISTORY:
//     1) Created 11/6/96
//     2) Updated to RTI 1.3 3/26/98
//
//-----------------------------------------------------------------
void Country::Update( const RTI::AttributeHandleValuePairSet& theAttributes )
{
   RTI::AttributeHandle attrHandle;
   RTI::ULong           valueLength;

   // We need to iterate through the AttributeHandleValuePairSet
   // to extract each AttributeHandleValuePair.  Based on the type
   // specified ( the value returned by getHandle() ) we need to
   // extract the data from the buffer that is returned by 
   // getValue().
   for ( unsigned int i = 0; i < theAttributes.size(); i++ )
   {
      attrHandle = theAttributes.getHandle( i );

      if ( attrHandle == Country::GetPopulationRtiId() )
      {
         // When we run this over multiple platforms we will have
         // a problem with different endian-ness of platforms. Either
         // we need to encode the data using something like XDR or
         // provide another mechanism.
         double population;
         theAttributes.getValue( i, (char*)&population, valueLength );

#if defined(_X86_) || defined(i386)
         long x = ntohl(*(long*)&population);
         *(long*)&population = ntohl(* (((long*)&population) + 1));
         *(((long*)&population)+1) = x;
#elif defined(__alpha)
         double x;
         cvt_ftof(&population, CVT_IEEE_T, &x, CVT_BIG_ENDIAN_IEEE_T, 0);
         population = x;
#endif  // __alpha

         SetPopulation( (double)population );
      }
      else if ( attrHandle == Country::GetNameRtiId() )
      {
        // Same as above goes here...
         char name[ 1024 ];
         theAttributes.getValue( i, (char*)name, valueLength );
         SetName( (const char*)name );
      }
   }
}
//------------------------------------------------------------------------------
// reflectAttributeValues() -- (Input support)
//  Called by our FederateAmbassador to update the attribute values for
//  this object instance.  (Also handles the network to host byte swapping)
//------------------------------------------------------------------------------
void Nib::reflectAttributeValues(const RTI::AttributeHandleValuePairSet& theAttrs)
{
   NetIO* netIO = static_cast<NetIO*>(getNetIO());
   if (netIO != nullptr && baseEntity != nullptr) {

      // PhysicalEntity pointer
      PhysicalEntity* physicalEntity = dynamic_cast<PhysicalEntity*>(baseEntity);

      RTI::ULong length;
      char netBuffer[1000];
      for (RTI::ULong j = 0; j < theAttrs.size(); j++ ) {

         // get the attribute's handle and data (network byte order)
         RTI::AttributeHandle theAttr = theAttrs.getHandle(j);
         theAttrs.getValue(j, netBuffer, length);

         // Process the attribute
         switch ( netIO->findAttributeIndex(theAttr) ) {

            // Update Federate ID
            case NetIO::ENTITY_IDENTIFIER_AI : {
               EntityIdentifierStruct* net = reinterpret_cast<EntityIdentifierStruct*>(&netBuffer);

               base::NetHandler::fromNetOrder(&baseEntity->entityIdentifier.federateIdentifier.applicationID, net->federateIdentifier.applicationID );
               base::NetHandler::fromNetOrder(&baseEntity->entityIdentifier.federateIdentifier.siteID, net->federateIdentifier.siteID );
               base::NetHandler::fromNetOrder(&baseEntity->entityIdentifier.entityNumber, net->entityNumber );

               setAttributeUpdateRequiredFlag(NetIO::ENTITY_IDENTIFIER_AI, true);
            }
            break;

            // Update Entity Type
            case NetIO::ENTITY_TYPE_AI : {
               EntityTypeStruct* net = reinterpret_cast<EntityTypeStruct*>(&netBuffer);

               // All bytes except for country
               baseEntity->entityType = *net;
               base::NetHandler::fromNetOrder(&baseEntity->entityType.countryCode, net->countryCode );

               setAttributeUpdateRequiredFlag(NetIO::ENTITY_TYPE_AI, true);
            }
            break;

            // Update Spatial
            case NetIO::SPATIAL_AI : {

               // NIB's base entity structure pointers
               SpatialStruct* spatial = &(baseEntity->spatial);
               SpatialRVStruct* spatialRvw = &(baseEntity->spatialRvw);
               WorldLocationStruct* worldLocation = &spatialRvw->worldLocation;
               OrientationStruct* orientation = &spatialRvw->orientation;
               VelocityVectorStruct* velocityVector = &spatialRvw->velocityVector;
               AccelerationVectorStruct* accelerationVector = &spatialRvw->accelerationVector;
               AngularVelocityVectorStruct* angularVelocity = &spatialRvw->angularVelocity;

               // Net buffer component pointers 
               SpatialStruct* netSpatial = reinterpret_cast<SpatialStruct*>(&netBuffer[0]);
               WorldLocationStruct* netWorldLocation = nullptr;
               OrientationStruct* netOrientation = nullptr;
               VelocityVectorStruct* netVelocityVector = nullptr;
               AccelerationVectorStruct* netAccelerationVector = nullptr;
               AngularVelocityVectorStruct* netAngularVelocity = nullptr;

               // Dead reckoning 
               spatial->deadReckoningAlgorithm = netSpatial->deadReckoningAlgorithm;

               // find network components based on dead reckoning algorithm
               // (and set the isFrozen flag)
               switch (spatial->deadReckoningAlgorithm) {

                  case DRM_STATIC : {
                     SpatialStaticStruct* netSpatialStatic = reinterpret_cast<SpatialStaticStruct*>(&netBuffer[sizeof(SpatialStruct)]);
                     spatialRvw->isFrozen = netSpatialStatic->isFrozen;
                     netWorldLocation = &netSpatialStatic->worldLocation;
                     netOrientation = &netSpatialStatic->orientation;
                  }
                  break;

                  case DRM_FPW : {
                     SpatialFPStruct* netSpatialFpw = reinterpret_cast<SpatialFPStruct*>(&netBuffer[sizeof(SpatialStruct)]);
                     spatialRvw->isFrozen = netSpatialFpw->isFrozen;
                     netWorldLocation = &netSpatialFpw->worldLocation;
                     netOrientation = &netSpatialFpw->orientation;
                     netVelocityVector = &netSpatialFpw->velocityVector;
                  }
                  break;

                  case DRM_RPW : {
                     SpatialRPStruct* netSpatialRpw = reinterpret_cast<SpatialRPStruct*>(&netBuffer[sizeof(SpatialStruct)]);
                     spatialRvw->isFrozen = netSpatialRpw->isFrozen;
                     netWorldLocation = &netSpatialRpw->worldLocation;
                     netOrientation = &netSpatialRpw->orientation;
                     netVelocityVector = &netSpatialRpw->velocityVector;
                     netAngularVelocity = &netSpatialRpw->angularVelocity;
                  }
                  break;

                  case DRM_RVW : {
                     SpatialRVStruct* netSpatialRvw = reinterpret_cast<SpatialRVStruct*>(&netBuffer[sizeof(SpatialStruct)]);
                     spatialRvw->isFrozen = netSpatialRvw->isFrozen;
                     netWorldLocation = &netSpatialRvw->worldLocation;
                     netOrientation = &netSpatialRvw->orientation;
                     netVelocityVector = &netSpatialRvw->velocityVector;
                     netAccelerationVector = &netSpatialRvw->accelerationVector;
                     netAngularVelocity = &netSpatialRvw->angularVelocity;
                  }
                  break;

                  case DRM_FVW : {
                     SpatialFVStruct* netSpatialFvw = reinterpret_cast<SpatialFVStruct*>(&netBuffer[sizeof(SpatialStruct)]);
                     spatialRvw->isFrozen = netSpatialFvw->isFrozen;
                     netWorldLocation = &netSpatialFvw->worldLocation;
                     netOrientation = &netSpatialFvw->orientation;
                     netVelocityVector = &netSpatialFvw->velocityVector;
                     netAccelerationVector = &netSpatialFvw->accelerationVector;
                  }
                  break;
               }  // end dead rec switch

               if (netWorldLocation != nullptr) {
                  base::NetHandler::fromNetOrder(&worldLocation->x, netWorldLocation->x);
                  base::NetHandler::fromNetOrder(&worldLocation->y, netWorldLocation->y);
                  base::NetHandler::fromNetOrder(&worldLocation->z, netWorldLocation->z);
               }
               else {
                  worldLocation->x = 0;
                  worldLocation->y = 0;
                  worldLocation->z = 0;
               }

               if (netOrientation != nullptr) {
                  base::NetHandler::fromNetOrder(&orientation->phi, netOrientation->phi);
                  base::NetHandler::fromNetOrder(&orientation->theta, netOrientation->theta);
                  base::NetHandler::fromNetOrder(&orientation->psi, netOrientation->psi);
               }
               else {
                  orientation->phi = 0;
                  orientation->theta = 0;
                  orientation->psi = 0;
               }

               if (netVelocityVector != nullptr) {
                  base::NetHandler::fromNetOrder(&velocityVector->xVelocity, netVelocityVector->xVelocity);
                  base::NetHandler::fromNetOrder(&velocityVector->yVelocity, netVelocityVector->yVelocity);
                  base::NetHandler::fromNetOrder(&velocityVector->zVelocity, netVelocityVector->zVelocity);
               }
               else {
                  velocityVector->xVelocity = 0;
                  velocityVector->yVelocity = 0;
                  velocityVector->zVelocity = 0;
               }

               if (netAccelerationVector != nullptr) {
                  base::NetHandler::fromNetOrder(&accelerationVector->xAcceleration, netAccelerationVector->xAcceleration);
                  base::NetHandler::fromNetOrder(&accelerationVector->yAcceleration, netAccelerationVector->yAcceleration);
                  base::NetHandler::fromNetOrder(&accelerationVector->zAcceleration, netAccelerationVector->zAcceleration);
               }
               else {
                  accelerationVector->xAcceleration = 0;
                  accelerationVector->yAcceleration = 0;
                  accelerationVector->zAcceleration = 0;
               }

               if (netAngularVelocity != nullptr) {
                  base::NetHandler::fromNetOrder(&angularVelocity->xAngularVelocity, netAngularVelocity->xAngularVelocity);
                  base::NetHandler::fromNetOrder(&angularVelocity->yAngularVelocity, netAngularVelocity->yAngularVelocity);
                  base::NetHandler::fromNetOrder(&angularVelocity->zAngularVelocity, netAngularVelocity->zAngularVelocity);
               }
               else {
                  angularVelocity->xAngularVelocity = 0;
                  angularVelocity->yAngularVelocity = 0;
                  angularVelocity->zAngularVelocity = 0;
               }

               setAttributeUpdateRequiredFlag(NetIO::SPATIAL_AI, true);
            }
            break;

            case NetIO::FORCE_IDENTIFIER_AI : {
               unsigned char* net = reinterpret_cast<unsigned char*>(&netBuffer);
               physicalEntity->forceIdentifier = ForceIdentifierEnum8( *net );
               //std::cout << "Recv force: " << physicalEntity->forceIdentifier << std::endl;;
               setAttributeUpdateRequiredFlag(NetIO::FORCE_IDENTIFIER_AI, true);
            }
            break;

         } // end -- process attribute switch
      } // end -- for each attribute pair

      // Update the basic NIB state data with this new data
      entityState2Nib();
   }
}