示例#1
0
void
Master_FA::receiveInteraction (
	RTI::InteractionClassHandle theInteraction,
	const RTI::ParameterHandleValuePairSet & theParameters,
	const RTI::FedTime & theTime,
	const char * theTag,
	RTI::EventRetractionHandle theHandle)
	throw (
		RTI::InteractionClassNotKnown,
		RTI::InteractionParameterNotKnown,
		RTI::InvalidFederationTime,
		RTI::FederateInternalError)
	{
	RTIfedTime fed_time(theTime);
	cout << "Incoming interaction at time " << fed_time.getTime() << endl;
	if (theInteraction != reply_handle)
		{
		cerr << "Received unknown interaction " << theInteraction << endl;
		return;
		}
	if (theParameters.size() != 3)
		{
		cerr << "Unexpected number of parameters " 
			 << theParameters.size() << endl;
		return;
		}

	// extract values
	RTI::ULong	id;
	RTI::Double	change_lat;
	RTI::Double	change_long;
	unsigned long length;
	RTI::ParameterHandle handle;
    char buffer [20];

	for (unsigned long i = 0; i < 3; i++)
		{
		handle = theParameters.getHandle (i);
		if (handle == reply_parameters [Id])
			{
			theParameters.getValue (i, buffer, length);
			Sim_Hla_Istream is (buffer, length);
			is >> id;
			}
		else if (handle == reply_parameters [ChangeLat])
示例#2
0
//-----------------------------------------------------------------
//
// METHOD:
//     void Country::Update( RTI::InteractionClassHandle theInteraction,
//                    const RTI::ParameterHandleValuePairSet& theParameters )
//
// PURPOSE:
//     Process an interaction.
//
// RETURN VALUES:
//     None. 
//
// HISTORY:
//     1) Created 11/6/96
//     2) Updated to RTI 1.3 3/26/98
//
//-----------------------------------------------------------------
void Country::Update( RTI::InteractionClassHandle theInteraction,
             const RTI::ParameterHandleValuePairSet& theParameters )
{
   if ( theInteraction == Country::GetCommRtiId() )
   {
      RTI::ParameterHandle paramHandle;
      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 frlom the buffer that is returned by 
      // getValue().
      for ( unsigned int i = 0; i < theParameters.size(); i++ )
      {
         paramHandle = theParameters.getHandle( i );
         if ( paramHandle == Country::GetMessageRtiId() )
         {
            // 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.
            char msg[ 1024 ];
            theParameters.getValue( i, (char*)msg, valueLength );
            cout << "FED_HW: Interaction Received: " << msg << endl;
         }
         else
         {
            // There must be an error since there should only be
            // one parameter to Communication.
            cerr << "FED_HW: Error: I seem to have received a parameter for "
                 << "interaction class Communication that I don't "
                 << "know about." << endl;
         }
      }
   }
   else
   {
      cerr << "FED_HW: Recieved an interaction class I don't know about." << endl;   
   }
}
示例#3
0
文件: hla_FedAmb.cpp 项目: LXiong/ccn
bool
HlaFedAmb::ReadDataIxnParameters(
    const RTI::ParameterHandleValuePairSet& theParameters,
    HlaDataIxnInfo& dataIxnInfo)
{
    HlaVariableDatumSetInfo& vdsInfo = dataIxnInfo.variableDatumSetInfo;

    unsigned i;
    for (i = 0; i < theParameters.size(); i++)
    {
        RTI::ParameterHandle ph = theParameters.getHandle(i);
        RTI::ULong size = theParameters.getValueLength(i);

        if (ph == m_dataOriginatingEntityHandle)
        {
            // Not used.
        }
        else
        if (ph == m_dataReceivingEntityHandle)
        {
            // Not used.
        }
        else
        if (ph == m_dataRequestIdentifierHandle)
        {
            // Not used.
        }
        else
        if (ph == m_dataFixedDatumsHandle)
        {
            // Not used.
        }
        else
        if (ph == m_dataVariableDatumSetHandle)
        {
            if (size > g_hlaVariableDatumSetBufSize)
            {
                if (m_debug)
                {
                    cout << "FED: Ignoring Data interaction containing"
                            " large VariableDatumSet parameter" << endl;
                }

                return false;
            }

            char variableDatumSet[g_hlaVariableDatumSetBufSize];
            theParameters.getValue(i, variableDatumSet, size);

            // NumberOfVariableDatums, DatumID, DatumLength.
            // Converted to host-byte-order.

            unsigned vdsOffset = 0;

            HlaCopyFromOffsetAndNtoh(
                &vdsInfo.numberOfVariableDatums,
                variableDatumSet,
                vdsOffset,
                sizeof(vdsInfo.numberOfVariableDatums));

            if (vdsInfo.numberOfVariableDatums != 1)
            {
                if (m_debug)
                {
                    cout << "FED: Ignoring Data interaction where"
                            " NumberOfVariableDatums != 1" << endl;
                }

                return false;
            }

            HlaVariableDatumInfo& vdInfo = vdsInfo.variableDatumsInfo[0];

            HlaCopyFromOffsetAndNtoh(
                &vdInfo.datumId,
                variableDatumSet,
                vdsOffset,
                sizeof(vdInfo.datumId));

            HlaCopyFromOffsetAndNtoh(
                &vdInfo.datumLength,
                variableDatumSet,
                vdsOffset,
                sizeof(vdInfo.datumLength));

            if (vdInfo.datumLength % 8 != 0)
            {
                if (m_debug)
                {
                    cout << "FED: Ignoring Data interaction where"
                            " DatumLength is not a multiple of 8" << endl;
                }

                return false;
            }

            unsigned datumLengthInBytes = vdInfo.datumLength / 8;

            if (datumLengthInBytes > g_hlaDatumValueBufSize)
            {
                if (m_debug)
                {
                    cout << "FED: Ignoring Data interaction containing"
                            " large DatumValue field" << endl;
                }

                return false;
            }

            // DatumValue.
            // Left in network-byte-order.

            HlaCopyFromOffset(
                vdInfo.datumValue,
                variableDatumSet,
                vdsOffset,
                datumLengthInBytes);
        }
        else
        {
            HlaReportError("Unknown parameter handle", __FILE__, __LINE__);
        }
    }//for//

    return true;
}
示例#4
0
//------------------------------------------------------------------------------
// receiveMunitionDetonation() -- (Input) handles the Munition Detonation interaction
//------------------------------------------------------------------------------
bool NetIO::receiveMunitionDetonation(const RTI::ParameterHandleValuePairSet& theParameters)
{
    // Things we need
    RTIObjectIdStruct firingObjectIdentifier;
    RTIObjectIdStruct munitionObjectIdentifier;
    RTIObjectIdStruct targetObjectIdentifier;
    simulation::Weapon::Detonation detonationResult = simulation::Weapon::DETONATE_NONE;

    // ---
    // Extract the required data from the interaction's parameters
    // ---
    RTI::ULong length;
    char netBuffer[1000];
    for (RTI::ULong i = 0 ; i < theParameters.size(); i++ ) {
        
        // get the parameter's handed and data (network byte order)
        RTI::ParameterHandle theHandle = theParameters.getHandle(i);
        theParameters.getValue(i, netBuffer, length);

        // Process the parameter
        switch ( findParameterIndex(theHandle) ) {

        case DETONATION_RESULT_CODE_MD_PI : {

            switch ( DetonationResultCodeEnum8( netBuffer[0] ) ) {
                case DetonationResultCodeOther :
                    detonationResult = simulation::Weapon::DETONATE_OTHER;
                    break;
                case EntityImpact :
                    detonationResult = simulation::Weapon::DETONATE_ENTITY_IMPACT;
                    break;
                case EntityProximateDetonation :
                    detonationResult = simulation::Weapon::DETONATE_ENTITY_PROXIMATE_DETONATION;
                    break;
                case GroundImpact :
                    detonationResult = simulation::Weapon::DETONATE_GROUND_IMPACT;
                    break;
                case GroundProximateDetonation :
                    detonationResult = simulation::Weapon::DETONATE_GROUND_PROXIMATE_DETONATION;
                    break;
                case Detonation :
                    detonationResult = simulation::Weapon::DETONATE_DETONATION;
                    break;
                case None :
                    detonationResult = simulation::Weapon::DETONATE_NONE;
                    break;
                default :
                    detonationResult = simulation::Weapon::DETONATE_OTHER;
                    break;
            };
        }
        break;
        
        case FIRING_OBJECT_IDENTIFIER_MD_PI : {
            // Get the object's name
            RTI::ULong n = RTIObjectIdStruct::ID_SIZE;
            if (n > length) n = length;
            base::utStrncpy(reinterpret_cast<char*>(&firingObjectIdentifier.id[0]), sizeof(firingObjectIdentifier.id), netBuffer, n);
            firingObjectIdentifier.id[n-1] = '\0';   
        }
        break;
        
        case MUNITION_OBJECT_IDENTIFIER_MD_PI : {
            // Get the object's name
            RTI::ULong n = RTIObjectIdStruct::ID_SIZE;
            if (n > length) n = length;
            base::utStrncpy(reinterpret_cast<char*>(&munitionObjectIdentifier.id[0]), sizeof(munitionObjectIdentifier.id), netBuffer, n);
            munitionObjectIdentifier.id[n-1] = '\0';   
        }
        break;
        
        case TARGET_OBJECT_IDENTIFIER_MD_PI : {
            // Get the object's name
            RTI::ULong n = RTIObjectIdStruct::ID_SIZE;
            if (n > length) n = length;
            base::utStrncpy(reinterpret_cast<char*>(&targetObjectIdentifier.id[0]), sizeof(targetObjectIdentifier.id), netBuffer, n);
            targetObjectIdentifier.id[n-1] = '\0';   
        }
        break;
                        
        }
    }
    std::cout << "RprFom::Nib::receiveMunitionDetonation() fired(" << firingObjectIdentifier.id << ")"  << std::endl;
  
    // ---
    // 1) Find the target (local) player
    // ---
    simulation::Player* tPlayer = nullptr;
    if ( std::strlen(reinterpret_cast<const char*>(targetObjectIdentifier.id)) > 0 ) {
        simulation::Nib* tNib = findNibByObjectName( reinterpret_cast<char*>(targetObjectIdentifier.id), OUTPUT_NIB);
        if (tNib != nullptr) tPlayer = tNib->getPlayer();
    }
    
    // ---
    // Note: we're only interested (at this time) with our local players being hit
    // by other networked IPlayers.
    // ---
    if (tPlayer != nullptr) {
        
        // ---
        // 2) Find the firing player and munitions (networked) IPlayers
        // ---
        simulation::Nib* fNib = nullptr;
        simulation::Nib* mNib = nullptr;
        if ( std::strlen(reinterpret_cast<const char*>(firingObjectIdentifier.id)) > 0 ) {
            fNib = findNibByObjectName( reinterpret_cast<char*>(firingObjectIdentifier.id), INPUT_NIB);
        }
        if ( std::strlen(reinterpret_cast<const char*>(munitionObjectIdentifier.id)) > 0 ) {
            mNib = findNibByObjectName( reinterpret_cast<char*>(munitionObjectIdentifier.id), INPUT_NIB);
        }

        // ---
        // 3) Tell the target player that it was killed by the firing player
        // ---
        if (detonationResult == simulation::Weapon::DETONATE_ENTITY_IMPACT) {
            if (fNib != nullptr) {
                tPlayer->event(KILL_EVENT,fNib->getPlayer());
            }
            else {
                tPlayer->event(KILL_EVENT,0);   // killed by we don't know by whom
            }
        }
        
        // ---
        // 4) Update the mode of the munition IPlayer
        // ---
        if (mNib != nullptr) {
            simulation::Weapon* mPlayer = dynamic_cast<simulation::Weapon*>(mNib->getPlayer());
            if (mPlayer != nullptr) {
                mPlayer->setMode(simulation::Player::DETONATED);
                mPlayer->setDetonationResults(detonationResult);
            }
            mNib->setMode(simulation::Player::DETONATED);
        }
    }

    return true;
}