/
How to get information about the Vortex simulation

How to get information about the Vortex simulation

When creating special behaviors using C# scripts, it often necessary to obtain timing and other information about the state of the Vortex simulation.

It is vital, especially for a distributed simulator, to rely on Vortex timing information instead of Unity timing. Each computer in a distributed simulator has its copy of the Unity application that was created, and each of these applications can have slightly different timing information. By accessing Vortex timing information, you ensure that all Unity applications will have a common time base, and display coming from those applications will be synchronized.

VortexApplication singleton

Information about the current simulation can be retrieved by using VortexApplication main. It can be accessed as a singleton, which is valid when the Vortex Application is running.

Properties

Instance

Give access to the current VortexApplication object. It can be used to test if the Vortex Application is created.

if (Vortex.VortexApplication.Instance == null) { Debug.LogError("Vortex Application is not running") }

SimulationTime

Returns the current simulation time in seconds

private void FixedUpdate() { double timeIncrement = Vortex.VortexApplication.Instance.SimulationTime - previousTime; playableDirector.time += timeIncrement; previousTime = VortexApplication.Instance.SimulationTime; }

SimulationTimeStep

Returns the simulation time step in seconds. This is how much time is increased at every update, the inverse of the frame rate.

private void FixedUpdate() { // this assumes that Vortex and Unity is absolutely in sync, which may not be the case in a distributed simulator elapsedTime += Vortex.VortexApplication.Instance.SimulationTimeStep; }

FrameIndex

Returns the current frame index. It is increased by one at each Update() of the simulation.

private void FixedUpdate() { if (triggerExplosion) { triggerExplosion = false; expolosionFrame = Vortex.VortexApplication.Instance.FrameIndex; } }

IsPaused

Determines whether the simulation is actually paused

private void FixedUpdate() { if (triggerExplosion && !Vortex.VortexApplication.Instance.IsPaused) { triggerExplosion = false; expolosionFrame = Vortex.VortexApplication.Instance.FrameIndex; } }

IsMaster

Determines if the current Vortex application is the master

private void FixedUpdate() { if (Vortex.VortexApplication.Instance.IsMaster) { // lengthy calculation is done only once on master var results = performComplexCalculation(); writeResultsToVHL(results); } else { // Slaves are reading the results and modifying graphics accordingly var results = readResultsFromVHL(); applyToGraphics(results); } }

SelectedLanguage

Returns the currently selected language and country code (LL_CC), or an empty string if no locale was selected.

This functionality requires a ConsoleModule properly configured.

 

private void OnEnabled() { string langauge = VortexApplication.Instance.SelectedLanguage; if ( string.IsNullOrEmpty(language) ) { Debug.LogError("Please select a language"); } }

Public Methods

 

public bool SetApplicationMode(Vortex.ApplicationMode mode, bool waitForModeToBeApplied)

Changes the application mode asynchronously. The application mode will change when possible by default. It is possible to wait for the mode to actually change by using the waitForModeToBeApplied parameter. à

Returns True if the requested application mode is valid in the current context.

public bool StartSimulation();

Sets the ApplicationMode to Simulation

public bool StopSimulation();

Sets the ApplicationMode to Editing

public bool PauseSimulation(bool pause)

Pauses the simulation. It will be effective at the next application update.

public void StepOnce()

Makes the simulation do one step and then pause.VC

public string Translate(string context, string text)

Translate the given text, with the given context.

This functionality requires a ConsoleModule properly configured.

 

Related content