VR-Vantage
Loading...
Searching...
No Matches
6 - Drivers

This section explains the function of drivers and the major drivers supplied.

6.1 - The Input Driver

For an introduction to drivers, please see 3.6 - The Driver Layer.

6.1.1 Creating Observer Configurations

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.

  1. 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:

    makVrv::DtObserverConfiguration observerConfig("Example Observer");
    TODO: This class is used to encapsulate a set of default observer settings and parameters.
    Definition DtObserverConfiguration.h:23

  2. Add the configuration to the input driver's observer configuration list:

    de.driverManager().inputDriver().addObserverConfiguration( observerConfig );

    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-Vantage 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.

6.1.2 Input Driver Signals

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
SignalDescription
signal_inputDriverCreatedEmitted when an input driver is created. Provides a pointer to the input driver selected.
signal_inputDriverAboutToBe-DestroyedEmitted when an input driver is about to be destroyed. Provides a pointer to the input driver about to be destroyed.
signal_observerCreatedEmitted when an observer is created. Provides a pointer to the input driver and a pointer to the observer created.
signal_observerAboutToBe-DestroyedEmitted 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_currentObserverChangedEmitted when the current observer changes. Provides a pointer to the input driver and a pointer to the new observer.
signal_rightClickTerrainMenu-RequestEmitted 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_rightClickSelectionMenuRequestEmitted 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_entityIndicatorsToggledEmitted when entity indicators are toggled.
signal_viewControlsEnableEmitted 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.

6.1.3 The Keyboard and Mouse Listener

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-Vantage-specific DtKeyEvent and DtMouseEvent classes, and pass these on to the input driver through its processKeyEvent() and processMouseEvent() methods.

Since VR-Vantage 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 MAK's VR-Vantage applications ), Qt grabs the keyboard and mouse events before they get to OSG. VR-Vantage 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.

6.1.4 The Observer Controller

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.

6.1.5 The Key Map Manager

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
SignalDescription
signal_keyMapCreatedEmitted when a key map is created. Provides a pointer to the Key Map Manager and the name of the key map created.
signal_keyMapAboutToBeDestroyedEmitted 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_keyMapChangedEmitted 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.

6.1.6 Custom Event Processors

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.

6.2 - Simulation Drivers

The VR-Vantage Toolkit  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.

6.2.1 Stopping and Starting Simulation Drivers

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.

6.2.2 Using Shared Source Files for Simulation Drivers

VR-Vantage 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.

6.2.3 Simulation Driver Classes and Namespaces

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.

6.2.4 Connections

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 6.2.7 Exercise Connection Configuration.

6.2.5 Listeners

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.

Note
Typically there is only one instance of a listener, because instances are registered with the connection instance of a driver. Individual state listeners are an exception. They are owned by the instance listener, which follows this rule.

6.2.6 Visualizers and Processors

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.

6.2.7 Exercise Connection Configuration

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-Vantage 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.

