//------------------------------------------------------------------------------ // 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; }
//------------------------------------------------------------------------------ // 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 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) } }