WSF
Getting Started (or Hello, Sim)

The following example demonstrates a trivial simulation and serves as a building block on which we will proceed to add additional capabilities. It loads a scenario from 'test.txt' (the format of the scenario input file is described in a separate document). It then initializes the simulation and proceeds to run it.

int main(int argc, char* argv[])
{
WsfApplication app("My app", argc, argv);
// Create the scenario and load inputs
WsfScenario scenario(app);
scenario.LoadFromFile("test.txt");
// Finalize input processing and detect errors
scenario.CompleteLoad();
// Create the simulation
WsfSimulation sim(scenario, 0 /* run number */);
sim.Initialize();
sim.Start();
double simTime = 0.0;
while (sim.IsActive())
{
simTime = sim.AdvanceTime();
}
sim.Complete(simTime);
return 0;
}
double simTime
Definition WsfScriptTrackClass.cpp:1880
Definition WsfApplication.hpp:45
Contains the data required to create a simulation, and acts as the entry point for input file process...
Definition WsfScenario.hpp:111
The main controller for a simulation.
Definition WsfSimulation.hpp:109
int main(int argc, char *argv[])
Definition engage.cpp:35

This simulation is not very useful because it doesn't produce any output. If we modify the example as follows, we can either direct the simulation entities to be sent to a Distributed Interactive Simulation (DIS) exercise or written to a replay file that can be displayed by external programs. The scenario input file 'test.txt' must define a 'dis_interface' block to define what to do. And again, the contents of the scenario input file are described in a separate document.

int main(int argc, char* argv[])
{
WsfApplication app("My app", argc, argv);
WSF_REGISTER_EXTENSION(app, dis_interface); // Added!
// Create the scenario and load inputs
WsfScenario scenario(app);
scenario.LoadFromFile("test.txt");
// Finalize input processing and detect errors
scenario.CompleteLoad();
// Create the simulation
WsfSimulation sim(scenario, 0 /* run number */);
sim.Initialize();
sim.Start();
double simTime = 0.0;
while (sim.IsActive())
{
simTime = sim.AdvanceTime();
}
sim.Complete(simTime);
return 0;
}
#define WSF_REGISTER_EXTENSION(APP, NAME)
Definition WsfApplication.hpp:212

The above examples only demonstrate the basics. They don't demonstrate how to extend WSF to provide your own types of simulation objects (platforms, sensors, etc.), or implement observers that let you gather information about things occuring in the simulation. These topics will be discussed in the following sections.

What do you want to do next?

Copyrights Multiple, All Rights Reserved