VR-Forces 4.2 Class Documentation
Create Parameter Database Dynamically

Table of Contents

The Create Parameter Database Dynamically example demonstrates the following:

The Create Parameter Database Dynamically example adds a number of entries to the parameter database without initially reading the vrfSim.opd file. It will then create entities and assign them a task based on those entries to show they have been created successfully. This example can be used as a starting point for populating the parameter database with entries not defined in the vrfSim.opd file or from another source other than the vrfSim.opd file.

How to Run the Example

This example demonstrates how to programmatically create a parameter database and use it in a standalone CGF application.

Usage

createParamDbDynamically

To view the new behavior:

  1. Start the vrfGui.
  2. Open the ground-db.mtd database.
  3. Start createParameDbDynamically.

A platoon consisting of 4 tanks will move to a waypoint in column formation.

Classes

DtParameterDbEntryFactoryClass that knows how to create different types of parameter database entries.
DtObjectParametersBuilderPure virtual class that object parameters subclass from to create themselves via the factory.
DtForceLevelAggregateParametersBuilderClass that creates a force level entry for the parameter database.
DtTankPlatoonParametersBuilderClass that creates a tank platoon entry for the parameter database.
DtWaypointParametersBuilderClass that creates a waypoint entry for the parameter database.
DtTankParametersBuilderClass that creates a tank entry for the parameter database.
DtRouteParametersBuilderClass that creates a route entry for the parameter database.

Plugin Entry Points

/*******************************************************************************
** Copyright (c) 2005 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
/*******************************************************************************
** $RCSfile: main.cxx,v $ $Revision: 1.14 $ $State: Exp $
*******************************************************************************/
//This example demonstrates how to create and populate the parameter database
//programmatically, as an alternative to loading the parameter database from
//MTL files (i.e. vrfSim.opd).
#ifdef WIN32
#include <winsock2.h>
#include <windows.h>
#endif
//Local (project) headers
//VR-Forces headers
#include "vrfcgf/cgf.h"
//VR-Link headers
#include <vl/exerciseConn.h>
#include <vlutil/vlPrint.h>
#include <vlutil/vlProcessControl.h>
#include <vl/hostStructs.h>
int main(int argc, char *argv[])
{
//DIS/RPR simulation address
DtSimulationAddress simAddress(1, 3005);
//Create the CGF
DtCgf* cgf = new DtCgf(simAddress);
//Create the exercise connection
#if DtHLA
DtString execName = "VR-Link"; //HLA federation execution name
DtString federateName = "simpleCgf"; //HLA federate name
double rprFomVersion = 1.0; //RPR FOM version number
DtExerciseConn* exerciseConn = new DtExerciseConn(execName, federateName,
new DtRprFomMapper(rprFomVersion));
#else //DIS
int port = 3923; //UDP port number
int exerciseId = 1; //DIS exercise ID
DtExerciseConn* exerciseConn = new DtExerciseConn(port, exerciseId,
simAddress.siteId(), simAddress.applicationId());
#endif
//Override the default kind of parameter database to create,
//DtMtlParameterDatabase. Replace it with an alternate kind
//of parameter database DtVrfParameterDb. This is the simplest
//kind of parameter database. It does not know how to serialize
//itself to file in MTL format.
//Initialize the CGF
cgf->init(exerciseConn, &creator);
//Create a new scenario, using the Ground-db.gdb terrain database
cgf->newScenario("../data/terrain/Ground-db/Cgf/Ground-db.gdb");
//Create various kinds of parameter database entries.
//The paramDbEntryFactory returns new instances of various kinds
//of parameter database objects, created programmatically (instead of
//being read in from file).
DtParameterDbEntryFactory paramDbEntryFactory;
DtVrfObjectParameters* tankParameters = paramDbEntryFactory.createTank();
DtVrfObjectParameters* platoonParameters =
paramDbEntryFactory.createTankPlatoon();
DtVrfObjectParameters* waypointParameters =
paramDbEntryFactory.createWaypoint();
DtVrfObjectParameters* routeParameters = paramDbEntryFactory.createRoute();
DtVrfObjectParameters* forceLevelAggregateParameters =
paramDbEntryFactory.createForceLevelAggregate();
//Populate the parameter database with the new entries.
DtVrfParameterDb* parameterDb = cgf->parameterDatabase();
parameterDb->add(tankParameters->objectType(), tankParameters);
parameterDb->add(platoonParameters->objectType(), platoonParameters);
parameterDb->add(waypointParameters->objectType(), waypointParameters);
parameterDb->add(routeParameters->objectType(), routeParameters);
parameterDb->add(forceLevelAggregateParameters->objectType(),
forceLevelAggregateParameters);
//Create some new instances of entities and a control object. It will
//make use of our newly configured parameter database, looking up
//the parameter entries and using them to direct the construction of
//new entities and control objects.
//Create a platoon
DtVector initialPosition(900.0, 900.0, 0.0); //Database coordinates, meters
DtReal initialHeading = 0.0; //Heading in degrees
bool createSubordinates = true;
DtVrfObject* tankPlatoon = cgf->createAggregate(
platoonParameters->objectType(),
DtForceFriendly, DtVector(1100.0, 1100.0, 0.0), initialHeading,
createSubordinates);
//tick the cgf to allow the aggregate to be fully formed before tasking
int counter;
for(counter = 0; counter < 2; counter++)
{
cgf->tick();
}
//Create a waypoint named "Alpha"
DtVrfObject* waypoint = cgf->createWaypoint(
DtVector(1300.0, 1000.0, 0.0),
"Alpha");
//Put the simulation engine into run mode.
cgf->run();
bool assignedTask = false;
//Main application loop
while (1)
{
//tick the CGF
cgf->tick();
if(!assignedTask)
{
//Set formation to column
DtSetFormationRequest formationRequest;
formationRequest.setFormationName(DtRwFormationType::getStringFromValue(DtColumnFormation));
cgf->sendSetDataRequest(tankPlatoon, formationRequest);
//Tell the platoon to move to waypoint "Alpha"
DtMoveToTask moveToTask;
moveToTask.setControlPtName("Alpha");
cgf->assignTask(tankPlatoon, moveToTask);
assignedTask = true;
}
char *keyPtr = DtGetInputLine();
if (keyPtr && *keyPtr == 'q')
{
break;
}
//Give up the remainder of our time slice.
DtSleep(0.01);
}
delete cgf;
delete exerciseConn;
return 0;
}

Document ID: Generated on Sun Nov 24 19:49:21 EST 2013 from SVN revision 133924
Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)