The Shared Configuration File
The default file lives at 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.
Automatic Load at Startup
Every VR-Link protocol driver – DIS (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.
Overriding the Default from the Command Line
Users can override the default file by supplying one or more --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-Vantage on the command line without editing the installed defaults.
Delta-Only Serialization
When VR-Vantage saves per-user driver settings, it writes only the values that differ from the loaded configuration. Anything not overridden falls through to the shared file at the next startup, so per-user settings files stay small and updates to the shared file propagate cleanly to everyone using it. If your workflow inspects the serialized driver settings, expect to see far fewer explicit entries than in VR-Vantage 3.1.1 – absence of a field means "inherit from the shared config", not "reset to the compiled-in default". See Driver Settings Now Serialize as a Delta in the migration guide for the upgrade note.
Programmatic Access
Custom applications that construct a 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.

Toolkit Example Applications
The standalone toolkit example applications that use DtVrlApplicationInitializer::parseCmdLine() – for example exampleDrawObjects*, exampleSendControl*, and exampleSendDrawControl* – inherit --exConnConfigFile support automatically. VR-Vantage 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-Vantage uses.
Choosing Between the Shared File and Programmatic Setup
If your application configures a connection entirely from code – for example an automation harness that calls 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-Vantage startup path, the shared file is the recommended way to keep connection settings consistent across MAK ONE products.

6.3 - Adding Functionality to a Driver (Accessories)

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 VR-Vantage Toolkit provides 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.

6.4 - Managing Connection Threads

The VR-Link simulation drivers create a DtVrlinkConnection, which runs in its own thread. Each active connection has its own thread of execution. VR-Vantage provides a number of mechanisms for marshalling data between the main thread and any connection threads that may exist.

Distributed Objects
Distributed objects are objects whose interfaces can exist in a connection thread (or master display engine) while an implementation of that object exists locally on each display engine to which it is distributed.
Distributed objects can be distributed to just the master display engine or to all display engines. Dcgen is used to define the API (all void functions) of a distributed object. It can then generate an Object Agent definition which is used as the interface to the distributed object. Calls to the agent's methods are relayed to the remote objects and executed by them. (See exampleDistributedObject .)
Shared Settings Objects
Shared Settings objects are mutex-protected blocks of settings data. They may be wrapped by a manager that uses an event signaler (see Event Signals) to signal (to connections) that settings have changed, or they may use the event signaler directly. These are typically used as one way (display engine to connection) data transfers, but there is nothing stopping a connection from grabbing a write lock and making changes. However, there is no built-in mechanism for the display engine to find out that those changes have been made.
Event Signals
Event Signals are sent from the main thread, and can be received in the main thread or any connection. Event Signals are often used by a shared settings manager or shared settings object to tell the connection thread to check because something has changed in a shared settings object. These event signals are often wrapped in a singleton SharedSettingsSignaler. Event Signals are also used to request changes in element attribute values.

Element Data
Certain information about elements is always passed from the connection thread to the main thread. For every entity and interaction that gets processed, an elementID is assigned to it, and a few data fields associated with it are made available, including ID, parent ID (vertices of of multipoint objects are children of the line or area), and type (Entity, Terrain, Prop, Aggregate, and so on). In addition to these fixed data, element attributes may optionally be added to the element data. The types of element attributes may depend on the element type; many elements have display name attributes, entity elements have a damage state attribute, and so on. The full list of supported element attributes is in DtElementAttributes.h. It is easy for developers to extend these.
Element data changes are reported to the connection, and each connection tick, any changes in element data are propagated to the main thread, where all the element data is maintained (in the master display engine's DtDataBank member). Signals are raised in the main thread when element data changes in the DtDataBank.
Elements are usually created by a driver (VR-Link Driver (entities, aggregates), SceneDriver (props, terrain), InputDriver (Observers) and so the drivers are expected to maintain and report changes in element attributes. If some other object wishes to change element attributes, it can send an event signal to request the change. DtDataBankSignaler provides event signals to request changes in element attributes, which are then effected by the owners of the elements (the drivers) or by the elements themselves.
queueConnectionFunction
queueConnectionFunction() is a method in the DtVrlinkDriver that allows you to make a request from the main thread that a function be executed in the connection thread. The arguments to the function are passed across the thread boundary safely, providing another mechanism to get data from the main thread to the connection thread. For example, VR-Vantage uses this to push observer information to the connection thread for publishing the observer. Since an accessory has access to the connection and the VR-Link driver, it is an ideal place to set these up.
queueDriverFunction
queueDriverFunction() is a method in the DtVrlinkDriver that allows you to make a request from the connection thread that a function be executed in the main thread. The arguments to the function are passed across the thread boundary safely, providing another mechanism to get data from the connection thread to the main thread.
Accessories
Connections are created and started by a DtVrlinkDriver. There will be a VR-Link driver instance associated with each connection. VR-Vantage supports accessory objects that are associated with a driver type. When a driver starts, it looks through the lists of existing accessories and if one supports its type, it 'installs' the accessory into itself. This general mechanism can be used to do a lot of custom connection initialization. The accessory can connect to the signals that the VR-Link driver raises when it starts and stops a connection, get access to the connection, and register creators and instances on the connection object.
Some of the factories (like the visualizer factory) are copied from the main thread to the connection thread when a connection is created. If you have a new type of visualizer (see the exampleBulletHole example) you can register the creator with the main thread and it will get copied to the connection when the connection is created. However, if you want to override a visualizer type that the connection itself might override (with a VR-Link specific version, perhaps), then you must get the creator registered AFTER the connection has registered any connection-specific visualizer creators.