Common snippets

These snippets are documented to help with common tasks in plugin development.

Get the vehicle position & velocity & yaw/pitch/roll

vec3 pos = simManager.Dyna.CurrentState.Location.Position;
vec3 velocity = simManager.Dyna.CurrentState.LinearSpeed;

float yaw, pitch, roll;
simManager.Dyna.CurrentState.Location.Rotation.GetYawPitchRoll(yaw, pitch, roll);

Load a command list script as the current one

CommandList list("inputs.txt");
list.Process();
SetCurrentCommandList(list);

Parse inputs from a command list script

CommandList list("inputs.txt");
list.Process(CommandListProcessOption::OnlyParse);
for (uint i = 0; i < list.InputCommands.Length; i++) {
    auto cmd = list.InputCommands[i];
    log(cmd.ToScript());
}

Convert current inputs to commands and save them into a file

CommandList list;
list.Content = simManager.InputEvents.ToCommandsText();
list.Save("inputs.txt");

Iterate current inputs

auto indices = simManager.InputEvents.EventIndices;
for (uint i = 0; i < simManager.InputEvents.Length; i++) {
    auto evt = simManager.InputEvents[i];
    if (evt.Value.EventIndex == indices.SteerId) {
        log("Steer at " + (evt.Time - 100010) + ": " + + evt.Value.Analog);
    } else if (evt.Value.EventIndex == indices.AccelerateId) {
        log("Accelerate at " + (evt.Time - 100010) + ": " + evt.Value.Binary);
    } else if (...) {
        ...
    }
}

Load a save state from a file and restore it

string error;
SimulationStateFile f;
if (!f.Load("state.bin", error)) {
    // Handle error
}

// Restore the full file with inputs and previous states
simManager.RewindToState(f);

// Alternatively, convert the file to a SimulationState (and restore without inputs or previous states)
simManager.RewindToState(f.ToState());

Save a save state to a file from the current state

string error;
SimulationStateFile f;
f.CaptureCurrentState(simManager, true);
if (!f.Save("saved.bin", error)) {
    // Handle error
}

Display a custom window

void Render()
{
    if (UI::Begin("Custom Window")) {
        // Render controls
    }

    UI::End();
}