![]() |
VR-Forces Developer's Guide
|
This section explains the function of drivers and the major drivers supplied.
For an introduction to drivers, please see 2.6 - The Driver Layer.
The input driver maintains a list of observer configurations (DtObserverConfiguration) that describe the observers that should be present when the input driver is running. A list of observer configurations is provided to the input driver when it is created. Additional configurations can be added. If a configuration is added while the input driver is running, then that observer is created immediately. Otherwise, it is created the next time (and each subsequent time) the input driver is started. The following example shows how to add an observer configuration to the input driver.
Create an observer configuration to describe the observer to be created. The observer configuration lets you change many of the default values for the observer, but all you really need to specify is the new observer's name in the constructor:
Add the configuration to the input driver's observer configuration list:
By adding the observer configuration to the input driver's observer configuration list, you ensure that the observer will be created each time the input driver is started.
The exampleCreateObserver example shows how to create a complete VR-Forces application with an additional observer created as described in this section. With a second observer, you can open the display configuration editor, select a channel, and change the observer associated with that channel.
The input driver uses the DtInputDriverSignaler to notify other objects of the operations that it performs. The following table describes the input driver signals.
| DtInputDriverSignaler Signals | |
|---|---|
| Signal | Description |
| signal_inputDriverCreated | Emitted when an input driver is created. Provides a pointer to the input driver selected. |
| signal_inputDriverAboutToBe-Destroyed | Emitted when an input driver is about to be destroyed. Provides a pointer to the input driver about to be destroyed. |
| signal_observerCreated | Emitted when an observer is created. Provides a pointer to the input driver and a pointer to the observer created. |
| signal_observerAboutToBe-Destroyed | Emitted when an observer is about to be destroyed. Provides a pointer to the input driver and a pointer to the observer about to be destroyed. |
| signal_currentObserverChanged | Emitted when the current observer changes. Provides a pointer to the input driver and a pointer to the new observer. |
| signal_rightClickTerrainMenu-Request | Emitted when the user right-clicks on the terrain. Provides the <x,y> mouse coordinates and a pointer to the channel that was moused in. |
| signal_rightClickSelectionMenuRequest | Emitted when the user right-clicks on an object in the scene. Provides the <x,y> mouse coordinates and a pointer to the channel in which the mouse was clicked. |
| signal_entityIndicatorsToggled | Emitted when entity indicators are toggled. |
| signal_viewControlsEnable | Emitted when the Accept View Controls switch is changed. Provides a boolean to indicate whether view control is on or off and a pointer to the affected observer. |
Management of keyboard and mouse events for an application is often dependent on which GUI system (if any) is in use. Sometimes other components within an application take responsibility for handling these events. For example, OSG provides a keyboard and mouse event handling system.
The keyboard and mouse event listener provides an interface for handling mouse and keyboard events that is independent of the GUI, the renderer, or other components that may grab events. The base class, DtKeyAndMouseEventListener, is a mechanism for registering and creating the type of listener needed for the system in use. It maintains accessors for the DtDe and the input driver, which provides a pointer to itself when it creates the listener. The listener is expected to process keyboard and mouse events in whatever manner it chooses, convert them to the VR-Forces-specific DtKeyEvent and DtMouseEvent classes, and pass these on to the input driver through its processKeyEvent() and processMouseEvent() methods.
Since VR-Forces uses an OSG-based renderer, it uses the DtOsgKeyAndMouseEventListener, which gets the keyboard and mouse events from an OSG event queue, converts them to DtKeyEvents and DtMouseEvents, and passes them on to the input driver. Each OSG channel has its own event queue. If there are multiple observers, events will affect whichever observer is assigned to the channel in which the events occur.
When a Qt-based GUI is in use (as it is in VR-Forces), Qt grabs the keyboard and mouse events before they get to OSG. VR-Forces uses the DtOsgAdapterWidget to convert these events to OSG keyboard and mouse events, and then puts them on the correct OSG event queue for the channel in which they occurred.
The observer controller tracks which observer is the one currently under keyboard and mouse control, and works with the Key Map Manager to execute observer functions on specific keyboard events. It provides mappable functions that wrap the observer functions that we want to be able to invoke from the keyboard. Mappable functions take no arguments and return void. The observer controller registers each of these functions and a corresponding string name with the Key Map Manager. Once registered, key events can be bound to the string names as part of a key map, which in turn causes the registered functions to be executed when those key events occur.
The Key Map Manager maintains a list of all functions that can be bound to a key and the string representation for that function. It also maintains a list of key maps, which provide mappings from key events to those string representations. The string representations are used to find and invoke the desired function. Please see exampleKeyMap for an explanation of how to register a function with the Key Map Manager, and bind it to a key event in a key map.
The Key Map Manager uses the Key Map Manager signaler (DtKeyMapManagerSignaler) to emit signals when certain operations are performed. The following table describes the DtKeyMapManagerSignaler signals.
| DtKeyMapManagerSignaler Signals | |
|---|---|
| Signal | Description |
| signal_keyMapCreated | Emitted when a key map is created. Provides a pointer to the Key Map Manager and the name of the key map created. |
| signal_keyMapAboutToBeDestroyed | Emitted when a key map is about to be destroyed. Provides a pointer to the Key Map Manager and the name of the key map about to be destroyed. |
| signal_keyMapChanged | Emitted when the current key map in use changes. Provides a pointer to the Key Map Manager and the name of the newly current key map. |
The input driver provides a way to see (and optionally, handle) keyboard and mouse events before it processes them. It maintains a queue of event processors, which are derived from the abstract base class DtEventProcessorInterface. You can add event processors to the front or the back of the queue. When a key or mouse event is received, the input driver invokes the appropriate processKeyboardEvent() or processMouseEvent() method for the event processor on the front of the queue. If the event processor wants to handle the event, it can return true; otherwise it returns false and the next processor on the queue is invoked. When the queue of event processors has been exhausted, if none of them has handled the event, the input driver handles the event directly.
The exampleEventProcessor example shows how to create an event processor.
The GUI API provides drivers for several protocols in the protocol-specific modules. Each driver provides the same set of capabilities, with minor exceptions based upon the protocol. These drivers visualize entities and interaction effects such as detonations. They also handle advanced visualization features such as track histories. You can have multiple simulation drivers added to the display engine, each with a different configuration. Each instance of a simulation driver is referred to as a simulation connection. You can save exercise configurations and easily switch between connections.
A simulation driver's state is controlled by its connection state. When a simulation driver is not connected to a simulation, it is in the stopped state. A simulation driver enters the running state (starts) when it successfully connects to a distributed exercise. While the simulation driver is connected to the exercise it continues to run. Disconnecting from the exercise causes the driver to stop.
VR-Forces simulation drivers use VR-Link, which provides a single interface for multiple simulation protocols. Because the interface is largely the same for both DIS and HLA, almost all protocol-specific classes are written once and compiled multiple times (for each simulation protocol). Each class is compiled into a separate namespace to eliminate duplicate symbols. Shared source classes are written in header (.h) files and inline (.inl) files. However, the inline files are not included by the header files. All shared source inline files are included in a single source (.cxx) file to be compiled for the particular library that defines the namespace.
The functionality of the distributed simulation drivers is implemented in a small number of associated classes and patterns in addition to the primary driver class.
To distinguish between classes with the same name, a different namespace is used under the main makVrv namespace. For example the DtVrlinkConnection class represents the simulation connection. The DIS protocol library is call vrvDis. The complete name of this class is makVrv::vrvDis::DtVrlinkConnection. In the header and inline files the namespace is defined using a macro, DT_PROTOCOL_NAMESPACE, which is redefined for each library that recompiles the code.
Each driver class has a connection class called DtVrlinkConnection, which manages the VR-Link exercise connection and registers listener classes. The connection class manages DtVirtualBaseClass instances. It deletes all instances before disconnecting by deleting the exercise connection at the appropriate time.
A connection registers listeners.
For how the driver initializes the exercise connection at startup and where the DIS / HLA settings come from, see 5.2.7 Exercise Connection Configuration.
A listener class provides signals for a particular type of data. The templated class DtInteractionListener can listen to any VR-Link interaction class. The DtFireInteractionListener is an example of a specialization that listens for instances of the DtFireInteraction class to be received. Stateful objects such as entities have two levels of listeners. The main instance listener class DtEntityExistenceListener listens for newly discovered entity instances and signals when existing instances are deleted. For each entity that is discovered, there is a DtEntityStateListener, which listens for changes to a particular entity's state and signals when attributes change. Listeners are created lazily on demand from a visualizer or a processor. Listener classes inherit the DtVirtualBaseClass and should be registered with the connection to ensure that they are destroyed before the exercise connection is destroyed.
Visualizer classes and processor classes use listeners to make visualization calls or data processing calls. Visualizer classes do not follow any pattern or class hierarchy other than that they connect to the signals of a particular listener and create scene object and model agents, which interact with the scene. An example of a visualizer is the DtFireInteractionVisualizer, which creates a muzzle flash effect in the scene for each DtFireInteraction that is received. A processor class is similar to a visualizer, but it does not make agents. An example of a processor is the DtViewControlProcessor, which receives custom Stealth Control messages and makes calls that control observers.
Usually there is only one instance of a particular type of visualizer or processor. While not required, it is useful to register the instance of the visualizer or processor with the connection to ensure proper memory management. Visualizers and processors can be dynamically added and removed from a connection. The Driver Accessories pattern lets you add visualizers to existing driver instances, thereby extending the functionality without modifying the existing capabilities.
All VR-Link simulation drivers share a single XML configuration file that captures the DIS and HLA settings used to join a distributed exercise. This shared file is the primary way VR-Forces reads its default connection state at startup and is the same file used by other MAK ONE products (VR-Forces, VR-Engage), so a site can converge on a single source of truth for site / exercise / port numbers, federation execution name, FED file, RPR / NETN FOM versions, and the full FOM-modules list.
appData/settings/connections/MAK-ONE-2026-Config.xml (the year in the filename is refreshed annually). It is a VR-Link DtVrlApplicationInitializer-format document containing a <disConnection> block (site, exercise ID, DIS port, DIS version, IPv6 flag) and an <hlaConnection> block (federation execution name, FED file name, RPR and NETN FOM versions, and the ordered list of FOM modules). Because the file uses the standard VR-Link initializer format, edits made to support one MAK ONE product are automatically visible to the others.DtDisDriver), HLA 1.3 (DtHla13Driver), HLA 1516e (DtHla1516eDriver), and HLA 4 / HLA Evolved (DtHla4Driver) – loads the shared file automatically during initialize(). There is no toolkit-side setup required: creating a driver in a plug-in or a custom application is enough for the driver to pick up the default settings.--exConnConfigFile <path> command-line arguments to vrvStealth or vrvIG. The option is repeatable, and multiple files are merged in argument order (later files override earlier ones). When any --exConnConfigFile argument is present, the built-in default file is suppressed rather than layered under the overrides – the user-supplied files fully replace the default set. This lets teams check a per-site or per-scenario file into version control and hand it to VR-Forces on the command line without editing the installed defaults.DtDeInitializer directly can pass the same configuration files as optional parameters using two keys on DtVrlinkDriver:DtVrlinkDriver::theExConnConfigFile – one or more paths to configuration files, in load order.DtVrlinkDriver::theExConnConfigFileCount – the number of files being supplied.The driver constructor validates each path and appends the files to its internal load list; the rest of the pipeline behaves exactly as if the files had been supplied on the command line.
DtVrlApplicationInitializer::parseCmdLine() – for example exampleDrawObjects*, exampleSendControl*, and exampleSendDrawControl* – inherit --exConnConfigFile support automatically. VR-Forces ships bin/example*Local.{bat,sh} launch scripts that pass the shared configuration file to demonstrate a typical loopback run against the same defaults VR-Forces uses.DtVrlinkConnection constructors with hand-built parameters – the shared file mechanism is optional. See exampleDisConnection and exampleHla1516eConnection for the programmatic pattern. For applications that follow the standard VR-Forces startup path, the shared file is the recommended way to keep connection settings consistent across MAK ONE products.Driver accessories allow functionality to be added to a driver without completely replacing it. Each driver can be written to support different amounts and types of extensibility through creators or signals. The GUI APIprovides a common mechanism for installing additional functionality on a per-driver basis through the use of driver accessories. A driver accessory is a simple interface for executing code when a driver starts. An accessory is registered with the display engine and can support any driver class that it knows how to interface with. The simulation drivers fully support modular extensibility using accessories.
The VR-Link simulation drivers create a DtVrlinkConnection, which runs in its own thread. Each active connection has its own thread of execution. VR-Forces provides a number of mechanisms for marshalling data between the main thread and any connection threads that may exist.
This section explains the function of drivers and the major drivers supplied.