void RenderPlayerShroud(CellRegion visibleRegion) { // Render the shroud by drawing the appropriate tile over each cell that is visible on-screen. // For performance we keep a cache tiles we have drawn previously so we don't have to recalculate the // vertices for tiles every frame, since this is costly. // Any shroud marked as dirty has either never been calculated, or has changed since we last drew that // tile. We will calculate the vertices for that tile and cache them before drawing it. // Any shroud that is not marked as dirty means our cached tile is still correct - we can just draw the // cached vertices. var visibleUnderShroud = currentShroud.IsExploredTest(visibleRegion); var visibleUnderFog = currentShroud.IsVisibleTest(visibleRegion); foreach (var uv in visibleRegion.MapCoords) { var offset = VertexArrayOffset(uv); if (shroudDirty[uv]) { shroudDirty[uv] = false; RenderDirtyTile(uv, offset, visibleUnderShroud, shroudSprites, shroudVertices, shroudPalette, shroudSpriteLayer); RenderDirtyTile(uv, offset, visibleUnderFog, fogSprites, fogVertices, fogPalette, fogSpriteLayer); } else { RenderCachedTile(shroudSpriteLayer[uv], shroudVertices, offset); RenderCachedTile(fogSpriteLayer[uv], fogVertices, offset); } } }
void UpdateShroud(Shroud shroud) { var visibleUnderShroud = shroud.IsExploredTest(updatedRegion); var visibleUnderFog = shroud.IsVisibleTest(updatedRegion); foreach (var cell in updatedRegion) { var shrouded = GetEdges(cell, visibleUnderShroud); var fogged = GetEdges(cell, visibleUnderFog); var shroudTile = tiles[cell]; var variant = shroudTile.Variant; shroudTile.Shroud = GetTile(shroudSprites, shrouded, variant); shroudTile.Fog = GetTile(fogSprites, fogged, variant); tiles[cell] = shroudTile; } }