pub struct TileSetWfcConstraint(/* private fields */);Expand description
A hash table based wave function collapse constraint that maps PatternBits
objects to sets of TileDefinitionHandle. Each handle refers to a tile,
and each tile is assigned a pattern and a frequency. The sum of the frequencies
of all a pattern’s tiles becomes the frequency of the pattern, which is then
normalized into a probability between 0.0 and 1.0 for use as a constraint
for a TileSetWfcPropagator which will perform the wave function collapse.
Implementations§
Source§impl TileSetWfcConstraint
impl TileSetWfcConstraint
Sourcepub fn fill_pattern_map(
&mut self,
tile_set: &TileSet,
pattern_property: TileSetPropertyNine,
frequency_property: Option<TileSetPropertyF32>,
terrain_freq: &FxHashMap<TileTerrainId, f32>,
) -> Result<(), FillPatternMapError>
pub fn fill_pattern_map( &mut self, tile_set: &TileSet, pattern_property: TileSetPropertyNine, frequency_property: Option<TileSetPropertyF32>, terrain_freq: &FxHashMap<TileTerrainId, f32>, ) -> Result<(), FillPatternMapError>
Clear the data from this constraint and replace it with new data
based upon the given tile set and property UUIDs. All of the tiles
of the tile set are searched and each one’s pattern property is checked
for a center value that matches one of the keys of terrain_freq.
When such a tile is found, it is inserted into the map using the pattern property
value as the pattern and the frequency property value as the frequency.
tile_set: The tile set to iterate through.pattern_property: The UUID of a nine-slice property intile_setthat will be used for the pattern of each tile. The center value of the nine-slice is the terrain, unless the center value is 0, in which case the tile is ignored.frequency_property: The UUID of a float property intile_setthat will be used for the frequency of each tile. If None, then every tile has frequency 1.0.terrain_freq: A hash map of the terrains that will be used in wave function collapse. Tiles whose center value are not keys in this hash map will be ignored. Tiles whose center value are keys in this hash map will have their frequency multiplied by the corresponding value in the hash map to calculate the final frequency of the tile. This allows terrains to have their frequency weighted, and allows unwanted terrains to be excluded.
Note: Terrain 0 is treated specially. It has one pattern, the all-zeros default
PatternBits, and it corresponds to the empty tile. Tiles whose pattern value
have 0 in the center are presumed to be not intended to be part of the wave
function collapse, since 0 is the default value. The frequency of choosing empty
tiles in wave function collapse can be controlled by setting terrain_freq[0] to
some value.
Methods from Deref<Target = HashWfcConstraint<PatternBits, TileDefinitionHandle>>§
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Remove all data, reseting this object to empty so it is ready to be reused with new pattern data.
Sourcepub fn add(&mut self, pattern: Pat, frequency: f32, value: V)
pub fn add(&mut self, pattern: Pat, frequency: f32, value: V)
Add a new value to the data with the given pattern and frequency.
The frequency does not need to be between 0.0 and 1.0.
Frequencies of 0.0 or less will be silently ignored, and
frequencies will be automatically normalized into probabilities
when finalize is called.
Sourcepub fn finalize(&mut self)
pub fn finalize(&mut self)
Calculate the probability of each pattern based on the frequencies
of all values that were added with add.
The sum of the frequencies is calculated and then each frequency is
divided by the sum to normalize the frequencies into probabilities between
0.0 and 1.0.
Sourcepub fn finalize_with_terrain_normalization<Ter, F>(&mut self, terrain: F)
pub fn finalize_with_terrain_normalization<Ter, F>(&mut self, terrain: F)
Calculate the probability of each pattern based on the frequencies
of all values that were added with add.
Divide the frequency of each pattern by the total number of patterns
in that pattern’s terrain so that terrains with many patterns are not
given an advantage over terrains with few patterns.
The terrain function is used to determine the terrain of each pattern.
The sum of the frequencies is calculated and then each frequency is
divided by the sum to normalize the frequencies into probabilities between
0.0 and 1.0.
Sourcepub fn get_random<R>(&self, rng: &mut R, pattern: &Pat) -> Option<&V>
pub fn get_random<R>(&self, rng: &mut R, pattern: &Pat) -> Option<&V>
A random value that matches the given pattern, based upon previous calls to
add. Often there may be more than one tile that matches a particular
pattern, and so this method helps with the final step after wave function collapse:
converting the chosen patterns into actual tiles.
Trait Implementations§
Source§impl Default for TileSetWfcConstraint
impl Default for TileSetWfcConstraint
Source§fn default() -> TileSetWfcConstraint
fn default() -> TileSetWfcConstraint
Source§impl Deref for TileSetWfcConstraint
impl Deref for TileSetWfcConstraint
Source§type Target = HashWfcConstraint<PatternBits, TileDefinitionHandle>
type Target = HashWfcConstraint<PatternBits, TileDefinitionHandle>
Auto Trait Implementations§
impl Freeze for TileSetWfcConstraint
impl RefUnwindSafe for TileSetWfcConstraint
impl Send for TileSetWfcConstraint
impl Sync for TileSetWfcConstraint
impl Unpin for TileSetWfcConstraint
impl UnwindSafe for TileSetWfcConstraint
Blanket Implementations§
Source§impl<T> AsyncTaskResult for T
impl<T> AsyncTaskResult for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T, U> ObjectOrVariant<T> for Uwhere
PhantomData<U>: ObjectOrVariantHelper<T, U>,
impl<T, U> ObjectOrVariant<T> for Uwhere
PhantomData<U>: ObjectOrVariantHelper<T, U>,
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.