void CacheMapBorderShroud() { // Cache the whole of the map border shroud ahead of time, since it never changes. Func <MPos, bool> mapContains = map.Contains; foreach (var uv in CellRegion.Expand(map.Cells, 1).MapCoords) { var offset = VertexArrayOffset(uv); var edges = GetEdges(uv, mapContains); var tileInfo = tileInfos[uv]; CacheTile(uv, offset, edges, tileInfo, shroudSprites, shroudVertices, shroudPalette, shroudSpriteLayer); CacheTile(uv, offset, edges, tileInfo, fogSprites, fogVertices, fogPalette, fogSpriteLayer); } }
public void WorldLoaded(World w, WorldRenderer wr) { // Initialize tile cache // Adds a 1-cell border around the border to cover any sprites peeking outside the map foreach (var uv in CellRegion.Expand(w.Map.Cells, 1).MapCoords) { var screen = wr.ScreenPosition(w.Map.CenterOfCell(uv.ToCPos(map))); var variant = (byte)Game.CosmeticRandom.Next(info.ShroudVariants.Length); tileInfos[uv] = new TileInfo(screen, variant); } fogPalette = wr.Palette(info.FogPalette); shroudPalette = wr.Palette(info.ShroudPalette); }
void Render(CellRegion visibleRegion) { // Due to diamond tile staggering, we need to expand the cordon to get full shroud coverage. if (map.TileShape == TileShape.Diamond) { visibleRegion = CellRegion.Expand(visibleRegion, 1); } if (currentShroud == null) { RenderMapBorderShroud(visibleRegion); } else { RenderPlayerShroud(visibleRegion); } }
void RenderMapBorderShroud(CellRegion visibleRegion) { // The map border shroud only affects the map border. If none of the visible cells are on the border, then // we don't need to render anything and can bail early for performance. if (CellRegion.Expand(map.Cells, -1).Contains(visibleRegion)) { return; } // Render the shroud that just encroaches at the map border. This shroud is always fully cached, so we can // just render straight from the cache. foreach (var uv in visibleRegion.MapCoords) { var offset = VertexArrayOffset(uv); RenderCachedTile(shroudSpriteLayer[uv], shroudVertices, offset); RenderCachedTile(fogSpriteLayer[uv], fogVertices, offset); } }
public void RenderShroud(WorldRenderer wr, Shroud shroud) { Update(shroud, wr.Viewport.VisibleCells); foreach (var cell in CellRegion.Expand(wr.Viewport.VisibleCells, 1)) { var t = tiles[cell]; if (t.Shroud != null) { var pos = t.ScreenPosition - 0.5f * t.Shroud.size; Game.Renderer.WorldSpriteRenderer.DrawSprite(t.Shroud, pos, shroudPalette); } if (t.Fog != null) { var pos = t.ScreenPosition - 0.5f * t.Fog.size; Game.Renderer.WorldSpriteRenderer.DrawSprite(t.Fog, pos, fogPalette); } } }
public void WorldLoaded(World w, WorldRenderer wr) { // Initialize tile cache // Adds a 1-cell border around the border to cover any sprites peeking outside the map foreach (var cell in CellRegion.Expand(w.Map.Cells, 1)) { var screen = wr.ScreenPosition(w.Map.CenterOfCell(cell)); var variant = Game.CosmeticRandom.Next(info.ShroudVariants.Length); tiles[cell] = new ShroudTile(cell, screen, variant); // Set the cells outside the border so they don't need to be touched again if (!map.Contains(cell)) { var index = info.UseExtendedIndex ? 240 : 15; tiles[cell].Shroud = shroudSprites[variant * variantStride + spriteMap[index]]; } } fogPalette = wr.Palette(info.FogPalette); shroudPalette = wr.Palette(info.ShroudPalette); }
public void WorldLoaded(World w, WorldRenderer wr) { // Initialize tile cache // Adds a 1-cell border around the border to cover any sprites peeking outside the map foreach (var cell in CellRegion.Expand(w.Map.Cells, 1)) { var screen = wr.ScreenPosition(w.Map.CenterOfCell(cell)); var variant = (byte)Game.CosmeticRandom.Next(info.ShroudVariants.Length); tiles[cell] = new ShroudTile(screen, variant); // Set the cells outside the border so they don't need to be touched again if (!map.Contains(cell)) { var shroudTile = tiles[cell]; shroudTile.Shroud = GetTile(shroudSprites, notVisibleEdges, variant); tiles[cell] = shroudTile; } } fogPalette = wr.Palette(info.FogPalette); shroudPalette = wr.Palette(info.ShroudPalette); }