![]() |
VR-Forces 5.0.1 Developer's Guide
|
The changes to VR-Forces 5.0 API are all centered around making VR-Forces sim engine a fully multithreaded application, thereby allowing it to take full advantage of as many CPUs as are available on the hardware. To do this, VRF has added some access limitations between various aspects of the API to help prevent plugin developers from inadvertently writing code that breaks the thread safety.
A compile macro can enable a “VRF4 API” to help migrate existing plugins to VRF 5. See VRF 4 Compatible API
Scenarios from VRF 4.10 will load and run in VRF 5.0.
VR-Forces 5.0 has a major threading overhaul allowing it to take advantage of many CPUs. This overhaul has requires that some access to data be restricted. See Threading Model for details.
The DtVrfObject class has been split into two classes:
The DtVrfObjectManager class has been split into two classes:
DtSimManager still exists as the top level owner to much of the simulation engine, but is no longer passed into DtVrfLocalObjects and their subcomponents. Instead, a new class called DtSimulationServices is passed into many classes. DtSimulationServices gives access to many of the different central managers and services that are needed by simulation components during their tick function, such as the DtSimObjectManager, exercise clock, and many other services. DtSimulationServices is a thread safe API and can be called from all these locations without locks.
The DtSimManager class is not thread safe and gives access to other non-thread safe classes. This is still accessible from the DtCgf class, and should only be used outside of the object tick when other threads are not running.
The state data associated with a simulated object is now broken up into distinct pieces:
A new system for holding external state data for simulation objects introduced in VRF 5 is known as state components. The set of state data for any given simulation object is composed of a collection of state components. Each state component contains a set of related data elements for a specific purpose.
Example state components:
State components can be accessed using the getStateComponent() and getNextFrameStateComponent() functions on DtSimObject and DtLocalObject, and passing the state component type as a template argument. Functions like DtSimObject::worldPosition() and DtLocalObject::setNextFrameWorldPosition() are convenience methods for calling down into the Location State Component, which is common to all simulated objects.
DtSimObjectFacade and DtLocalObjectFacade are convenience classes for accessing external state of an object without needing to use the State Components directly. There are different façade classes, each organized around a particular functionality set, which provide access to the data in one or more state components. Each façade has a SimObject and a LocalObject version. Many cases in VRF 4.x where a dynamic_cast was used on a state repository to access external state should be replaced with a facade in VRF 5.0.
Internal state is data that is private to a particular simulation object and cannot be safely accessed by other simulation objects directly. For example:
This data is stored in the DtVrfObjectStateRepository class and subclasses. This structure has not changed from VRF 4.x, but it now holds only internal state and is accessed using DtLocalObject::internalState().
In VRF 4.x, sensors, actuators and controllers hold internal state local to their function in process state repositories. This remains unchanged in VRF 5.
To make upgrading sim engine plugins to VRF 4 easier, VR-Forces now has a preprocessor flag that allows the use of a set of functions that exist in the VRF 4 API but have been removed in VRF 5. By default, these functions are not available, and will cause a compile error if used. To enable them, define the ALLOW_VRF4API macro to 1. This can be done for a whole project, or on a file-by-file basis. The VRF4 API does not cover the complete set of changes between VRF 4 and 5, so some changes are still needed.
Key API calls enabled with ALLOW_VRF4API:
To protect from threading errors, the creation and deletion of one simulation object by another has been altered. All these operations are now performed using DtCreateObjectServiceInterface from DtSimulationServices. DtCreateObjectServiceInterface::createAndInitVrfObject() is not able to return a pointer to the newly created DtLocalObject anymore, as this accessing one DtLocalObject from within another would violate the threading boundry. Instead, it returns a DtCreateObjectHandle instance which contains the DtUUID and marking text of the new object. This object can be looked up in the DtSimObjectManager, but is not valid to use until the following frame.
Any state that needs to be set in the newly created object from the creating object must now be done using the DtVrfLocalObjectCreateInformation class as an argument into DtCreateObjectServiceInterface::createAndInitVrfObject().
Example:
Data transfer between the simulation state and the simulation network (DIS, HLA, etc) has been reworked in VRF 5 to separate the network send and receive events into separate threads from the simulation computations. This required changes to the classes involved.
These network classes are now used in both the VRF Sim Engine as well as VRF GUI.
Some libraries have changed names in VRF 5.0:
[Home] [Top of Page]