WfcContext

Struct WfcContext 

Source
pub struct WfcContext<'a, TBitSet>
where TBitSet: BitSearch + BitEmpty + BitSet + BitIntersection + BitUnion + BitTestNone + Hash + Eq + Copy + BitIntersection<Output = TBitSet> + BitUnion<Output = TBitSet>,
{ /* private fields */ }
Expand description

A heart of WFC. Does an actual collapse work

Implementations§

Source§

impl<'a, TBitSet> WfcContext<'a, TBitSet>
where TBitSet: BitSearch + BitEmpty + BitSet + BitIntersection + BitUnion + BitTestNone + Hash + Eq + Copy + BitIntersection<Output = TBitSet> + BitUnion<Output = TBitSet>,

Source

pub fn local_collapse( &mut self, row: usize, column: usize, module: usize, result_transmitter: Sender<Result<Vec<usize>, WfcError>>, )

A function which lets a user to “draw” some new parts above existing collapse result

When the work is done, the result is being sent through result_transmitter to a corresponding receiver

The successful result is composed of a vec with a size = (self.width * self.height) indices of modules which have been chosen of corresponding slots during collapse

Source

pub fn set_module(&mut self, row: usize, column: usize, module: usize)

A function which lets a user to “preset” some modules before doing actual collapse

Examples found in repository?
examples/dungeon.rs (line 358)
349    pub fn generate_new_map(&mut self) {
350        let mut wfc_context: WfcContext<CustomBitSet> = WfcContextBuilder
351            ::new(&self.modules, self.w, self.h)
352            .build();
353
354        let (tx, rc) = channel();
355
356        // Preset some fields in a map with a void to enforce more island-ish look
357        {
358            wfc_context.set_module(0, 0, 0);
359            wfc_context.set_module(self.h - 1, 0, 0);
360            wfc_context.set_module(0, self.w - 1, 0);
361            wfc_context.set_module(self.h - 1, self.w - 1, 0);
362            wfc_context.set_module(self.h / 2, self.w / 2, 0);
363        }
364
365        wfc_context.collapse(100, tx.clone());
366
367        let results = rc.recv()
368            .unwrap()
369            .unwrap_or_else(|_| vec![0; self.w * self.h]);
370
371        self.map_data.clear();
372        for &idx in results.iter() {
373            let random_id = rand::gen_range(0, self.tiles[idx].subrects.len());
374            self.map_data.push((idx, random_id));
375        }
376    }
Source

pub fn collapse( &mut self, max_contradictions: i32, result_transmitter: Sender<Result<Vec<usize>, WfcError>>, )

A function which is making actual collapse

When the work is done, the result is being sent through result_transmitter to a corresponding receiver

The successful result is composed of a vec with a size = (self.width * self.height) indices of modules which have been chosen of corresponding slots during collapse

Examples found in repository?
examples/wang_corner_carpet.rs (line 159)
152    pub fn generate_new_map(&mut self) {
153        let mut wfc_context: WfcContext<CustomBitSet> = WfcContextBuilder
154        ::new(&self.modules, self.w, self.h)
155            .build();
156
157        let (tx, rc) = channel();
158
159        wfc_context.collapse(100, tx.clone());
160
161        let results = rc.recv()
162            .unwrap()
163            .unwrap_or_else(|_| vec![0; self.w * self.h]);
164
165        self.map_data.clear();
166        self.map_data.extend_from_slice(&results[..]);
167    }
More examples
Hide additional examples
examples/summer_garden.rs (line 425)
418    pub fn generate_new_map(&mut self) {
419        let mut wfc_context: WfcContext<CustomBitSet> = WfcContextBuilder
420        ::new(&self.modules, self.w, self.h)
421            .build();
422
423        let (tx, rc) = channel();
424
425        wfc_context.collapse(100, tx.clone());
426
427        let results = rc.recv()
428            .unwrap()
429            .unwrap_or_else(|_| vec![0; self.w * self.h]);
430
431        self.map_data.clear();
432        self.map_data.extend_from_slice(&results[..]);
433
434        self.plant_trees()
435    }
examples/dungeon.rs (line 365)
349    pub fn generate_new_map(&mut self) {
350        let mut wfc_context: WfcContext<CustomBitSet> = WfcContextBuilder
351            ::new(&self.modules, self.w, self.h)
352            .build();
353
354        let (tx, rc) = channel();
355
356        // Preset some fields in a map with a void to enforce more island-ish look
357        {
358            wfc_context.set_module(0, 0, 0);
359            wfc_context.set_module(self.h - 1, 0, 0);
360            wfc_context.set_module(0, self.w - 1, 0);
361            wfc_context.set_module(self.h - 1, self.w - 1, 0);
362            wfc_context.set_module(self.h / 2, self.w / 2, 0);
363        }
364
365        wfc_context.collapse(100, tx.clone());
366
367        let results = rc.recv()
368            .unwrap()
369            .unwrap_or_else(|_| vec![0; self.w * self.h]);
370
371        self.map_data.clear();
372        for &idx in results.iter() {
373            let random_id = rand::gen_range(0, self.tiles[idx].subrects.len());
374            self.map_data.push((idx, random_id));
375        }
376    }

Auto Trait Implementations§

§

impl<'a, TBitSet> Freeze for WfcContext<'a, TBitSet>

§

impl<'a, TBitSet> !RefUnwindSafe for WfcContext<'a, TBitSet>

§

impl<'a, TBitSet> !Send for WfcContext<'a, TBitSet>

§

impl<'a, TBitSet> !Sync for WfcContext<'a, TBitSet>

§

impl<'a, TBitSet> Unpin for WfcContext<'a, TBitSet>
where TBitSet: Unpin,

§

impl<'a, TBitSet> !UnwindSafe for WfcContext<'a, TBitSet>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V