public bool MoveNext() { while (true) { while (_entryEnum == null || !_entryEnum.MoveNext()) { if (!_tileEnum.MoveNext()) { return(false); } BoxTile tile = Assert.NotNull(_tileEnum.Current); _entryEnum = _tree.GetTileEnumerator(this, tile.EnumElems()); } if (_searchBox == null) { return(true); } if (Assert.NotNull(Current).Box.Intersects(_searchBox)) { return(true); } } }
public void SpawnBox(BoxTile tile) { BoxCharacter box = Instantiate(boxPrefab, boxParent).GetComponent <BoxCharacter>(); box.Spawn(mapContainer, tile); boxes.Add(box); }
public void StopAt(BoxTile boxTile) { isMoving = false; gifController.Play("Idle"); this.currentTile = boxTile; this.destination = transform.position; }
public void TileMEnter(BoxTile tile) { foreach (BoxTile t in allTiles) { t.tileImage.color = t.emptyColor; } List <BoxTile> selection = GetTileSelection(tile); bool validPlacement = true; foreach (BoxTile t in selection) { if (t == null) { validPlacement = false; break; } } foreach (BoxTile t in selection) { if (t == null) { continue; } if (validPlacement) { t.tileImage.color = Color.yellow; } else { t.tileImage.color = Color.red; } } }
private void CreateDoor(System.Random engine) { int rand = engine.Next(2, width - 7); tiles[rand][0] = new BoxTile(new Vector3Int(rand, 0, 0), 5); tiles[rand + 2][0] = new BoxTile(new Vector3Int(rand + 2, 0, 0), 15); }
public Box GetTile(IBox box, double maxSize) { if (_mainBox == null) { throw new InvalidOperationException("main box not initialized"); } VerifyExtent(box); IList <int> counter0 = null; IList <int> denominator = null; if (_unitBox != null) { GetPositions(out counter0, out denominator); } BoxTile addTile = FindAddTile(_mainTile, box, true, counter0, denominator); while (addTile.MaxInParentSplitDim - addTile.MinInParentSplitDim > maxSize) { addTile.Split(_unitBox, counter0, denominator, _mainCounter, _mainSize); BoxTile childTile = FindAddTile(addTile, box, false, counter0, denominator); if (childTile == addTile) { break; } addTile = childTile; } Box tileBox = GetBox(addTile); return(tileBox); }
private Box GetBox([NotNull] BoxTile tile) { Pnt min = Pnt.Create(_dimension); Pnt max = Pnt.Create(_dimension); var handled = new bool[_dimension]; var nHandled = 0; BoxTile t = tile; while (t.Parent != null && nHandled < _dimension) { if (!handled[t.Parent.SplitDimension]) { min[t.Parent.SplitDimension] = t.MinInParentSplitDim; max[t.Parent.SplitDimension] = t.MaxInParentSplitDim; handled[t.Parent.SplitDimension] = true; nHandled++; } t = t.Parent; } if (nHandled < _dimension) { for (var iHandled = 0; iHandled < _dimension; iHandled++) { if (!handled[iHandled]) { min[iHandled] = _mainBox.Min[iHandled]; max[iHandled] = _mainBox.Max[iHandled]; } } } return(new Box(min, max)); }
internal BoxTree(int dimension, int nElem, bool dynamic, [NotNull] BoxTile mainTile) { _dimension = dimension; _mainTile = mainTile; _maxElemPerTile = nElem; _dynamic = dynamic; }
private void AddChildren(LinkedListNode <BoxTile> neighbourNode, double searchSize) { BoxTile neighbourTile = neighbourNode.Value; double[] searchExtent = GetSearchExtent(neighbourTile.SplitDimension); BoxTile c0 = neighbourTile.Child0; if (c0 != null && Intersects(c0, searchExtent)) { AddChild(neighbourNode, c0, searchSize); } BoxTile c1 = neighbourTile.Child1; if (c1 != null && Intersects(c1, searchExtent)) { AddChild(neighbourNode, c1, searchSize); } neighbourNode.List.Remove(neighbourNode); if (neighbourTile.ElemsCount > 0) { AddNeighbourTileWithElements(neighbourTile); } }
internal TileEntryEnumerable(BoxTree tree, BoxTile startTile, Box startBox, IBox search) { Tree = tree; StartTile = startTile; StartBox = startBox; Search = search; }
private void AddNeighbourTileWithElements(BoxTile neighbourTile) { if (_neighbourTilesWithElems == null) { _neighbourTilesWithElems = new List <BoxTile>(); } _neighbourTilesWithElems.Add(neighbourTile); }
internal TileEntryEnumerator(BoxTree tree, BoxTile startTile, Box startBox, IBox search) { _tree = tree; _startTile = startTile; _startBox = startBox; _searchBox = search; Reset(); }
internal static BoxTile NextSelTile([NotNull] BoxTile currentTile, [NotNull] Box currentBox, [CanBeNull] IBox extent, BoxTile stopTile) { int splitDim = currentTile.SplitDimension; BoxTile child = currentTile.Child0; if (child != null) { if (Math.Abs(currentBox.Min[splitDim] - child.MinInParentSplitDim) > double.Epsilon) { throw new InvalidProgramException( "Error in software design assumption: SplitDim"); } currentBox.Max[splitDim] = child.MaxInParentSplitDim; if (extent == null || currentBox.Intersects(extent)) { return(child); } } while (currentTile != stopTile && currentTile != null) { if (child != currentTile.Child1) { child = currentTile.Child1; currentBox.Min[splitDim] = child.MinInParentSplitDim; currentBox.Max[splitDim] = child.MaxInParentSplitDim; if (extent == null || currentBox.Intersects(extent)) { return(child); } } // reset box to current extent if (child != null) { currentBox.Min[splitDim] = currentTile.MinInSplitDim; currentBox.Max[splitDim] = currentTile.MaxInSplitDim; } // one step up child = currentTile; currentTile = currentTile.Parent; if (currentTile != null) { splitDim = currentTile.SplitDimension; } } // für genuegend unterteilte Tiles (sonst ev. Min.X == 0 o.ae.): // Debug.Assert(currentBox.Equals(mMainBox)); return(null); }
private void CreateFloor() { for (int i = 1; i < width - 1; ++i) { for (int j = 1; j < height - 1; ++j) { tiles[i][j] = new BoxTile(new Vector3Int(i, j, 0), 3); } } }
public BoxTile SetTile(int x, int y, BoxTile newTile) { if (PositionInBounds(x, y)) { BoxTile oldTile = tiles[x + width * y]; tiles[x + width * y] = newTile; return(oldTile); } return(newTile); }
public bool GetTile(int x, int y, out BoxTile emptyTile) { if (PositionInBounds(x, y)) { emptyTile = tiles[x + width * y]; return(true); } emptyTile = null; return(false); }
private void CreateWindows() { for (int i = 2; i < width; ++i) { if (i % 5 == 0) { tiles[i][0] = new BoxTile(new Vector3Int(i, 0, 0), 4); tiles[i][height - 1] = new BoxTile(new Vector3Int(i, height - 1, 0), 4); } } }
public bool IsTouched(Vector3 mousePos, out BoxTile activeTile) { boxMask.UpdateRect(); if (boxMask.HasPoint(mousePos)) { activeTile = this; return(true); } activeTile = null; return(false); }
private double[] GetNeighbourSearchDimExtent(BoxTile neighbourTile) { double[] neighbourExtent = _master._neighbourTree.GetExtent(neighbourTile, _searchDim); if (_searchExtent[1] >= neighbourExtent[0] && _searchExtent[0] <= neighbourExtent[1]) { return(neighbourExtent); } return(null); }
public bool TouchedBoard(Vector3 worldPos) { for (int i = 0; i < tiles.Length; i++) { if (tiles[i].IsTouched(worldPos, out currentTile)) { return(true); } } currentTile = null; return(false); }
private void CreateDimensions() { for (int i = 0; i < width; ++i) { tiles[i][0] = new BoxTile(new Vector3Int(i, 0, 0), 0); tiles[i][height - 1] = new BoxTile(new Vector3Int(i, height - 1, 0), 0); } for (int i = 0; i < height; ++i) { tiles[0][i] = new BoxTile(new Vector3Int(0, i, 0), 1); tiles[width - 1][i] = new BoxTile(new Vector3Int(width - 1, i, 0), 2); } }
private void ShiftTileUp(BoxTile tile) { int tileY = tile.y; while (tileY < height) { tileY += 1; BoxTile topTile; if (GetTile(tile.x, tileY, out topTile)) { MetaSwapTiles(tile, topTile); } } }
public BoxTile GetTileFromCoord(Vector2 c) { BoxTile result = null; foreach (BoxTile tile in allTiles) { if (tile.pos == c) { result = tile; break; } } return(result); }
private double[] GetExtent([NotNull] BoxTile tile, int dimension) { BoxTile t = tile; while (t.Parent != null) { if (dimension == t.Parent.SplitDimension) { return(new[] { t.MinInParentSplitDim, t.MaxInParentSplitDim }); } t = t.Parent; } return(new[] { _mainBox.Min[dimension], _mainBox.Max[dimension] }); }
private void AddLeaves([NotNull] BoxTile parent, [NotNull] List <BoxTile> leaves, bool nonEmpty) { if (parent.Child0 == null) { if (!nonEmpty || parent.ElemsCount > 0) { leaves.Add(parent); } return; } AddLeaves(parent.Child0, leaves, nonEmpty); AddLeaves(parent.Child1, leaves, nonEmpty); }
private void MetaSwapTiles(BoxTile sideOne, BoxTile sideTwo) { int freex = sideOne.x; sideOne.x = sideTwo.x; sideTwo.x = freex; int freey = sideOne.y; sideOne.y = sideTwo.y; sideTwo.y = freey; SetTile(sideOne.x, sideOne.y, sideOne); SetTile(sideTwo.x, sideTwo.y, sideTwo); sideOne.inPlace = false; sideTwo.inPlace = false; }
private double[] GetSearchExtent([NotNull] BoxTree tree, [NotNull] BoxTile tile, double search, [NotNull] IBox commonBox, out int splitDim) { if (tile.Parent == null) { splitDim = -1; return(null); } splitDim = tile.Parent.SplitDimension; double[] extent = tree.GetExtent(tile, splitDim); extent[0] = Math.Max(extent[0] - search, commonBox.Min[splitDim]); extent[1] = Math.Min(extent[1] + search, commonBox.Max[splitDim]); return(extent); }
public void Collapse() { if ((_child0.Child0 == null) == false) { throw new InvalidProgramException("_child0.child0 == null"); } if ((_child1.Child0 == null) == false) { throw new InvalidProgramException("_child1.child0 == null"); } AddRange(_child0); AddRange(_child1); _child0 = null; _child1 = null; }
public override async Task Execute() { BoxTile destTile = await FindDestTile(); MovementController movementController = controllers.Find(x => x.GetType() == typeof(MovementController)) as MovementController; movementController.MoveToPoint((Vector3)destTile.Position * 1.28f + offset); while (movementController.GetDistance() > Mathf.Epsilon) { if (token.IsCancellationRequested) { throw new TaskCanceledException(); } await Task.Delay(50); } movementController.StopAt(destTile); }
private BoxTile Enlarge(int directedDimension) { int dimension = Math.Abs(directedDimension) - 1; BoxTile newTile = _mainTile.CreateEmptyTile(); int size = _mainSize[dimension]; _mainSize[dimension] *= 2; double u0 = _unitBox.Min[dimension]; double u = _unitBox.Max[dimension] - _unitBox.Min[dimension]; if (directedDimension > 0) { _mainBox.Max[dimension] = Position(u0, u, _mainCounter[dimension] + 2 * size, 1); newTile.InitChildren(_mainTile, _mainTile.CreateEmptyTile(), u0, u, _mainCounter[dimension], size / 2, 1); } else { if ((size & 1) != 0) { throw new InvalidProgramException( string.Format( "Error in software design assumption size {0} must be divisible by 2", size)); } _mainCounter[dimension] -= size / 2; _mainBox.Min[dimension] = Position(u0, u, _mainCounter[dimension], 1); _mainBox.Max[dimension] = Position(u0, u, _mainCounter[dimension] + 2 * size, 1); newTile.InitChildren(_mainTile.CreateEmptyTile(), _mainTile, u0, u, _mainCounter[dimension], size / 2, 1); } newTile.SplitDimension = dimension; _mainTile = newTile; return(newTile); }