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