pub trait SimState: WasmNotSend + 'static {
Show 14 methods
// Required methods
fn step(&mut self);
fn tick(&self) -> u64;
fn stats(&self) -> Vec<StatEntry>;
fn set_param(&mut self, index: usize, value: &ParamValue) -> bool;
fn population(&self) -> u64;
fn heap_bytes(&self) -> usize;
// Provided methods
fn grid_view(&self) -> Option<GridView<'_>> { ... }
fn point_view(&self) -> Option<PointView<'_>> { ... }
fn edge_view(&self) -> Option<EdgeView<'_>> { ... }
fn prepare_view(&mut self) { ... }
fn act(&mut self, _index: usize) -> bool { ... }
fn set_layout(&mut self, _on: bool, _budget_ms: f32) -> bool { ... }
fn relax_layout(&mut self) { ... }
fn parallel_jobs(&self) -> Option<usize> { ... }
}Expand description
A running simulation, as the runner drives it.
The trait is object-safe, and a model entry type-erases every model behind it. A model implements one of the authoring traits, and the engine implements this trait.
Required Methods§
Sourcefn stats(&self) -> Vec<StatEntry>
fn stats(&self) -> Vec<StatEntry>
Returns the current statistics, one entry per declared series.
Sourcefn set_param(&mut self, index: usize, value: &ParamValue) -> bool
fn set_param(&mut self, index: usize, value: &ParamValue) -> bool
Sets parameter index to value, and returns whether the state accepted the edit.
A state rejects an edit to a parameter declared ParamApply::OnReload.
Sourcefn population(&self) -> u64
fn population(&self) -> u64
Size of the population: its cells, its agents or its live nodes.
Sourcefn heap_bytes(&self) -> usize
fn heap_bytes(&self) -> usize
Approximate size in bytes of the memory this state owns, on the host for a CPU state and on the device for a GPU state.
Provided Methods§
Sourcefn grid_view(&self) -> Option<GridView<'_>>
fn grid_view(&self) -> Option<GridView<'_>>
Returns the grid layer to draw, if the state has one.
A state can return both a grid and agents from SimState::point_view, and the agents are then drawn
over the field.
Sourcefn point_view(&self) -> Option<PointView<'_>>
fn point_view(&self) -> Option<PointView<'_>>
Returns the agents to draw, if the state has any.
Sourcefn edge_view(&self) -> Option<EdgeView<'_>>
fn edge_view(&self) -> Option<EdgeView<'_>>
Returns the edges to draw between the positions from SimState::point_view.
Sourcefn prepare_view(&mut self)
fn prepare_view(&mut self)
Prepares the views before a snapshot is built.
A model turns its state into something drawable here, without paying for it every tick.
Sourcefn act(&mut self, _index: usize) -> bool
fn act(&mut self, _index: usize) -> bool
Runs the model’s action at index, between ticks, and returns whether it ran.
It returns false when the model declares no such action.
Sourcefn set_layout(&mut self, _on: bool, _budget_ms: f32) -> bool
fn set_layout(&mut self, _on: bool, _budget_ms: f32) -> bool
Turns the layout on or off, with a time budget per publish in milliseconds.
Returns false if the state has no layout.
Sourcefn relax_layout(&mut self)
fn relax_layout(&mut self)
Runs the layout for one time budget, if it is on.
The runner decides which publishes call this.
Sourcefn parallel_jobs(&self) -> Option<usize>
fn parallel_jobs(&self) -> Option<usize>
Number of jobs that one step splits into. None if a backend has no such split.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".