public void UpdateVisibility() { var wasVisible = Visible; Shrouded = true; Visible = true; // PERF: Avoid LINQ. foreach (var puv in Footprint) { if (shroud.IsVisible(puv)) { Visible = false; Shrouded = false; break; } if (Shrouded && shroud.IsExplored(puv)) { Shrouded = false; } } NeedRenderables |= Visible && !wasVisible; }
void UpdateVisibility() { var wasVisible = Visible; Shrouded = true; // We are doing the following LINQ manually for performance since this is a hot path. // Visible = !Footprint.Any(shroud.IsVisible); Visible = true; foreach (var puv in Footprint) { if (shroud.IsVisible(puv)) { Visible = false; Shrouded = false; break; } if (Shrouded && shroud.IsExplored(puv)) { Shrouded = false; } } NeedRenderables |= Visible && !wasVisible; }
public void UpdateVisibility() { var wasVisible = Visible; Shrouded = true; Visible = true; // PERF: Avoid LINQ. foreach (var puv in Footprint) { if (shroud.IsVisible(puv)) { Visible = false; Shrouded = false; break; } if (Shrouded && shroud.IsExplored(puv)) { Shrouded = false; } } // Force the backing trait to update so other actors can't // query inconsistent state (both hidden or both visible) if (Visible != wasVisible) { frozenTrait.OnVisibilityChanged(this); } NeedRenderables |= Visible && !wasVisible; }
static int ShroudedEdges(Shroud s, CPos p, bool useExtendedIndex) { if (!s.IsExplored(p.X, p.Y)) return 15; // If a side is shrouded then we also count the corners var u = 0; if (!s.IsExplored(p.X, p.Y - 1)) u |= 0x13; if (!s.IsExplored(p.X + 1, p.Y)) u |= 0x26; if (!s.IsExplored(p.X, p.Y + 1)) u |= 0x4C; if (!s.IsExplored(p.X - 1, p.Y)) u |= 0x89; var uside = u & 0x0F; if (!s.IsExplored(p.X - 1, p.Y - 1)) u |= 0x01; if (!s.IsExplored(p.X + 1, p.Y - 1)) u |= 0x02; if (!s.IsExplored(p.X + 1, p.Y + 1)) u |= 0x04; if (!s.IsExplored(p.X - 1, p.Y + 1)) u |= 0x08; // RA provides a set of frames for tiles with shrouded // corners but unshrouded edges. We want to detect this // situation without breaking the edge -> corner enabling // in other combinations. The XOR turns off the corner // bits that are enabled twice, which gives the behavior // we want here. return useExtendedIndex ? u ^ uside : u & 0x0F; }
Sprite ChooseFog(Shroud s, int i, int j) { if (!s.IsVisible(i, j)) return shadowBits[0xf]; if (!s.IsExplored(i, j)) return shadowBits[0xf]; // bits are for unexploredness: up, right, down, left var v = 0; // bits are for unexploredness: TL, TR, BR, BL var u = 0; if (!s.IsVisible(i, j - 1)) { v |= 1; u |= 3; } if (!s.IsVisible(i + 1, j)) { v |= 2; u |= 6; } if (!s.IsVisible(i, j + 1)) { v |= 4; u |= 12; } if (!s.IsVisible(i - 1, j)) { v |= 8; u |= 9; } var uSides = u; if (!s.IsVisible(i - 1, j - 1)) u |= 1; if (!s.IsVisible(i + 1, j - 1)) u |= 2; if (!s.IsVisible(i + 1, j + 1)) u |= 4; if (!s.IsVisible(i - 1, j + 1)) u |= 8; return shadowBits[SpecialShroudTiles[u ^ uSides][v]]; }