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>,
impl<'a, TBitSet> WfcContext<'a, TBitSet>where
TBitSet: BitSearch + BitEmpty + BitSet + BitIntersection + BitUnion + BitTestNone + Hash + Eq + Copy + BitIntersection<Output = TBitSet> + BitUnion<Output = TBitSet>,
Sourcepub fn local_collapse(
&mut self,
row: usize,
column: usize,
module: usize,
result_transmitter: Sender<Result<Vec<usize>, WfcError>>,
)
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
Sourcepub fn set_module(&mut self, row: usize, column: usize, module: usize)
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?
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 }Sourcepub fn collapse(
&mut self,
max_contradictions: i32,
result_transmitter: Sender<Result<Vec<usize>, WfcError>>,
)
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?
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
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 }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 }