Search Results for

    Show / Hide Table of Contents

    Class WaveFunctionCollapser

    This object manages a run of the wave function collapse algorithm applied to 3D autotiling.

    Inheritance
    System.Object
    WaveFunctionCollapser
    Inherited Members
    System.Object.ToString()
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    Namespace: CarbideFunction.Wildtile
    Syntax
    public class WaveFunctionCollapser

    Constructors

    WaveFunctionCollapser(IReadOnlyList<Module>, FaceLayoutIndex[], FaceLayoutIndex[], Int32)

    Create a wave function collapser instance. This is designed to be used with the fields from a Tileset asset.

    Declaration
    public WaveFunctionCollapser(IReadOnlyList<Module> modules, FaceLayoutIndex[] horizontalFaceToRequiredFace, FaceLayoutIndex[] verticalFaceToRequiredFace, int seed)
    Parameters
    Type Name Description
    System.Collections.Generic.IReadOnlyList<Module> modules
    FaceLayoutIndex[] horizontalFaceToRequiredFace
    FaceLayoutIndex[] verticalFaceToRequiredFace
    System.Int32 seed

    Methods

    Collapse(SlotGrid, WaveFunctionCollapser.ReportCollapseResult, PropagationReporting.ReportContradictionSlot, Boolean)

    Starts a coroutine that collapses the slot grid.

    The coroutine will call resultReporter by the end of the operation. It will call with Success if the algorithm successfully collapsed the operatingGrid to have one module in all non-wildcard slots, otherwise it will call with UnrecoverableContradiction.

    Declaration
    public IEnumerable<CoroutineStatus> Collapse(SlotGrid operatingGrid, WaveFunctionCollapser.ReportCollapseResult resultReporter, PropagationReporting.ReportContradictionSlot contradictionReporter = null, bool rewindAfterCollapse = false)
    Parameters
    Type Name Description
    SlotGrid operatingGrid

    The grid of slots that should be collapsed. At the end of the coroutine, all non-wildcard slots will have one module remaining if the grid was collapsible and if rewindAfterCollapse was false, otherwise it will return to its state when the coroutine started. During the coroutine, the slots may lose and gain modules - these can be read (e.g. for animating the collapse) but writing to the slots during the coroutine may cause it to crash.

    This coroutine will not affect the slots' wildness.

    WaveFunctionCollapser.ReportCollapseResult resultReporter

    A delegate that will be called once during the coroutine, reporting if the algorithm successfully collapsed all non-wildcard slots to a single available module.

    PropagationReporting.ReportContradictionSlot contradictionReporter

    A delegate that will be called an unknown number of times during the coroutine, reporting any contradictions that cause the algorithm to rewind.

    System.Boolean rewindAfterCollapse

    If true, guarantees that the operatingGrid will be returned to its original state even if the collapse was successful.

    Returns
    Type Description
    System.Collections.Generic.IEnumerable<CoroutineStatus>

    InitialPropagateAndCollapseWithWildcardRetreatAndAdvance(SlotGrid)

    Starts a coroutine that force-collapses the operatingGrid, making slots wildcards where necessary.

    This algorithm safely adds wildcards where slots have no available modules.

    It attempts to reduce the number of wildcards in the grid, but it is not guaranteed to give the fewest possible wildcards for every grid.

    Declaration
    public IEnumerable<CoroutineStatus> InitialPropagateAndCollapseWithWildcardRetreatAndAdvance(SlotGrid operatingGrid)
    Parameters
    Type Name Description
    SlotGrid operatingGrid

    The grid of slots that should be collapsed. At the end of the coroutine, all non-wildcard slots will have one module remaining. During the coroutine, the slots may lose and gain modules and their wildness may change - these can be read (e.g. for animating the collapse) but writing to the slots during the coroutine may cause it to crash.

    Returns
    Type Description
    System.Collections.Generic.IEnumerable<CoroutineStatus>

    PropagateAll(SlotGrid, PropagationReporting.ReportPropagationResult, PropagationReporting.ReportContradictionSlot, List<KeyValuePair<Slot, List<TransformedModule>>>)

    Start running a coroutine of the algorithm.

    Declaration
    public IEnumerable<CoroutineStatus> PropagateAll(SlotGrid operatingGrid, PropagationReporting.ReportPropagationResult resultReporter, PropagationReporting.ReportContradictionSlot reportContradictions, List<KeyValuePair<Slot, List<TransformedModule>>> removedModules)
    Parameters
    Type Name Description
    SlotGrid operatingGrid
    PropagationReporting.ReportPropagationResult resultReporter
    PropagationReporting.ReportContradictionSlot reportContradictions
    System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<Slot, System.Collections.Generic.List<TransformedModule>>> removedModules
    Returns
    Type Description
    System.Collections.Generic.IEnumerable<CoroutineStatus>

    A coroutine that will collapse the slots in operatingGrid.

    PropagateAllAndCollapseAndRewind(SlotGrid, WaveFunctionCollapser.ReportCollapseResult)

    Starts a coroutine that calculates if the operatingGrid is collapsible from its original state and emits the result to resultReporter

    Always rewinds the slot grid back to the state it was when the coroutine was started. This function reads wildcard status, but does not change it.

    Declaration
    public IEnumerable<CoroutineStatus> PropagateAllAndCollapseAndRewind(SlotGrid operatingGrid, WaveFunctionCollapser.ReportCollapseResult resultReporter)
    Parameters
    Type Name Description
    SlotGrid operatingGrid

    The slot grid to operate on. During the coroutine, the slots' modules may change - these can be read (e.g. for animating the collapse) but writing to the slots during the coroutine may cause it to crash.

    WaveFunctionCollapser.ReportCollapseResult resultReporter

    Once per coroutine this delegate will be called with the result of the calculation.

    Returns
    Type Description
    System.Collections.Generic.IEnumerable<CoroutineStatus>
    In This Article
    Generated by DocFX Wildtile Documentation