![]() |
VR-Link API Documentation for HLA 1516
|
This Example FOM Mapper shows how to create a FOM Mapper for a new FOM, but assumes that the new FOM contains concepts already covered by VR-Link's API, so no extensions are necessary.
It also demonstrates how to put the new FOM Mapper into a shared library that can be loaded by DtExerciseConn, and by MAK applications like MAK Stealth, MAK Data Logger, and VR-Forces. The shared library works with the FED file called example-MyFomMap.fed that is in the VR-Link root directory.
For this example, we created a new FED file called example-MyFomMap.fed, representing a new, simple FOM. The MyFomMap FOM contains one object class called Vehicle, and one interaction class called Shoot.
Vehicle has two attributes:
These attributes are mapped to DtEntityStateRepository's concepts of entity type and location.
Shoot has two parameters:
Both parameters are character strings representing the HLA object names of the attacker and target respectively. These parameters will be mapped to DtFireInteraction's concepts of attacker ID and target ID respectively.
This FOM uses different class, attribute, and parameter names than the RPR FOM, but uses similar data representations to keep our type conversion examples simple. (Though in one case - the VehicleType attribute, our data representation is very different to demonstrate that this can be done.)
For each of these FOM classes, the example:
When you execute make in the example directory, you build a shared library called myFomMap<protocol>.so or myFomMap<protocol>.dll. You can test this library with any VR-Link example that accepts a path to a FOM mapping shared library (through the -f option.) You can omit the .so or .dll, so that the same command can be used in Windows or in UNIX. Remember to also specify a federation execution name of MyFomMap, using the -x option, so that the example-MyFomMap.fed file is used.
For example, from the ./bin64 directory, you can run the following commands for the protocol of choice:
Alternatively, you can write your own application that passes the name of the shared library to the DtExerciseConn. Again, make sure that you use the right FED or FOM file:
The myFomMap.cxx file contains the main class MyFomMapper which is created by the plugin manager.
There are several ways to configure a FOM Mapper to work with this new FOM. For example, you could allow the DtExerciseConn constructor to create an empty FOM Mapper, and then add mappings to that FOM Mapper later.
However, this example creates a subclass of DtFomMapper called MyFomMapper, whose implementation of the virtual init() function self registers all of the mappings we want. Then it can either create an instance of this class and pass it to the DtExerciseConn constructor, or create a shared library containing a function called DtCreateFomMapper() that returns a new'ed instance of MyFomMapper, and pass the name of the shared library to the DtExerciseConn constructor. This example uses the shared library option.
Regardless of how an instance of a DtFomMapper is passed to a DtExerciseConn constructor, DtExerciseConn calls init() on that FOM Mapper after reading the FED file and initializing the RTI.
The MyFomMapper class is defined in myFomMap.h and myFomMap.cxx. The code is included below. Notice that MyFomMapper is derived from DtEmptyFomMapper. Within MyFomMapper::init(), call down to the DtEmptyFomMapper::init(), which initializes the FOM Mapper with empty factories and tables. Then add your own mappings to the tables, including adding instances of our encoders and decoders to the FOM Mapper's encoder and decoder factories.
The createFomMap.cxx source file is the entry point for the DLL. It contains definitions for the functions that are required by VR-Link if you are creating a FOM Mapper shared library. When you pass the name of a shared library to a DtExerciseConn constructor, it opens the shared library and looks for the functions DtCreateFomMapper() and DtDeleteFomMapper(). Here, DtCreateFomMapper() just returns a new instance of our MyFomMapper class. These two functions must have C linkage, so we enclose their definitions within extern "C" {}.
The VehicleEncoder and VehicleDecoder show how to encode and decode the attributes of an object.
The ShootEncoder and ShootDecoder show how to encode and decode the parameters of an interaction.