private static void ExpandVisible(Grid <Tile> buffer, Grid <Tile> visibility, int visibleIndex, Grid <Tile> terrainTiles, TileInfo[] tileData) { int width = visibility.Width; int height = visibility.Height; buffer.ResizeClear(width, height); visibility.CopyTo(buffer); Tile[] newVisibilityData = visibility.RawData; Tile[] visibilityData = buffer.RawData; Tile[] terrainData = terrainTiles.RawData; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { int i = x + width * y; // Don't expand visibility to non-blocking tiles TileCollisionShapes collision = tileData[terrainData[i].BaseIndex].Collision; bool blockingView = collision[TileCollisionLayer.Layer2] != TileCollisionShape.Free; if (!blockingView) { continue; } bool visible = visibilityData[i].BaseIndex == visibleIndex; visible |= x > 0 && y > 0 && visibilityData[i - 1 - width].BaseIndex == visibleIndex; visible |= y > 0 && visibilityData[i - width].BaseIndex == visibleIndex; visible |= x < width - 1 && y > 0 && visibilityData[i + 1 - width].BaseIndex == visibleIndex; visible |= x > 0 && visibilityData[i - 1].BaseIndex == visibleIndex; visible |= x < width - 1 && visibilityData[i + 1].BaseIndex == visibleIndex; visible |= x > 0 && y < height - 1 && visibilityData[i - 1 + width].BaseIndex == visibleIndex; visible |= y > 0 && visibilityData[i - width].BaseIndex == visibleIndex; visible |= x < width - 1 && y < height - 1 && visibilityData[i + 1 + width].BaseIndex == visibleIndex; if (visible) { newVisibilityData[i].BaseIndex = visibleIndex; } } } }
private void GrowFire() { Grid <Tile> collisionTiles = this.collisionMap.BeginUpdateTiles(); Tile[] collisionData = collisionTiles.RawData; Tileset collisionTileset = this.collisionMap.Tileset.Res; TileInfo[] collisionTileInfo = collisionTileset.TileData.Data; Grid <Tile> tiles = this.fireMap.BeginUpdateTiles(); Tile[] tileData = tiles.RawData; int width = tiles.Width; int height = tiles.Height; // Expand existing local fire for (int y = 0; y < tiles.Height; y++) { for (int x = 0; x < tiles.Width; x++) { int i = y * width + x; int fireIndex = this.GetFireIndex(tileData[i].BaseIndex); if (fireIndex != -1 && fireIndex < this.firstFireTile + this.fireTileCount - 1) { fireIndex++; tileData[i].BaseIndex = fireIndex; } } } // Spread fire from neighbours for (int y = 0; y < tiles.Height; y++) { for (int x = 0; x < tiles.Width; x++) { int i = y * width + x; int fireIndex = this.GetFireIndex(tileData[i].BaseIndex); if (fireIndex != -1) { continue; } if ((x > 0 && this.GetFireIndex(tileData[i - 1].Index) != -1) || (x < width - 1 && this.GetFireIndex(tileData[i + 1].Index) != -1) || (y > 0 && this.GetFireIndex(tileData[i - width].Index) != -1) || (y < height - 1 && this.GetFireIndex(tileData[i + width].Index) != -1)) { TileCollisionShapes collisionShapes = collisionTileInfo[collisionData[i].Index].Collision; bool isFree = collisionShapes[TileCollisionLayer.Layer1] == TileCollisionShape.Free; if (isFree) { fireIndex = this.firstFireTile; tileData[i].BaseIndex = fireIndex; } } } } // Update everything on the fire map this.fireMap.EndUpdateTiles(); // Update nothing on the collision map (didn't change anything) this.collisionMap.EndUpdateTiles(0, 0, 0, 0); }