SuperAPI AI Directory

fog-of-war-js-ts

Coding & development

View repository

Updated 10-16 03:46

About this skill

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