![]() |
VR-Forces 4.1.1 Class Documentation
|
The Add PSR example demonstrates how add a new kind of process state repository to an entity for maintaining persistent state information associated with a new kind of behavior.
The method of doing this is to create a new controller and associated process state repository. In this particular case, the new behavior is keeping track of the elapsed simulation time since creation of the entity. This controller, then, can be added to an existing VRF object entry (.ope) to write out the elapsed time to the order of battle file when the object is saved.
Because process state repositories are saved as part of an entity’s state in the order of battle file, all of the state member data that needs to be preserved in a scenario or checkpoint should be kept in a process state repository. Components are not saved as part of a scenario, so any state member data in those classes is not preserved when a scenario gets saved. If you are extending the toolkit by adding or extending components, you may want to extend the process state repositories to include any new process-related state you introduce.
The key tasks in creating and adding a new controller are as follows:
The addPSR example creates a new state repository class, DtTimeKeeperPSR, which is derived from DtVrfProcessStateRepository. In this example, the PSR is fairly low-slung, and principally exists to store and retrieve the elapsed time float associated with the controller via the mutator (setElapsedTime()) and accessor (elapsedTime()) methods.
Of specific note, the type() method must be overridden in order to return a unique string for use in the factory/ .ope. The string in this case is "time-keeper-psr-type," stored in the const variable TimeKeeperPSRType.
In this example, the DtTimeKeeperComponent is responsible for management, manipulation and implementation of the PSR. The component is responsible for creating the PSR and registering it with the DtVrfProcessStateRepositoryManager in its createPSR() method, called during initialization. The component also, within its tick() mechanism, updates the elapsed time in the PSR and outputs the elapsed time value to the console at intervals. Finally, the destuctor of the component deletes its associated PSR.
The component's tick() is automatically registered with the DtSimManager upon instantiation of a controller registered with the factory, and is then called in each time interval.
The plugin.cxx file is the location that the component and PSR are registered with their respective factories and is called when the plugin is loaded by VR Forces. Registration associates the unique strings (given by type()) with the correct static creator() methods and allows for association with .OPE files.
The data members of the PSR that are to be saved need to be registed with the DtReaderWriter parent registry. This ensures that the item will be included as part of the object’s data that gets written to file. This is done in the PSR's constructor:
The SMS structure located at \ contains an vrfSim.opd and .ope that specifies the necessary information for creation of an M1A2 tank with our new controller and PSR:
Although the "time-keeper-component" - the DtTimeKeeperComponent - defaults to creation of its associated "time-keeper-process-state-rep" - the DtTimeKeeperPSR - when initialized, explicitly listing a different PSR in the .OPE within the controller's block will override the default and the controller will, instead, instantiate the listed PSR. In this case, we've simply reiterated the default PSR.
Select Settings> Plugins... and on the Plugins Editor page, use the combo box at the top of the page to select the plug-in. Then enable the "Load Plugin" checkbox and re-start VR-Forces.
To view the behavior:
The information window will display messages updating the elapsed simulation time every 10 seconds.
| DtTimeKeeperPSR | The subclass of DtVrfProcessStateRepository that is used to store the elapsed time. |
| DtTimeKeeperComponent | The subclass of DtSimCompnent that will write the elapsed time to the DtTimeKeeperPSR during its tick(). |
/*******************************************************************************
** Copyright (c) 2003 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
/*******************************************************************************
** $RCSfile: plugin.cxx,v $ $Revision: 1.3 $ $State: Exp $
*******************************************************************************/
#include "vrfcgf/vrfPluginExtension.h"
#include "timeKeeperCmpt.h"
#include "timeKeeperPSR.h"
#include "vrfcgf/cgf.h"
#include "vrfcgf/factoryMgr.h"
#include "vrfobjcore/compTypes.h"
extern "C" {
DT_VRF_DLL_PLUGIN void DtPluginInformation(DtVrfPluginInformation& info)
{
info.pluginName = "Add PSR";
info.pluginVersion = "1.00";
info.pluginCreator = "MAK Technologies";
info.pluginCreatorEmail = "sales@mak.com";
info.pluginContactWebPage = "www.mak.com";
info.pluginContactMailingAddress = "150 Cambridge Park Drive 3rd Floor - Cambridge, MA 02140 USA";
info.pluginContactPhone = "(617) 876 8085";
}
DT_VRF_DLL_PLUGIN bool DtInitializeVrfPlugin(DtCgf* cgf)
{
//Register the component with its factory
cgf->factoryManager()->componentFactory()->addCreatorFcn(
TimeKeeperComponentType, DtTimeKeeperComponent::creator);
//Register the new process state repository
cgf->factoryManager()->processStateRepositoryFactory()->addCreatorFcn(
TimeKeeperPSRType, DtTimeKeeperPSR::creator);
return true;
}
}