The Add FOM Class example demonstrates the following:
- How to add new FOM object class that can be mapped to an existing object type supported by VR-Forces
- How to receive and process FOM attributes that cannot be mapped to existing object attributes in VR-Forces
- How to write a front-end example that works in conjunction with a back-end example
Adding a New FOM Object Class
The Add FOM Class example shows how to add a new FOM object class that is not part of the RPR FOM and is therefore not typically supported by VR-Forces. It shows how to map this new object class to an existing RPR-based object, assuming the concepts being simulated are similar. This example also uses an example SMS called addFomClass which can be found in data. This SMS includes a new OPE file called Alternate_Fixed_Wing.ope. This OPE makes two important additions to the standard EntityLevel Fixed Wing OPE file:
1) The hla-fom-class is set so that any entity that uses this OPE will be published with the new FOM object class.
(hla-fom-class "AlternateEntity")
2) A new state property is added in the state-data section. This state property is added to support the only attribute of the new FOM class that cannot be mapped to an existing RPR FOM entity attribute. All other attributes are mapped to existing RPR FOM attributes in the example code. This state property is a structure with two fields. This structure matches the attribute of the same name in the AlternateEntity FOM class. In order to properly encode and decode this attribute as a state property, it is important that the type defined in the OPE matches the datatype in the FOM.
(state-data (DtRwStructure SomeOtherAttribute (DtRwReal Field1 0.0) (DtRwInt Field2 0) publish ) )
For more details on state properties, please see the Add State Property Sim example.
The plugin code configures the VR-Link FOM mapper so that instances of AlternateEntity can be encoded from and decoded to an entity state repository, which is based on the RPR FOM entity classes. It also adds the AlternateEntity FOM class as a supported class of the DtExtendedPropertiesEntityPublisher and DtExtendedPropertiesEntityList classes in order to process additional FOM attributes as state properties.
The example scenario also includes a Lua scripted set called Some Other Attribute that sets the two fields of the AlternateEntity attribute called SomeOtherAttribute.
How to Run the Example
-
Copy the AlternateEntity_evolved.xml FOM module from examples to the bin64 directory. Note that his FOM module is for HLA Evolved. If you are using another HLA version you will need to edit your FOM to add in the new FOM class.
-
Since this example is loaded as a plugin, it can be used in conjunction with the released VR-Forces application.
Usage
In the Launcher:
-
Choose an HLA 1516 Evolved protocol configuration.
-
Set the addFomClass plugin to load.
-
Add AlternateEntity_evolved.xml to the list of FOM modules.
-
Set the RPR FOM version to 2.0.
-
Start VR-Forces.
To view the new behavior:
-
Load the addFomClass developer toolkit example scenario
-
Notice the entity that appears. It is published using AlternateEntity FOM class. This can be verified by running another application that subscribes to this class or using some inspection tool of your RTI.
-
Right-click on the entity and select Information... to open its information window.
-
Find the Some Other Attribute entry on the State Data page, which is updated via the SomeOtherAttribute state property.
-
By default, after the very first scenario load - the text should read "0.0 | 0".
-
Select the entity and open the Set->Some Other Attribute dialog. Set the two fields to new values.
-
The Some Other Attribute entry on the State Data page will update.
After the example run is completed:
- Remove the AlternateEntity_evolved.xml FOM module from the bin64 directory.
- Remove the AlternateEntity_evolved.xml from the list of FOM modules in the Launcher.
Configure FOM Mapper Code
#if DtHLA
#include "configFomMap.h"
#include <vl/stateEncoderFactory.h>
#include <vl/stateDecoderFactory.h>
#include <vl/fom.h>
#include <vl/fomMapper.h>
const DtString theFomClass =
"AlternateEntity";
{
DtFom* fom = exConn->fom();
DtFomMapper* mapper = exConn->fomMapper();
init->addSupportedClass(theFomClass);
DtObjClassDesc* objClass = fom->objClassByName(theFomClass);
if (objClass)
{
mapper->stateEncoderFactory()->addEncoder(objClass->handle(), enc);
mapper->stateDecoderFactory()->addDecoder(objClass->handle(), dec);
}
if (runExtPropInit)
{
init->initialize(exConn);
}
}
{
DtFom* fom = exConn->fom();
DtFomMapper* mapper = exConn->fomMapper();
DtObjClassDesc* objClass = fom->objClassByName(theFomClass);
if (objClass)
{
objClass->handle(), 0);
delete enc;
objClass->handle(), 0);
delete dec;
}
}
#endif