//------------------------------------------------------------------------------ // processInputList() -- Update players/systems from the Input-list //------------------------------------------------------------------------------ void NetIO::processInputList() { for (unsigned int idx = 0; idx < getInputListSize(); idx++) { Nib* nib = static_cast<Nib*>( getInputNib(idx) ); if (nib != nullptr) nib->updateTheIPlayer(); } }
//------------------------------------------------------------------------------ // This function will copy our type codes to the target NIB, 'targetNib', object. //------------------------------------------------------------------------------ bool Ntm::copyEntityType(simulation::Nib* const targetNib) const { bool ok = false; Nib* tgtNib = dynamic_cast<Nib*>(targetNib); if (tgtNib != nullptr) { ok = tgtNib->setEntityType(kind, domain, country, category, subcategory, specific, extra); } return ok; }
void Ambassador::reflectAttributeValues ( RTI::ObjectHandle theObject, const RTI::AttributeHandleValuePairSet& theAttrs, const char* theTag) throw ( RTI::ObjectNotKnown, RTI::AttributeNotKnown, RTI::FederateOwnsAttributes, RTI::FederateInternalError) { //std::cout << "Ambassador::reflectAttributeValues(): object = " << theObject << ", theTag=" << theTag << std::endl; // find the input object NetIO* netIO = getNetIO(); Nib* nib = static_cast<Nib*>( netIO->findNibByObjectHandle(theObject, NetIO::INPUT_NIB) ); if (nib != nullptr) nib->reflectAttributeValues(theAttrs); }
//------------------------------------------------------------------------------ // unregisterAllObjects() -- //------------------------------------------------------------------------------ bool NetIO::unregisterAllObjects() { // Stop Registration For Object Classes clearAllObjectClassRegistrationFlags(); // Unregister all of our output objects ... for (unsigned int idx = 0; idx < nOutObjects; idx++) { Nib* nib = outHandleTbl[idx]; if (nib->isRegistered()) { getRTIambassador()->deleteObjectInstance(nib->getObjectHandle(),0); nib->setObjectHandle(0); nib->setClassIndex(0); } } return true; }
void Ambassador::provideAttributeValueUpdate ( RTI::ObjectHandle theObject, const RTI::AttributeHandleSet& theAttrs) throw ( RTI::ObjectNotKnown, RTI::AttributeNotKnown, RTI::AttributeNotOwned, RTI::FederateInternalError) { //std::cout << "Ambassador:provideAttributeValueUpdate(): "; // Find the output object NetIO* netIO = getNetIO(); Nib* nib = static_cast<Nib*>( netIO->findNibByObjectHandle(theObject, NetIO::OUTPUT_NIB) ); if (nib != nullptr) nib->provideAttributeValueUpdate(theAttrs); //std::cout << std::endl; }
void Ambassador::removeObjectInstance ( RTI::ObjectHandle theObject, const char* theTag) throw ( RTI::ObjectNotKnown, RTI::FederateInternalError) { std::cout << "Ambassador::removeObjectInstance(): remove object = " << theObject << ", theTag=" << theTag << std::endl; // find the input object NetIO* netIO = getNetIO(); Nib* nib = netIO->findNibByObjectHandle(theObject, NetIO::INPUT_NIB); if (nib != nullptr) { // set NIB delete request (Simulation::NetIO::cleanupInputList() should handle this) nib->setMode(simulation::Player::DELETE_REQUEST); } }
//------------------------------------------------------------------------------ // turnUpdatesOffForObjectInstance //------------------------------------------------------------------------------ void Ambassador::turnUpdatesOffForObjectInstance ( RTI::ObjectHandle theObject, const RTI::AttributeHandleSet& theAttributes) throw ( RTI::ObjectNotKnown, RTI::AttributeNotOwned, RTI::FederateInternalError) { //std::cout << "Ambassador:turnUpdatesOffForObjectInstance(): "; // Find the output object NetIO* netIO = getNetIO(); Nib* nib = static_cast<Nib*>(netIO->findNibByObjectHandle(theObject, NetIO::OUTPUT_NIB)); if (nib != 0) nib->turnUpdatesOff(theAttributes); //std::cout << std::endl; }
//------------------------------------------------------------------------------ // Create a new output NIB //------------------------------------------------------------------------------ simulation::Nib* NetIO::createNewOutputNib(simulation::Player* const player) { // --- // Check if we are enabled to register this class of objects and // create the proper FOM class structure // --- unsigned int idx = 0; BaseEntity* baseEntity = nullptr; if (player->isClassType(typeid(simulation::AirVehicle))) { if (isObjectClassRegistrationEnabled( AIRCRAFT_CLASS )) { baseEntity = new Aircraft(); idx = AIRCRAFT_CLASS; } } else if (player->isClassType(typeid(simulation::Missile))) { if (isObjectClassRegistrationEnabled( MUNITION_CLASS )) { baseEntity = new Munition(); idx = MUNITION_CLASS; } } else if (player->isClassType(typeid(simulation::LifeForm))) { if (isObjectClassRegistrationEnabled( HUMAN_CLASS )) { baseEntity = new Human(); idx = HUMAN_CLASS; } } else if (player->isClassType(typeid(simulation::GroundVehicle))) { if (isObjectClassRegistrationEnabled( GROUND_VEHICLE_CLASS )) { baseEntity = new GroundVehicle(); idx = GROUND_VEHICLE_CLASS; } } else if (player->isClassType(typeid(simulation::Ship))) { if (isObjectClassRegistrationEnabled( SURFACE_VESSEL_CLASS )) { baseEntity = new SurfaceVessel(); idx = SURFACE_VESSEL_CLASS; } } // --- // If enabled, create and set the output NIB // --- Nib* nib = nullptr; if (baseEntity != nullptr) { nib = static_cast<Nib*>(nibFactory(simulation::NetIO::OUTPUT_NIB)); if (nib != nullptr) { nib->setBaseEntity(baseEntity); nib->setNetIO(this); nib->setPlayer(player); nib->setClassIndex(idx); nib->setOutputPlayerType(player); } baseEntity->unref(); // the NIB should have it } return nib; }
void NetIO::destroyOutputNib(Simulation::Nib* const nib0) { std::cout << "NetIO::destroyOutputNib(" << nib0 << ")" << std::endl; Nib* nib = dynamic_cast<Nib*>(nib0); if (nib != 0) { if (nib->isRegistered()) { // When this output NIB was registered as an HLA object ... std::cout << "###DeleteReq- Unref-2: handle: " << nib->getObjectHandle() << std::endl; removeNibFromObjectTables(nib, OUTPUT_NIB); getRTIambassador()->deleteObjectInstance(nib->getObjectHandle(),0); nib->setObjectHandle(0); nib->setClassIndex(0); } // Let our base class handle the rest BaseClass::destroyOutputNib(nib); } }
//------------------------------------------------------------------------------ // discoverObjectInstance() -- handle the discover of an object //------------------------------------------------------------------------------ void NetIO::discoverObjectInstance( const RTI::ObjectHandle theObject, const RTI::ObjectClassHandle theObjectClass, const char* theObjectName) { BaseEntity* baseEntity = nullptr; unsigned int idx = findObjectClassIndex(theObjectClass); switch (idx) { case AIRCRAFT_CLASS : baseEntity = new Aircraft(); break; case MUNITION_CLASS : baseEntity = new Munition(); break; case HUMAN_CLASS : baseEntity = new Human(); break; case GROUND_VEHICLE_CLASS : baseEntity = new GroundVehicle(); break; case SURFACE_VESSEL_CLASS : baseEntity = new SurfaceVessel(); break; }; if (baseEntity != nullptr) { Nib* nib = dynamic_cast<Nib*>( createNewInputNib() ); if (nib != nullptr) { nib->setObjectHandle(theObject); nib->setObjectName(theObjectName); nib->setClassIndex(idx); nib->setTimeExec( (double) getCurrentTime() ); nib->setBaseEntity(baseEntity); addNib2InputList(nib); addNibToObjectTables(nib, INPUT_NIB); nib->unref(); } baseEntity->unref(); // (NIB has it now) } }
//------------------------------------------------------------------------------ // munitionDetonationMsgFactory() -- (Output) Munition detonation message factory //------------------------------------------------------------------------------ bool Nib::munitionDetonationMsgFactory(const double) { std::cout << "rprfom::Nib::sendMunitionDetonation() HERE!!" << std::endl; // Early out -- we must be registered if (!isRegistered()) return false; NetIO* netIO = static_cast<NetIO*>(getNetIO()); // Create the parameter/value set RTI::ParameterHandleValuePairSet* pParams = RTI::ParameterSetFactory::create( NetIO::NUM_INTERACTION_PARAMETER ); // Set our mode so that we don't do this again. setMode(simulation::Player::DETONATED); // If our player just detonated, then it must be a weapon! simulation::Weapon* mPlayer = dynamic_cast<simulation::Weapon*>(getPlayer()); if (mPlayer == nullptr) return false; // Early out -- it wasn't a weapon // --- // Event ID // --- unsigned short fireEvent = getWeaponFireEvent(); EventIdentifierStruct eventIdentifier; base::NetHandler::toNetOrder(&eventIdentifier.eventCount, fireEvent); base::utStrncpy( reinterpret_cast<char*>(&eventIdentifier.issuingObjectIdentifier.id[0]), sizeof(eventIdentifier.issuingObjectIdentifier.id), getObjectName(), RTIObjectIdStruct::ID_SIZE ); pParams->add( netIO->getInteractionParameterHandle(NetIO::EVENT_IDENTIFIER_MD_PI), reinterpret_cast<char*>(&eventIdentifier), sizeof(EventIdentifierStruct) ); // --- // Location & Velocity // --- { osg::Vec3d geocPos = getDrPosition(); osg::Vec3d geocVel = getDrVelocity(); osg::Vec3d geocAcc = getDrAcceleration(); // World Coordinates WorldLocationStruct detonationLocation; base::NetHandler::toNetOrder(&detonationLocation.x, geocPos[base::Nav::IX]); base::NetHandler::toNetOrder(&detonationLocation.y, geocPos[base::Nav::IY]); base::NetHandler::toNetOrder(&detonationLocation.z, geocPos[base::Nav::IZ]); pParams->add( netIO->getInteractionParameterHandle(NetIO::DETONATION_LOCATION_MD_PI), reinterpret_cast<char*>(&detonationLocation), sizeof(WorldLocationStruct) ); // Velocity VelocityVectorStruct finalVelocityVector; base::NetHandler::toNetOrder(&finalVelocityVector.xVelocity, static_cast<float>(geocVel[base::Nav::IX])); base::NetHandler::toNetOrder(&finalVelocityVector.yVelocity, static_cast<float>(geocVel[base::Nav::IY])); base::NetHandler::toNetOrder(&finalVelocityVector.zVelocity, static_cast<float>(geocVel[base::Nav::IZ])); pParams->add( netIO->getInteractionParameterHandle(NetIO::FINAL_VELOCITY_VECTOR_MD_PI), reinterpret_cast<char*>(&finalVelocityVector), sizeof(VelocityVectorStruct) ); } // --- // Munition Object identifiers: // --- { RTIObjectIdStruct munitionObjectIdentifier; base::utStrncpy( reinterpret_cast<char*>(&munitionObjectIdentifier.id[0]), sizeof(munitionObjectIdentifier.id), getObjectName(), RTIObjectIdStruct::ID_SIZE ); pParams->add( netIO->getInteractionParameterHandle(NetIO::MUNITION_OBJECT_IDENTIFIER_MD_PI), reinterpret_cast<char*>(&munitionObjectIdentifier), sizeof(RTIObjectIdStruct) ); } // --- // Firing Object identifier: // // Get the firing player and its NIB. // First check to see if it's an IPlayer from an HLA network. // If it's not, then check our output list. // --- { Nib* fNib = nullptr; simulation::Player* fPlayer = mPlayer->getLaunchVehicle(); if (fPlayer != nullptr) { if (fPlayer->isNetworkedPlayer()) { fNib = dynamic_cast<Nib*>( fPlayer->getNib() ); } else { fNib = dynamic_cast<Nib*>( netIO->findNib(fPlayer, simulation::NetIO::OUTPUT_NIB) ); } } if (fNib != nullptr) { RTIObjectIdStruct firingObjectIdentifier; base::utStrncpy( reinterpret_cast<char*>(&firingObjectIdentifier.id[0]), sizeof(firingObjectIdentifier.id), fNib->getObjectName(), RTIObjectIdStruct::ID_SIZE ); pParams->add( netIO->getInteractionParameterHandle(NetIO::FIRING_OBJECT_IDENTIFIER_MD_PI), reinterpret_cast<char*>(&firingObjectIdentifier), sizeof(RTIObjectIdStruct) ); } } // --- // Target Object identifier: // // Get the target player and its NIB. // First check to see if it's an IPlayer from an HLA network. // If it's not, then check our output list. // --- { Nib* tNib = nullptr; simulation::Player* tPlayer = mPlayer->getTargetPlayer(); if (tPlayer != nullptr) { tNib = dynamic_cast<Nib*>( tPlayer->getNib() ); if (tNib == nullptr) tNib = dynamic_cast<Nib*>( netIO->findNib(tPlayer, simulation::NetIO::OUTPUT_NIB) ); } if (tNib != nullptr) { RTIObjectIdStruct targetObjectIdentifier; base::utStrncpy( reinterpret_cast<char*>(&targetObjectIdentifier.id[0]), sizeof(targetObjectIdentifier.id), tNib->getObjectName(), RTIObjectIdStruct::ID_SIZE ); pParams->add( netIO->getInteractionParameterHandle(NetIO::TARGET_OBJECT_IDENTIFIER_MD_PI), reinterpret_cast<char*>(&targetObjectIdentifier), sizeof(RTIObjectIdStruct) ); } } // --- // Munition Type // --- { EntityTypeStruct munitionType; munitionType.entityKind = getEntityKind(); munitionType.domain = getEntityDomain(); base::NetHandler::toNetOrder(&munitionType.countryCode, getEntityCountry() ); munitionType.category = getEntityCategory(); munitionType.subcategory = getEntitySubcategory(); munitionType.specific = getEntitySpecific(); munitionType.extra = getEntityExtra(); pParams->add( netIO->getInteractionParameterHandle(NetIO::MUNITION_TYPE_MD_PI), reinterpret_cast<char*>(&munitionType), sizeof(EntityTypeStruct) ); } // --- // Fuse Type (16 bit enum) // --- { FuseTypeEnum16 fuseType = FuseTypeOther; unsigned short netBuffer; base::NetHandler::toNetOrder(&netBuffer, static_cast<unsigned short>(fuseType) ); pParams->add( netIO->getInteractionParameterHandle(NetIO::FUSE_TYPE_MD_PI), reinterpret_cast<char*>(&netBuffer), sizeof(unsigned short) ); } // --- // Quantity fired // --- { unsigned short quantityFired = 1; unsigned short netBuffer; base::NetHandler::toNetOrder(&netBuffer, quantityFired ); pParams->add( netIO->getInteractionParameterHandle(NetIO::QUANTITY_FIRED_MD_PI), reinterpret_cast<char*>(&netBuffer), sizeof(unsigned short) ); } // --- // Rate Of Fire // --- { unsigned short rateOfFire = 0; unsigned short netBuffer; base::NetHandler::toNetOrder(&netBuffer, rateOfFire ); pParams->add( netIO->getInteractionParameterHandle(NetIO::RATE_OF_FIRE_MD_PI), reinterpret_cast<char*>(&netBuffer), sizeof(unsigned short) ); } // --- // Warhead type // --- { WarheadTypeEnum16 warheadType = WarheadTypeOther; unsigned short netBuffer; base::NetHandler::toNetOrder(&netBuffer, static_cast<unsigned short>(warheadType) ); pParams->add( netIO->getInteractionParameterHandle(NetIO::WARHEAD_TYPE_MD_PI), reinterpret_cast<char*>(&netBuffer), sizeof(unsigned short) ); } // --- // Relative detonation location // --- { RelativePositionStruct relativeDetonationLocation; relativeDetonationLocation.bodyXDistance = 0; relativeDetonationLocation.bodyYDistance = 0; relativeDetonationLocation.bodyZDistance = 0; RelativePositionStruct netBuffer; base::NetHandler::toNetOrder(&netBuffer.bodyXDistance, relativeDetonationLocation.bodyXDistance ); base::NetHandler::toNetOrder(&netBuffer.bodyYDistance, relativeDetonationLocation.bodyYDistance ); base::NetHandler::toNetOrder(&netBuffer.bodyZDistance, relativeDetonationLocation.bodyZDistance ); pParams->add( netIO->getInteractionParameterHandle(NetIO::RELATIVE_DETONATION_LOCATION_MD_PI), reinterpret_cast<char*>(&netBuffer), sizeof(RelativePositionStruct) ); } // --- // Detonation result code // --- { DetonationResultCodeEnum8 detonationResultCode; switch ( mPlayer->getDetonationResults() ) { case simulation::Weapon::DETONATE_OTHER : detonationResultCode = DetonationResultCodeOther; break; case simulation::Weapon::DETONATE_ENTITY_IMPACT : detonationResultCode = EntityImpact; break; case simulation::Weapon::DETONATE_ENTITY_PROXIMATE_DETONATION : detonationResultCode = EntityProximateDetonation; break; case simulation::Weapon::DETONATE_GROUND_IMPACT : detonationResultCode = GroundImpact; break; case simulation::Weapon::DETONATE_GROUND_PROXIMATE_DETONATION : detonationResultCode = GroundProximateDetonation; break; case simulation::Weapon::DETONATE_DETONATION : detonationResultCode = Detonation; break; case simulation::Weapon::DETONATE_NONE : detonationResultCode = None; break; default : detonationResultCode = DetonationResultCodeOther; break; }; unsigned char netBuffer = static_cast<unsigned char>(detonationResultCode); pParams->add( netIO->getInteractionParameterHandle(NetIO::DETONATION_RESULT_CODE_MD_PI), reinterpret_cast<char*>(&netBuffer), sizeof(unsigned char) ); } // --- // Send the interaction // --- bool ok = netIO->sendInteraction( netIO->getInteractionClassHandle(NetIO::MUNITION_DETONATION_INTERACTION), pParams ); // don't need this anymore delete pParams; return ok; }