![]() |
VR-Link API Documentation for HLA 1516
|
The ability for the user to modify the user tag sent with object updates and interactions was added to VR-Link 3.12.
This is achieved by providing two base classes: DtObjectTagModifier and DtInteractionTagModifier. These classes can be subclassed, with the modifyTag() method implemented, and registered with the exercise connection. modifyTag() will be called for each update/interaction sent for each object/interaction class that it is registered for.
A typical usage of the user tag modifier may look like this:
// Only applicable to HLA! #if DtHLA // Needed to use the exercise connection #include <vl/exerciseConn.h> // Needed to use the tag modifier classes #include <vl/userTagModifiers.h> // Needed to modify interactions #include <vl/interaction.h> // Need to create a class to modify user tags for object updates. The // key here is overriding the modifyTag() method to actually modify // the tag, and to pass any needed data in through the constructor. Here, // we are going to use the execution name as the user tag for all objects, // and the FED file name for all interactions. class DtMyObjectTagModifier : public DtObjectTagModifier { public: DtMyObjectTagModifier(DtExerciseConn* exConn) : DtObjectTagModifier(), myExConn(exConn) {} virtual ~DtMyObjectTagModifier() {} // Note that a state repository is passed in. This allows you to use data // from that object to modify the tag. For instance, if this class was set // for only BaseEntity objects, you could cast rep to a DtBaseEntityStateRepository // and use an attribute of the object to fill in the user tag (e.g. EntityID). // Here, since this is for all object, we will simply use the execution name. virtual void modifyTag(DtStateMsg* msg, const DtStateRepository* rep) { DtString execName = myExConn->execName(); #if DtHLA_1516 RTI::VariableLengthData newTag; newTag.setData(execName.c_str(), execName.length() + 1); msg->setCustomTag(newTag); #else msg->setCustomTag(execName); #endif } protected: DtExerciseConn* myExConn; }; // This is the interaction tag modifier, which is very similar to the object tag // modifier. class DtMyInteractionTagModifier : public DtInteractionTagModifier { public: DtMyInteractionTagModifier(DtExerciseConn* exConn) : DtInteractionTagModifier(), myExConn(exConn) {} virtual ~DtMyInteractionTagModifier() {} // Just as with the modifyTag() method of the object tag modifier, the interaction // can be cast to a particular type of interaction (e.g. DtDetonationInteraction) if // this class is set for a particular type of interaction. Note that the DtInteraction // object contains both the parameter data *and* the tag. virtual void modifyTag(DtInteraction* inter) { DtString fedType = myExConn->fedType(); #if DtHLA_1516 RTI::VariableLengthData newTag; newTag.setData(fedType.c_str(), fedType.length() + 1); inter->setCustomTag(newTag); #else inter->setCustomTag(fedType); #endif } protected: DtExerciseConn* myExConn; }; // Now that our classes have been constructed, we just need to register them // with the exercise connection. void registerUserTagModifiers(DtExerciseConn* exConn) { // First, we create shared pointers with instances of the newly created // classes. DtObjectTagModifierSP objectTagModifier(new DtMyObjectTagModifier(exConn)); DtInteractionTagModifierSP interTagModifier(new DtMyInteractionTagModifier(exConn)); // These calls actually register the classes with particular objects. Passing in // ObjectRoot or InteractionRoot as the first parameter will register for // all objects/interactions. A third parameter of "false" can be passed in // to *not* apply the classes to all subclasses of the FOM object/interaction // specified. // For instance, to register the objectTagModifier with *just* PhysicalEntity objects, // you could call: // exConn->setObjectTagModifier("BaseEntity.PhysicalEntity", objectTagModifier, false); exConn->setObjectTagModifier("ObjectRoot", objectTagModifier); exConn->setInteractionTagModifier("InteractionRoot", interTagModifier); } #endif