Class SimulationExtension
- Namespace
- NominalSystems.Universe
- Assembly
- NominalSystems.Universe.dll
[Nominal] The simulation extension provides additional functionality to the simulation for accessing objects, adding objects, and updating the simulation using more appropriate tick events.
public static class SimulationExtension
- Inheritance
-
SimulationExtension
Methods
AddSchematic(Simulation?)
Adds a new schematic to the controller of a particular type.
public static Schematic? AddSchematic(this Simulation? simulation)
Parameters
simulation
SimulationA reference to the simulation
Returns
- Schematic
The schematic that was created
ForceUpdate(UniverseEvent)
Force update universe object
public static void ForceUpdate(this UniverseEvent src)
Parameters
src
UniverseEvent
GetCurrentSeconds(Simulation)
Returns the current time of the simulation in seconds, which is converted from the raw nanoseconds stored in the simulation clock.
public static double GetCurrentSeconds(this Simulation simulation)
Parameters
simulation
SimulationThe simulation reference
Returns
- double
[s] The time of the simulation in seconds
GetDatabaseHistory(SQLiteConnection?, Object, string, double, double, double)
Returns the database history for a particular variable on a particular object. This assumes that the simulation database contains data for that object and that particular variable.
public static string[] GetDatabaseHistory(SQLiteConnection? connection, Simulation.Object obj, string variable, double startTime, double endTime, double resolution)
Parameters
connection
SQLiteConnectionThe SQLite connection
obj
Simulation.ObjectThe object to grab the history of
variable
stringThe variable name to grab the history of
startTime
doubleThe start time, in seconds, to fetch the data from
endTime
doubleThe end time, in seconds, to fetch the data from. If less than 0, then there is no end
resolution
doubleThe resolution in seconds to store the data in
Returns
- string[]
The array of variable variants from the history
GetIsRunning(Simulation)
Returns whether the simulation is still running or whether it has reached the end of its life.
public static bool GetIsRunning(this Simulation simulation)
Parameters
simulation
SimulationThe simulation reference
Returns
- bool
The is running flag
GetObjects(Simulation)
Returns a list of Nominal Systems objects in the simulation. This will not be of a particular type, but will be of the base type and will return all objects and messages added.
public static Simulation.Object[] GetObjects(this Simulation simulation)
Parameters
simulation
SimulationThe simulation reference
Returns
- Object[]
An array of all objects in the simulation, in the order they were added
GetSchematics(Simulation)
Returns a list of schematics that exist within the simulation. This will be an exhaustive list.
public static Schematic[] GetSchematics(this Simulation simulation)
Parameters
simulation
SimulationThe simulation reference
Returns
- Schematic[]
An array of all schematics in the simulation
GetSystem(Simulation, Type)
Returns a reference to a universe system added to the simulation. If it does not yet exist, it will create the object and attach it to the controller as a universe system should always exist. This works for a defined type.
public static UniverseSystem GetSystem(this Simulation simulation, Type type)
Parameters
simulation
SimulationThe simulation reference
type
TypeThe universe system type to fetch
Returns
- UniverseSystem
The universe system object from the controller
GetSystem<T>(Simulation)
Returns a reference to a universe system added to the simulation. If it does not yet exist, it will create the object and attach it to the controller as a universe system should always exist.
public static T GetSystem<T>(this Simulation simulation) where T : UniverseSystem
Parameters
simulation
SimulationThe simulation reference
Returns
- T
The universe system object from the controller
Type Parameters
T
The universe system type to fetch
InitializeSimulation(Simulation)
Initializes the simulation by updating the universe event controller. This should be called before the first tick and will ensure that the simulation is correctly initialized and an update step is called on all components for the purpose of the saving and loading system.
public static void InitializeSimulation(this Simulation simulation)
Parameters
simulation
SimulationThe simulation reference
IsModelSupported(Type, Type)
Returns whether a universe model can be attached to a particular universe class. If the class is not supported, this will return false.
public static bool IsModelSupported(Type modelClass, Type objectClass)
Parameters
Returns
- bool
A supported flag and enables adding of the class
IsParentSupported(Type, Type)
Returns whether a child class is supported by a parent class. If the class is not supported, this will return false. If there is no attribute, it will be assumed to be supported.
public static bool IsParentSupported(Type childClass, Type parentClass)
Parameters
Returns
- bool
A supported flag and enables adding of the class
LoadFromDatabase(Simulation, SQLiteConnection?, double)
Attempts to load the data from a database into the simulation object. This will require an SQLite database.
public static bool LoadFromDatabase(this Simulation simulation, SQLiteConnection? connection, double time)
Parameters
simulation
SimulationThe simulation object to load
connection
SQLiteConnectionThe SQLite database connection
time
double[s] The time to fetch the data from
Returns
- bool
A successful load operation
LoadFromFile(Simulation, string)
Loads the simulation state from a file. This will attempt to update every value in the simulation state to match the values in the file.
public static bool LoadFromFile(this Simulation simulation, string path)
Parameters
simulation
SimulationThe simulation reference to load to
path
stringThe full file path of the file to load
Returns
- bool
A successful load operation
LoadFromJson(Simulation, JObject)
Loads the simulation state from a JSON. This will attempt to update every value in the simulation state to match the values in the JSON.
public static bool LoadFromJson(this Simulation simulation, JObject json)
Parameters
simulation
SimulationThe simulation reference to load to
json
JObjectThe JSON object
Returns
- bool
A successful load operation
LoadFromString(Simulation, string)
Loads the simulation state from a string of JSON.
public static bool LoadFromString(this Simulation simulation, string json)
Parameters
simulation
SimulationThe simulation reference to load to
json
stringThe full JSON string
Returns
- bool
A successful load operation
RemoveSchematic(Simulation?, Schematic?)
Removes a schematic from the simulation
public static void RemoveSchematic(this Simulation? simulation, Schematic? schematic)
Parameters
simulation
SimulationA reference to the simulation
schematic
SchematicThe schematic to remove
SaveToDatabase(Simulation, SQLiteConnection?)
Saves the state of the simulation to a database file that has already been opened. If the connection is not valid, then this will return false.
public static bool SaveToDatabase(this Simulation simulation, SQLiteConnection? connection)
Parameters
simulation
SimulationThe simulation object to save
connection
SQLiteConnectionThe SQLite database connection
Returns
- bool
A successful save operation
SaveToFile(Simulation, string)
Saves the state of the simulation to a file at the specified path. This will save the current state and turn it into a JSON object, which will be written to the file at the path location.
public static bool SaveToFile(this Simulation simulation, string path)
Parameters
simulation
SimulationThe simulation object to save
path
stringThe full file path to the location of the save file
Returns
- bool
A successful save operation
SaveToJson(Simulation)
Saves the state of the simulation to a JSON object.
public static JObject SaveToJson(this Simulation simulation)
Parameters
simulation
SimulationThe simulation object to save
Returns
- JObject
The simulation JSON
SaveToString(Simulation)
Saves the state of the simulation to a string and returns the string of the simulation.
public static string SaveToString(this Simulation simulation)
Parameters
simulation
SimulationThe simulation object to save
Returns
- string
The simulation JSON string