public void Collapse(WfcCell <TModule, TPosition> cell, Func <WfcCell <TModule, TPosition>, TModule> moduleSelectionFunc, Action <WfcSpace <TModule, TPosition>, TModule> onModuleSelected) { TModule selectedModule = moduleSelectionFunc.Invoke(cell); cell.AvailableModules.RemoveAll(tile => tile != selectedModule); onModuleSelected.Invoke(this, selectedModule); PropagateResult(cell); }
public void PropagateGlobally() { Stack <WfcCell <TModule, TPosition> > updateStack = new (GetCells()); while (updateStack.Any()) { WfcCell <TModule, TPosition> currentCell = updateStack.Pop(); var wereElementsRemoved = currentCell.RemoveInvalidModules(this); if (wereElementsRemoved) { GetNeighbors(currentCell).ForEach(wfcCell => updateStack.Push(wfcCell)); } } }
protected virtual void PropagateResult(WfcCell <TModule, TPosition> cell) { Stack <WfcCell <TModule, TPosition> > updateStack = new (GetNeighbors(cell)); while (updateStack.Any()) { WfcCell <TModule, TPosition> currentCell = updateStack.Pop(); var wereElementsRemoved = currentCell.RemoveInvalidModules(this); if (wereElementsRemoved) { GetNeighbors(currentCell).ForEach(wfcCell => updateStack.Push(wfcCell)); } } }
public abstract List <WfcCell <TModule, TPosition> > GetNeighbors(WfcCell <TModule, TPosition> cell);
public void Collapse(WfcCell <TModule, TPosition> cell) { Collapse(cell, wfcCell => RandomSelector(wfcCell.AvailableModules), (space, module) => {}); }
public void Collapse(WfcCell <TModule, TPosition> cell, Action <WfcSpace <TModule, TPosition>, TModule> onModuleSelected) { Collapse(cell, wfcCell => RandomSelector(wfcCell.AvailableModules), onModuleSelected); }