本文整理汇总了C++中NetIO::getSimulation方法的典型用法代码示例。如果您正苦于以下问题:C++ NetIO::getSimulation方法的具体用法?C++ NetIO::getSimulation怎么用?C++ NetIO::getSimulation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetIO
的用法示例。
在下文中一共展示了NetIO::getSimulation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: entityStateManager
//------------------------------------------------------------------------------
// entityStateManager() -- (Output support)
// -- Update the entity object for this NIB(Player)
//------------------------------------------------------------------------------
bool Nib::entityStateManager(const LCreal curExecTime)
{
bool ok = false;
// Get the player pointer
const Simulation::Player* player = getPlayer();
if (player == nullptr) return ok;
// Dummy weapon?
const Simulation::Weapon* ww = dynamic_cast<const Simulation::Weapon*>( player );
if (ww != nullptr) {
if (ww->isDummy()) return ok;
}
if (isPlayerStateUpdateRequired(curExecTime)) {
//
// Send an entity state PDU
// 1) create buffer
// 2) set state information
// 3) send data
//
// Get our NetIO and the main simulation
NetIO* disIO = static_cast<NetIO*>(getNetIO());
Simulation::Simulation* sim = disIO->getSimulation();
// Capture the player data, reset the dead reckoning and
// mark the current time.
playerState2Nib();
// ---
// Create buffer and cast it as an entity state PDU
// ---
char pduBuffer[NetIO::MAX_PDU_SIZE];
EntityStatePDU* pdu = (EntityStatePDU*) &pduBuffer[0];
//
// Entity state PDU structure
// =========================================================
// PDUHeader header;
// EntityIdentifierDIS entityID;
// uint8_t forceID;
// uint8_t numberOfArticulationParameters;
// EntityType entityType;
// EntityType alternativeType;
// VectorDIS entityLinearVelocity;
// WorldCoordinates entityLocation;
// EulerAngles entityOrientation;
// uint32_t appearance;
// uint8_t deadReckoningAlgorithm;
// uint8_t otherParameters[15];
// VectorDIS DRentityLinearAcceleration;
// AngularVelocityVectorDIS DRentityAngularVelocity;
// EntityMarking entityMarking;
// uint32_t capabilities;
// =========================================================
//
// ---
// Standard header (PDUHeader)
// ---
pdu->header.protocolVersion = disIO->getVersion();
pdu->header.exerciseIdentifier = disIO->getExerciseID();
pdu->header.PDUType = NetIO::PDU_ENTITY_STATE;
pdu->header.protocolFamily = NetIO::PDU_FAMILY_ENTITY_INFO;
//
if (disIO->getTimeline() == Simulation::NetIO::UTC)
pdu->header.timeStamp = disIO->makeTimeStamp( getTimeUtc(), true );
else
pdu->header.timeStamp = disIO->makeTimeStamp( getTimeExec(), false );
//
pdu->header.status = 0;
pdu->header.padding = 0;
// ---
// Entity ID (EntityIdentifierID)
// ---
pdu->entityID.simulationID.siteIdentification = getSiteID();
pdu->entityID.simulationID.applicationIdentification = getApplicationID();
pdu->entityID.ID = getPlayerID();
// ---
// Force ID: When mapping Player side to force IDs ...
// ---
if (getSide() == Simulation::Player::BLUE) {
// blue's are friendly, ...
pdu->forceID = NetIO::FRIENDLY_FORCE;
}
else if (getSide() == Simulation::Player::RED) {
// red's are not, ...
pdu->forceID = NetIO::OPPOSING_FORCE;
}
else if (getSide() == Simulation::Player::WHITE) {
// white is neutral, ...
pdu->forceID = NetIO::NEUTRAL_FORCE;
//.........这里部分代码省略.........
示例2: updateBasicEntity
//------------------------------------------------------------------------------
// updateBasicEntity() -- (Output support)
// -- sets the BasicEntity attribute values that need to be updated
//
// -- We send all published BasicEntity attributes every time.
//
// The function isPlayerStateUpdateRequired() checking if the player's state
// needs to be resent. Therefore, we're not check the individual update
// required flags with isAttributeUpdateRequired(), but we do clear them
// with setAttributeUpdateRequiredFlag().
//
// (Also handles the host to network byte swapping)
//------------------------------------------------------------------------------
void Nib::updateBasicEntity(
RTI::AttributeHandleValuePairSet* attrs,
const double)
{
if (baseEntity != nullptr) {
// Our handler
NetIO* netIO = static_cast<NetIO*>(getNetIO());
// Our simulation
simulation::Simulation* ourSim = netIO->getSimulation();
// Get the player data
playerState2Nib();
// Entity ID
if (isAttributeUpdateEnabled(NetIO::ENTITY_IDENTIFIER_AI)) {
EntityIdentifierStruct* entityId = &baseEntity->entityIdentifier;
entityId->federateIdentifier.siteID = getSiteID();
entityId->federateIdentifier.applicationID = getApplicationID();
entityId->entityNumber = getPlayerID();
//std::cout << "Send Federate ID: (" << entityId->entityNumber << "," << entityId->federateIdentifier.applicationID << "," << entityId->federateIdentifier.siteID << ")" << std::endl;
EntityIdentifierStruct netBuffer;
base::NetHandler::toNetOrder(&netBuffer.federateIdentifier.applicationID, entityId->federateIdentifier.applicationID );
base::NetHandler::toNetOrder(&netBuffer.federateIdentifier.siteID, entityId->federateIdentifier.siteID );
base::NetHandler::toNetOrder(&netBuffer.entityNumber, entityId->entityNumber );
attrs->add(netIO->getObjectAttributeHandle(
NetIO::ENTITY_IDENTIFIER_AI),
reinterpret_cast<char*>(&netBuffer),
sizeof(EntityIdentifierStruct)
);
setAttributeUpdateRequiredFlag(NetIO::ENTITY_IDENTIFIER_AI, false);
}
// Entity Type
if (isAttributeUpdateEnabled(NetIO::ENTITY_TYPE_AI)) {
EntityTypeStruct* entityType = &baseEntity->entityType;
entityType->entityKind = getEntityKind();
entityType->domain = getEntityDomain();
entityType->countryCode = getEntityCountry();
entityType->category = getEntityCategory();
entityType->subcategory = getEntitySubcategory();
entityType->specific = getEntitySpecific();
entityType->extra = getEntityExtra();
// Network byte order: all bytes except country code which is unsigned short.
EntityTypeStruct netBuffer = *entityType;
base::NetHandler::toNetOrder(&netBuffer.countryCode, entityType->countryCode );
attrs->add(netIO->getObjectAttributeHandle(
NetIO::ENTITY_TYPE_AI),
reinterpret_cast<char*>(&netBuffer),
sizeof(EntityTypeStruct)
);
setAttributeUpdateRequiredFlag(NetIO::ENTITY_TYPE_AI, false);
}
// Spatial Structure
if (isAttributeUpdateEnabled(NetIO::SPATIAL_AI)) {
osg::Vec3d pos = getDrPosition();
osg::Vec3d vel = getDrVelocity();
osg::Vec3d accel = getDrAcceleration();
osg::Vec3d angles = getDrEulerAngles();
osg::Vec3d arates = getDrAngularVelocities();
// NIB's base entity structures
SpatialStruct* spatial = &(baseEntity->spatial);
SpatialRVStruct* spatialRvw = &(baseEntity->spatialRvw);
// Net order buffer (used to send the attribute to the RTI)
const unsigned int SPATIAL_NET_BUFFER_SIZE = sizeof(SpatialStruct) + sizeof(SpatialRVStruct);
unsigned char netBuffer[SPATIAL_NET_BUFFER_SIZE];
SpatialStruct* netSpatial = reinterpret_cast<SpatialStruct*>(&netBuffer[0]);
SpatialRVStruct* netSpatialRvw = reinterpret_cast<SpatialRVStruct*>(&netBuffer[sizeof(SpatialStruct)]);
// Ref Position
double refLat = 0.0;
double refLon = 0.0;
if (ourSim != nullptr) {
refLat = ourSim->getRefLatitude();
refLon = ourSim->getRefLongitude();
}
//.........这里部分代码省略.........