![]() |
VR-Link API Documentation for DIS
|
Talk is a minimal VR-Link application. The program simulates the flight of an F18 aircraft. The program begins by sending a fire PDU or HLA fire interaction. Then, the F18 flies north for 10 seconds, updating its position by sending DIS entity state PDUs or HLA attribute updates.
This example is an extremely simplified version of the F18 example. It publishes a stripped down aircraft. The published data can be viewed by The Listen Application.
This example builds and runs in DIS, HLA1.3, HLA1516 and HLA1516e, because we use the VR-Link Protocol Independent API.
Like The Listen Application example, this program creates a DtExerciseConn to provide an interface to the RTI or DIS network.
We define the entity type the F18 will use.
To be visible to other applications in the exercise, each locally-simulated entity requires a DtEntityPublisher. The entity publisher manages the generation of messages for this particular entity. It provides an entity state repository where you can set state values, and a tick() function, which causes state information to be sent to the network if necessary.
It sets up a pointer to the entity state repository, then creates a topographic view on that repository. This lets us set the entity's positional data using topographic coordinates, rather than the default geocentric coordinates. (The coordinates are hard-coded for this example.) We show an example of storing a non-positional state value in the repository.
The example sends an interaction. You can send the interaction using the exercise connection's sendStamped() function.
You can use sendStamped() to send state updates, but it is preferable to let the entity publisher send state updates for you, using data in the entity state repository.
The main loop executes twenty times per second for ten seconds. As in the listen-only example, this program sets VR-Link simulation time at the start of each iteration.
While this program's main purpose is to demonstrate the sending of data to the network, it is not a true send-only application. Incoming data is also processed with the drainInput() call. This call is required for HLA, because this is where we tick the RTI.
The program updates the F18's positional data in its entity state repositoryentity state repository and ticks the entity publisher to send the updated data onto the network. It sets topographic coordinates through a view, which VR-Link converts to geocentric coordinates.
Then, the only remaining tasks are to increment the F18's position, increment the simulation time, and sleep until it is time to begin the next iteration.
Listen is a simple listen-only VR-Link application. This application can be compiled for either DIS or HLA. The only protocol-specific code is contained in the #if statement (#if DtDIS).
With each iteration of the loop, the program prints an entity's updated, dead-reckoned position in topographic coordinates. If a fire PDU or interaction is detected on the network, the program prints a message showing the entity ID of the attacker.
To exit, press the 'q' key. This example works with the Talk example.
The program creates an exercise connection (DtExerciseConn.) This connection serves as the program's interface to an exercise. DtExerciseConn has several constructors. In this example, we create a DtVrlApplicationInitializer and pass it to the DtExerciseConn. Use of a DtVrlApplicationInitializer provides support for command line arguments. The default protocol-specific initialization values are set in the DtVrlApplicationInitializer and its base class, DtExerciseConnInitializer. This is the only protocol-specific part of the code.
Applications based on VR-Link typically use callbacks to handle incoming interactions such as fire, detonations, and collisions. For example, a callback named fireCb is registered with the DtFireInteraction class. This callback prints a message containing the attacker ID. It executes whenever the exercise connection receives a Fire PDU or interaction during a call to drainInput().
We create a reflected entity list to keep track of entities found on the network. The entity list tracks the arrival and departure of entities, performs dead reckoning, manages time outs, and performs other entity-tracking tasks.
We obtain a pointer to the simulation clock from the exercise connection.
At the start of each iteration, the program sets VR-Link simulation time to provide a common time value for use by time-related operations that occur within an iteration of the loop (such as the dead-reckoning of multiple entities.) The drainInput() call reads and processes any messages arriving through the exercise connection. This call triggers the execution, if needed, of any callbacks you have registered for that exercise connection.
The program finds the first entity in the entity list, then it retrieves the pointer to the entity's entity state repository. It creates a topographic view of that entity state repository, allowing us to retrieve its position data in topographic coordinates rather than geocentric. (The coordinates for this example are hard-coded.) The application obtains and prints the dead-reckoned entity location.