protected static bool IsHorizontalEdge(TileGridBlock block, ref int x, ref int y) { return(y <= 0 || y >= block.BlockSize - 1 || block.GetCell(x, y - 1).IsEmpty || block.GetCell(x, y + 1).IsEmpty); }
protected virtual void AggregateTiles(TileGridBlock block, ITileDefinitionSource tileDefinitionSource, GraphicsContext graphicsContext, ref Vector2 cellSize) { var blockSize = block.BlockSize; RectangleF outRect = new RectangleF(); outRect.X = block.Origin.X; outRect.Y = block.Origin.Y; outRect.Width = cellSize.X; outRect.Height = cellSize.Y; for (int y = 0; y < blockSize; y++) { for (int x = 0; x < blockSize; x++) { var tileRef = block.GetCell(x, y); if (!tileRef.IsEmpty) { var tile = tileDefinitionSource.GetTile(ref tileRef); if (tile != null && tile.CanCacheTileMesh) { var frame = tile[0]; Add(frame.Texture, ref frame.TextureRegion, ref outRect); } } outRect.X += cellSize.X; } outRect.X = block.Origin.X; outRect.Y -= cellSize.Y; } }
protected static bool IsVerticalEdge(TileGridBlock block, ref int x, ref int y) { return(x <= 0 || x >= block.BlockSize - 1 || block.GetCell(x - 1, y).IsEmpty || block.GetCell(x + 1, y).IsEmpty); }
public virtual TileMeshDraw Build(TileGridBlock block, ITileDefinitionSource tileDefinitionSource, GraphicsContext graphicsContext, ref Vector2 cellSize) { TileMeshDraw tileMeshDraw = null; AggregateTiles(block, tileDefinitionSource, graphicsContext, ref cellSize); CompleteBuild(graphicsContext, block.BlockSize * block.BlockSize, ref tileMeshDraw); return(tileMeshDraw); }
protected static bool IsEdge(TileGridBlock block, ref int x, ref int y) { var maxIndex = block.BlockSize - 1; return(x <= 0 || x >= maxIndex || y <= 0 || y >= maxIndex || block.GetCell(x - 1, y).IsEmpty || block.GetCell(x + 1, y).IsEmpty || block.GetCell(x, y - 1).IsEmpty || block.GetCell(x, y + 1).IsEmpty); }
protected override void Update(PhysicsShapeBuilderContext context, TileGridBlock block) { Rectangle cellSelection = new Rectangle(0, 0, 1, 1); for (int y = 0; y < block.BlockSize; y++) { for (int x = 0; x < block.BlockSize; x++) { var tile = block.GetCell(x, y); if (!tile.IsEmpty) { context.AddColliderShape(context.ColliderShapeProvider.CalculateColliderShape(ref cellSelection, block)); } cellSelection.X += 1; } cellSelection.Y += 1; cellSelection.X = 0; } }
protected override void Update(PhysicsShapeBuilderContext context, TileGridBlock block) { throw new NotImplementedException(); //Rectangle cellSelection = new Rectangle(0, 0, 1, 1); //int left = 0; //Rectangle adjacent = default(Rectangle); //bool hasAdjacent = false; //for (int y = 0; y < block.BlockSize; y++) //{ // for (int x = 0; x < block.BlockSize; x++) // { // var tile = block.GetCell(x, y); // if (!tile.IsEmpty) // { // if (IsLeftEdge(block, ref x, ref y)) // { // cellSelection.X = left = x; // cellSelection.Width = 1; // if (hasAdjacent = previousBounds.TryGetValue(x, out adjacent)) // previousBounds.Remove(x); // } // if (IsRightEdge(block, ref x, ref y)) // { // if (hasAdjacent) // { // if (adjacent.Width == cellSelection.Width) // { // adjacent.Height += 1; // currentBounds[left] = adjacent; // } // else // { // context.AddColliderShape(context.ColliderShapeProvider.CalculateColliderShape(ref adjacent, block)); // currentBounds[left] = cellSelection; // } // hasAdjacent = false; // } // else // { // currentBounds[left] = cellSelection; // } // } // else // { // cellSelection.Width += 1; // } // } // } // cellSelection.Y += 1; // cellSelection.X = left = 0; // cellSelection.Width = 1; // foreach (var item in previousBounds.Values) // { // var leftOver = item; // context.AddColliderShape(context.ColliderShapeProvider.CalculateColliderShape(ref leftOver, block)); // } // Utilities.Swap(ref previousBounds, ref currentBounds); // currentBounds.Clear(); //} //foreach (var item in previousBounds.Values) //{ // var leftOver = item; // context.AddColliderShape(context.ColliderShapeProvider.CalculateColliderShape(ref leftOver, block)); //} //previousBounds.Clear(); }
protected override void Update(PhysicsShapeBuilderContext context, TileGridBlock block) { Rectangle cellSelection = new Rectangle(0, 0, 1, 1); int left = 0; Rectangle adjacent = default(Rectangle); bool hasAdjacent = false; for (int y = 0; y < block.BlockSize; y++) { for (int x = 0; x < block.BlockSize; x++) { var tile = block.GetCell(x, y); if (!tile.IsEmpty) { if (IsLeftEdge(block, ref x, ref y)) { cellSelection.X = left = x; cellSelection.Width = 1; if (hasAdjacent = previousBounds.TryGetValue(x, out adjacent)) { previousBounds.Remove(x); } } if (IsRightEdge(block, ref x, ref y)) { if (hasAdjacent) { if (adjacent.Width == cellSelection.Width) { adjacent.Height += 1; currentBounds[left] = adjacent; } else { context.AddColliderShape(context.ColliderShapeProvider.CalculateColliderShape(ref adjacent, block)); currentBounds[left] = cellSelection; } hasAdjacent = false; } else { currentBounds[left] = cellSelection; } } else { cellSelection.Width += 1; } } } cellSelection.Y += 1; cellSelection.X = left = 0; cellSelection.Width = 1; foreach (var item in previousBounds.Values) { var leftOver = item; context.AddColliderShape(context.ColliderShapeProvider.CalculateColliderShape(ref leftOver, block)); } Utilities.Swap(ref previousBounds, ref currentBounds); currentBounds.Clear(); } foreach (var item in previousBounds.Values) { var leftOver = item; context.AddColliderShape(context.ColliderShapeProvider.CalculateColliderShape(ref leftOver, block)); } previousBounds.Clear(); }
protected static bool IsBottomEdge(TileGridBlock block, ref int x, ref int y) { return(y >= block.BlockSize - 1 || block.GetCell(x, y + 1).IsEmpty); }
protected static bool IsTopEdge(TileGridBlock block, ref int x, ref int y) { return(y <= 0 || block.GetCell(x, y - 1).IsEmpty); }
protected static bool IsRightEdge(TileGridBlock block, ref int x, ref int y) { return(x >= block.BlockSize - 1 || block.GetCell(x + 1, y).IsEmpty); }
protected static bool IsLeftEdge(TileGridBlock block, ref int x, ref int y) { return(x <= 0 || block.GetCell(x - 1, y).IsEmpty); }
protected abstract void Update(PhysicsShapeBuilderContext context, TileGridBlock block);
public virtual void Recycle(TileMeshDraw tileMeshDraw, TileGridBlock block, ITileDefinitionSource tileDefinitionSource, GraphicsContext graphicsContext, ref Vector2 cellSize) { AggregateTiles(block, tileDefinitionSource, graphicsContext, ref cellSize); CompleteBuild(graphicsContext, block.BlockSize * block.BlockSize, ref tileMeshDraw); }