pub trait GridModel:
Send
+ Sync
+ 'static {
type Params: Send + Sync;
const NAME: &'static str;
const ID: &'static str;
const DESCRIPTION: &'static str;
const PALETTE: &'static [[u8; 4]];
const NEIGHBORHOOD: NeighborhoodKind;
const STATS: &'static [StatDescriptor];
const ACTIONS: &'static [ActionDescriptor] = _;
// Required methods
fn param_descriptors() -> Vec<ParamDescriptor>;
fn from_params(params: &[ParamValue]) -> Self::Params;
fn init(grid: &mut Grid2D<u8>, params: &[ParamValue], rng: &mut u64);
fn step_cell(
cell: u8,
neighbors: &[u8],
params: &Self::Params,
rng: &mut u64,
) -> u8;
fn stats(grid: &Grid2D<u8>) -> Vec<StatValue>;
// Provided method
fn act(
_action: usize,
_grid: &mut Grid2D<u8>,
_params: &[ParamValue],
_rng: &mut u64,
) { ... }
}Expand description
A cellular automaton over u8 cells.
The engine owns grid allocation, double buffering, chunking, tick counting, the views, and the
whole SimState impl.
Required Associated Constants§
Sourceconst ID: &'static str
const ID: &'static str
Stable id that identifies the model in a model set, on the command line and in a spec file.
Sourceconst DESCRIPTION: &'static str
const DESCRIPTION: &'static str
One-line description shown in the UI.
Sourceconst NEIGHBORHOOD: NeighborhoodKind
const NEIGHBORHOOD: NeighborhoodKind
Neighbourhood whose cells Self::step_cell receives.
Sourceconst STATS: &'static [StatDescriptor]
const STATS: &'static [StatDescriptor]
Stat series for the history chart. Declared once, so stats returns bare values.
Provided Associated Constants§
Sourceconst ACTIONS: &'static [ActionDescriptor] = _
const ACTIONS: &'static [ActionDescriptor] = _
One-off steps the user can trigger. Each gets a button in the Parameters panel.
Required Associated Types§
Required Methods§
Sourcefn param_descriptors() -> Vec<ParamDescriptor>
fn param_descriptors() -> Vec<ParamDescriptor>
Model parameters. The engine prepends grid width and height, but never shows them here.
Sourcefn from_params(params: &[ParamValue]) -> Self::Params
fn from_params(params: &[ParamValue]) -> Self::Params
Extracts the hot parameters for one tick. params is this model’s own slice, so its indices are 0 based.
Sourcefn init(grid: &mut Grid2D<u8>, params: &[ParamValue], rng: &mut u64)
fn init(grid: &mut Grid2D<u8>, params: &[ParamValue], rng: &mut u64)
Fills the grid for a new run.
params is this model’s own slice, as for Self::from_params.
Sourcefn step_cell(
cell: u8,
neighbors: &[u8],
params: &Self::Params,
rng: &mut u64,
) -> u8
fn step_cell( cell: u8, neighbors: &[u8], params: &Self::Params, rng: &mut u64, ) -> u8
Returns the next value of cell, given its neighbours.
neighbors follows the order of MOORE_ROW_MAJOR or VON_NEUMANN, as Self::NEIGHBORHOOD picks.
The function must be pure apart from rng, since the engine steps rows in parallel.
Provided Methods§
Sourcefn act(
_action: usize,
_grid: &mut Grid2D<u8>,
_params: &[ParamValue],
_rng: &mut u64,
)
fn act( _action: usize, _grid: &mut Grid2D<u8>, _params: &[ParamValue], _rng: &mut u64, )
Runs Self::ACTIONS entry action over the current cells.
Receives the arguments of init. An action is a setup step that the user requests mid run. rng
is a separate stream, so a press leaves the tick’s draws where they were.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".