public InfiniteMap(int height) : base() { this.Height = height; this.slots = new Dictionary <Vector3Int, Slot>(); this.defaultColumn = new TilingMap(new Vector3Int(1, height, 1)); if (ModuleData.Current == null || ModuleData.Current.Length == 0) { throw new InvalidOperationException("Module data was not available, please create module data first."); } }
public override void ApplyBoundaryConstraints(IEnumerable <BoundaryConstraint> constraints) { this.defaultColumn = new TilingMap(new Vector3i(1, this.Height, 1)); foreach (var constraint in constraints) { int y = constraint.RelativeY; if (y < 0) { y += this.Height; } int[] directions = null; switch (constraint.Direction) { case BoundaryConstraint.ConstraintDirection.Up: directions = new int[] { 4 }; break; case BoundaryConstraint.ConstraintDirection.Down: directions = new int[] { 1 }; break; case BoundaryConstraint.ConstraintDirection.Horizontal: directions = Orientations.HorizontalDirections; break; } foreach (int d in directions) { switch (constraint.Mode) { case BoundaryConstraint.ConstraintMode.EnforceConnector: this.defaultColumn.GetSlot(new Vector3i(0, y, 0)).EnforceConnector(d, constraint.Connector); break; case BoundaryConstraint.ConstraintMode.ExcludeConnector: this.defaultColumn.GetSlot(new Vector3i(0, y, 0)).ExcludeConnector(d, constraint.Connector); break; } } } foreach (var slot in this.defaultColumn.GetAllSlots()) { float _ = slot.Modules.Entropy; // Inititalize cached value } }
public void SimplifyNeighborData() { ModuleData.Current = this.Modules; const int height = 12; int count = 0; var center = new Vector3Int(0, height / 2, 0); int p = 0; foreach (var module in this.Modules) { // TODO Import seed var map = new TilingMap(new Vector3Int(6, 6, 6), 0); var slot = map.GetSlot(center); try { slot.Collapse(module); } catch (CollapseFailedException exception) { throw new InvalidOperationException("Module " + module.Name + " creates a failure at relative position " + (exception.Slot.Position - center) + "."); } for (int direction = 0; direction < 6; direction++) { var neighbor = slot.GetNeighbor(direction); int unoptimizedNeighborCount = module.PossibleNeighbors[direction].Count; module.PossibleNeighbors[direction].Intersect(neighbor.Modules); count += unoptimizedNeighborCount - module.PossibleNeighbors[direction].Count; } module.PossibleNeighborsArray = module.PossibleNeighbors.Select(ms => ms.ToArray()).ToArray(); p++; EditorUtility.DisplayProgressBar("Simplifying... " + count, module.Name, (float)p / this.Modules.Length); } Debug.Log("Removed " + count + " impossible neighbors."); EditorUtility.ClearProgressBar(); EditorUtility.SetDirty(this); AssetDatabase.SaveAssets(); }