[][src]Struct swarm_it::Swarm

pub struct Swarm<T: PartialEq + Eq + Hash + Copy> { /* fields omitted */ }

Main struct that allow you to talk to the library

Methods

impl<T: PartialEq + Eq + Hash + Copy> Swarm<T>[src]

pub fn new() -> Swarm<T>[src]

Constructs a new Swarm.

T - the type of cargo that your carriers will carry around. The Copy bound is going to be removed in future versions.

Example

let game = swarm_it::Swarm::<char>::new();

pub fn add_carrier(&mut self, carrier: Carrier<T>) -> usize[src]

Adds new carrier. Returns the index of the new carrier.

Example

use swarm_it::*;
let mut game = Swarm::<char>::new();
game.add_carrier(Carrier::new(100.0, 200.0));

pub fn add_slot(&mut self, slot: Slot<T>) -> usize[src]

Adds new slot. Returns the index of the new slot.

Example

use swarm_it::*;
let mut game = Swarm::<char>::new();
game.add_slot(Slot::new(100.0, 100.0, None, Some(Payload::new('X')), swarm_it::SlotKind::CLASSIC));

pub fn get_carriers(&self) -> &Vec<Carrier<T>>[src]

Returns all carriers

pub fn get_carriers_mut(&mut self) -> &mut Vec<Carrier<T>>[src]

Returns all carriers

pub fn get_slots(&self) -> &Vec<Slot<T>>[src]

Returns all slots

pub fn get_slots_mut(&mut self) -> &mut Vec<Slot<T>>[src]

Returns all slots

pub fn tick(&mut self) -> bool[src]

The engine must be regularly ticked by the outside world by invoking this function. At each tick swarm will perform calculation of the internal state logic, move carriers around, etc.

Returns true if there were no more action required, meaning that carriers have finished tranferring the layout to target position.

Example

use swarm_it::*;
let mut game = Swarm::<char>::new();
if game.tick() { println!("Job finished, yay!"); };

pub fn slot_data_changed(&mut self)[src]

Initiates some precalculation in order for the carriers to be aware of modified slots. Call this function each time you finished adding new slots or manually manipulating their data through get_slots_mut().

In the future I might eventually remove this obligation, but I need to come up with some clever way of deciding whether a precalc is needed or not. Invoking precalc after each single change is an overkill, since one might want to add 100k slots and do the precalc only once at the end.

Example

use swarm_it::*;
let mut game = Swarm::<char>::new();
game.slot_data_changed();

TODO

Different kind of that may change. Provide additional parameter in order NOT to precalculate everything

  1. Slot payload => recalculate cargo balance
  2. Slots added/removed => recalculate slot distances

Trait Implementations

impl<T: Default + PartialEq + Eq + Hash + Copy> Default for Swarm<T>[src]

Auto Trait Implementations

impl<T> Send for Swarm<T> where
    T: Send

impl<T> Sync for Swarm<T> where
    T: Sync

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,