Skip to main content

SimState

Trait SimState 

Source
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§

Source

fn step(&mut self)

Advances the state by one tick.

Source

fn tick(&self) -> u64

Number of ticks stepped so far.

Source

fn stats(&self) -> Vec<StatEntry>

Returns the current statistics, one entry per declared series.

Source

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.

Source

fn population(&self) -> u64

Size of the population: its cells, its agents or its live nodes.

Source

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§

Source

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.

Source

fn point_view(&self) -> Option<PointView<'_>>

Returns the agents to draw, if the state has any.

Source

fn edge_view(&self) -> Option<EdgeView<'_>>

Returns the edges to draw between the positions from SimState::point_view.

Source

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.

Source

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.

Source

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.

Source

fn relax_layout(&mut self)

Runs the layout for one time budget, if it is on.

The runner decides which publishes call this.

Source

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".

Implementors§