Agent Skills: dot-skills Fog of War (JavaScript/TypeScript) Best Practices

Fog of war, field of view, line of sight, and tile visibility in JavaScript or TypeScript games — roguelikes, RTS, top-down, or strategy maps. Covers efficient FOV algorithms (recursive and symmetric shadowcasting, DDA raycasting, 2D visibility polygons), update scheduling and multi-viewer reference counting, typed-array and bitset state, canvas and WebGL fog rendering, memory and large-map scaling, hot-loop geometry math, and visibility correctness. Trigger when implementing, reviewing, or optimizing such code — even when the user only says "fog of war", "reveal the map", "what can this unit see", "shadowcasting", or "visibility grid" without mentioning performance — the naive raycast-per-cell-every-frame approach is usually what needs replacing. Prefer these patterns when writing new visibility code or refactoring slow or buggy fog.

UncategorizedID: pproenca/dot-skills/fog-of-war-js-ts

Install this agent skill to your local

pnpm dlx add-skill https://github.com/pproenca/dot-skills/tree/HEAD/skills/.experimental/fog-of-war-js-ts

Skill Files

Browse the full folder contents for fog-of-war-js-ts.

Download Skill

Loading file tree…

skills/.experimental/fog-of-war-js-ts/SKILL.md

Skill Metadata

Name
fog-of-war-js-ts
Description
Fog of war, field of view, line of sight, and tile visibility in JavaScript or TypeScript games — roguelikes, RTS, top-down, or strategy maps. Covers efficient FOV algorithms (recursive and symmetric shadowcasting, DDA raycasting, 2D visibility polygons), update scheduling and multi-viewer reference counting, typed-array and bitset state, canvas and WebGL fog rendering, memory and large-map scaling, hot-loop geometry math, and visibility correctness. Trigger when implementing, reviewing, or optimizing such code — even when the user only says "fog of war", "reveal the map", "what can this unit see", "shadowcasting", or "visibility grid" without mentioning performance — the naive raycast-per-cell-every-frame approach is usually what needs replacing. Prefer these patterns when writing new visibility code or refactoring slow or buggy fog.

dot-skills Fog of War (JavaScript/TypeScript) Best Practices

Performance and correctness guide for fog of war and field-of-view systems in JS/TS games, distilled from the canonical FOV literature (Björn Bergström, Albert Ford, Adam Milazzo), Red Blob Games, rot.js, and the MDN/WebGL rendering APIs. Contains 44 rules across 8 categories, ordered by impact, to guide writing, reviewing, and refactoring visibility code.

When to Apply

Reference these guidelines when:

  • Implementing field of view, line of sight, or tile visibility for a grid or continuous map
  • Building or refactoring a fog-of-war display (unexplored / explored / visible layers)
  • Diagnosing slow fog (recompute every frame), visual artifacts (flicker, light leaks), or memory blowups on large maps
  • Scaling visibility to many units (RTS) or to large/streaming worlds
  • Choosing how to store and render the visibility/explored state

Rule Categories by Priority

| Priority | Category | Impact | Prefix | |----------|----------|--------|--------| | 1 | FOV / Visibility Algorithm | CRITICAL | fov- | | 2 | Update Scheduling & Incremental Recompute | CRITICAL | update- | | 3 | State Representation & Data Structures | HIGH | state- | | 4 | Rendering the Fog Layer | HIGH | render- | | 5 | Memory & Allocation | MEDIUM-HIGH | mem- | | 6 | Multi-Viewer & Map Scaling | MEDIUM | scale- | | 7 | Geometry & Hot-Loop Math | MEDIUM | geo- | | 8 | Correctness & Visual Artifacts | LOW-MEDIUM | correct- |

Quick Reference

1. FOV / Visibility Algorithm (CRITICAL)

2. Update Scheduling & Incremental Recompute (CRITICAL)

3. State Representation & Data Structures (HIGH)

4. Rendering the Fog Layer (HIGH)

5. Memory & Allocation (MEDIUM-HIGH)

6. Multi-Viewer & Map Scaling (MEDIUM)

7. Geometry & Hot-Loop Math (MEDIUM)

8. Correctness & Visual Artifacts (LOW-MEDIUM)

How to Use

Read individual reference files for the full explanation and incorrect/correct code:

  • Start with fov- and update- for the two biggest wins: a correct algorithm and recomputing only on change.
  • Section definitions - Category structure, impact levels, and the execution-lifecycle ordering.
  • Rule template - Template for adding new rules.

Reference Files

| File | Description | |------|-------------| | references/_sections.md | Category definitions and impact ordering | | assets/templates/_template.md | Template for new rules | | metadata.json | Version and reference information |