Skip to main content

BoidsModel

Struct BoidsModel 

Source
pub struct BoidsModel;
Expand description

Boids flocking as an AgentModel.

Trait Implementations§

Source§

impl AgentModel for BoidsModel

Source§

const CHUNK: usize = 64

Agents per chunk, smaller than the default since the kernel draws no random numbers and the population can be small. At 512, a thousand boids make two chunks and most of the pool sits idle.

Source§

fn index_cell_size(params: &BoidParams) -> f32

Returns a third of the visual range, so the walk covers about twice the disc it needs instead of about three times.

Source§

const NAME: &'static str = "Boids Flocking"

Name shown in the UI.
Source§

const ID: &'static str = "boids"

Stable id that identifies the model in a model set, on the command line and in a spec file.
Source§

const DESCRIPTION: &'static str = "A simulation of flocking behavior in a group of boids."

One-line description shown in the UI.
Source§

const PALETTE: &'static [[u8; 4]]

Agent colours. The field layer carries its own colours.
Source§

const STATS: &'static [StatDescriptor]

Stat series for the history chart. Declared once, so stats returns bare values.
Source§

const ACTIONS: &'static [ActionDescriptor] = ACTION_SPECS

One-off steps the user can trigger. Each gets a button in the Parameters panel.
Source§

const DEFAULT_AGENTS: u32 = 50_000

Default of num_agents.
Source§

const MAX_AGENTS: u32 = 1_000_000

Upper bound of num_agents.
Source§

const DEFAULT_EXTENT: Extent

Defaults of world_width and world_height.
Source§

type Lanes = BoidLanes

Agent storage, declared with agent_lanes!.
Source§

type Field = NoField

Grid layer under the population, or NoField for a model without a field.
Source§

type Index = SpatialHash

Neighbour index, SpatialHash when agents read each other and NoIndex otherwise.
Source§

type Params = BoidParams

Pre-extracted hot parameters, rebuilt once per tick.
Source§

type Tally = ()

Per chunk reduction, accumulated across ticks. () when there is nothing to count. Read more
Source§

fn param_descriptors() -> Vec<ParamDescriptor>

Model parameters. num_agents, world_width and world_height are prepended by the engine at indices 0, 1 and 2.
Source§

fn from_params(params: &[ParamValue], extent: Extent) -> BoidParams

Extracts the hot parameters for one tick. params is this model’s own slice, so its indices are 0 based and cannot shift when the engine or a field layer changes.
Source§

fn init( lanes: &mut BoidLanes, extent: Extent, params: &[ParamValue], rng: &mut u64, )

Fills the lanes for a new run. Read more
Source§

fn run_step_pass( lanes: &mut BoidLanes, ctx: &StepCtx<'_, Self>, seed: u64, tick: u64, )

Runs the step pass and returns its tally. Read more
Source§

fn act( action: usize, lanes: &mut BoidLanes, _field: &mut NoField, _extent: Extent, params: &[ParamValue], rng: &mut u64, )

Runs Self::ACTIONS entry action over the current lanes and field. Read more
Source§

fn stats(lanes: &BoidLanes, _field: &NoField, (): &()) -> Vec<StatValue>

Current statistics, in Self::STATS order.
Source§

fn run_deposit_pass( _lanes: &Self::Lanes, _deposits: &mut <Self::Field as FieldLayer>::DepositLanes, _ctx: &StepCtx<'_, Self>, )

Fills the field’s deposit lanes before the step pass, without moving any agent. Read more
Source§

impl Debug for BoidsModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WasmNotSync for T
where T: Sync,