An example that creates multiple F18 entities and demonstrates how to parallelize the simulation.
#include <stdlib.h>
#include <iostream>
#ifndef _WIN32
#include <sys/socket.h>
#endif
DtTime timeOutInterval = 12.0;
double translationThreshold = 1.0;
static int keybrdTick( );
#if VXWORKS
#define main realMain
#endif
int main( int argc, char* argv[] )
{
try
{
DtString appName =
"VR-Link F18 " + pidStr;
#if DtDIS
initializer.setDisVersionToSend( 7 );
#else
#endif
initializer.parseCmdLine();
initializer.setApplicationNumber( pid );
DtString defaultF18Name( initializer.f18Name() );
defaultF18Name += " " + pidStr;
initializer.setF18Name( defaultF18Name );
#ifdef DtHLA
initializer.setFederateType( "Parallel F18" );
initializer.setFederateName(defaultF18Name);
#endif
#if DtDIS
DtEntityPublisher::setDfltTimeThreshold( timeThreshold );
initializer.setUseAsynchIO(true);
#endif
#ifdef DtHLA
std::cout <<
"[" << clock->
elapsedRealTime() <<
", 0] Initializing" << std::endl;
#endif
DtTime frameTime = initializer.deltaTime();
#ifdef DtHLA
std::cout <<
"[" << clock->
elapsedRealTime() <<
", 0] Initialized" << std::endl;
#endif
int forever = 1;
double outputInterval = initializer.outputInterval();
#ifdef DtHLA
std::cout <<
"[" << clock->
elapsedRealTime() <<
", 0] Executing" << std::endl;
#endif
unsigned long frameCount = 1;
double totalDrainDuration = 0.0;
double totalSimDuration = 0.0;
double totalPubDuration = 0.0;
double totalIdle = 0.0;
double totalFrameDuration = 0.0;
int numberFrameOverflows = 0;
double totalOverflow = 0.0;
std::cout << std::fixed;
while( forever )
{
dt = startTime - lastTime;
totalDrainDuration += drainDuration;
totalSimDuration += simDuration;
totalPubDuration += pubDuration;
totalFrameDuration += frameDuration;
if (frameDuration < frameTime)
{
idle = frameTime - frameDuration;
totalIdle += idle;
dt = frameTime;
}
else
{
dt = frameDuration;
idle = -1.0;
numberFrameOverflows++;
totalOverflow += frameDuration - frameTime;
}
if (outputInterval <= 0.0 || outputTime < startTime)
{
std::cout <<
"[" << std::setprecision(2) << simulator.
simTime() <<
", " << frameCount <<
"] #entities: " << simulator.
numberRemoteEntities()
<< " total=" << std::setprecision(6) << frameDuration << "(" << totalFrameDuration / frameCount << ")"
<< " idle=" << idle << "(" << totalIdle/frameCount << ")"
<< " drain=" << drainDuration << "(" << totalDrainDuration / frameCount << ")"
<< " sim=" << simDuration << "(" << totalSimDuration / frameCount << ")"
<< " pub=" << pubDuration << "(" << totalPubDuration / frameCount << ")"
<< " #FO=" << numberFrameOverflows << "(" << (numberFrameOverflows > 0 ? totalOverflow/numberFrameOverflows : 0) << ")"
<< std::endl;
numberFrameOverflows = 0;
totalOverflow = 0.0;
}
if (idle > 0.0)
{
}
lastTime = startTime;
frameCount++;
}
}
return 0;
}
#include "vehicleSim.h"
#include <stdio.h>
#include <iostream>
{
}
{
}
{
std::cout << "Opening connection..." << std::endl;
{
std::cerr << "Failed to open connection error: " << status << "." << std::endl;
return;
}
#if DtHLA
#if DtHLA_1516
for (std::list<DtObjClassDesc*>::const_iterator item = fom->
objClassList().begin();
++item)
{
#else
classDesc;
{
#endif
}
#endif
#ifdef DtHLA
#endif
std::cout << "Connection open, status=" << status << "." << std::endl;
{
std::cout << "Serial execution." << std::endl;
}
{
std::cout << "Parallel execution." << std::endl;
}
else
{
std::cout << "Unknown execution mode, default to parallel execution." << std::endl;
}
#if DtDIS
#else
#endif
}
{
return myVehicle;
}
{
name = baseName;
if (num > 0)
{
name += "-";
}
return name;
}
{
#ifdef DtHLA_1516_EVOLVED
std::set<std::wstring> objectNames;
for (int nVehicle = 1; nVehicle <= theNumVehicles; ++nVehicle)
{
}
#endif
for (int nVehicle=1; nVehicle<=theNumVehicles; ++nVehicle)
{
}
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
{
}
else
{
}
}
{
}
{
}
{
}