fog-of-war-js-ts

v2026.09.24

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.

GitHub
安装命令
npx skhub add pproenca/fog-of-war-js-ts
Markdown
SKILL.md

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

PriorityCategoryImpactPrefix
1FOV / Visibility AlgorithmCRITICALfov-
2Update Scheduling & Incremental RecomputeCRITICALupdate-
3State Representation & Data StructuresHIGHstate-
4Rendering the Fog LayerHIGHrender-
5Memory & AllocationMEDIUM-HIGHmem-
6Multi-Viewer & Map ScalingMEDIUMscale-
7Geometry & Hot-Loop MathMEDIUMgeo-
8Correctness & Visual ArtifactsLOW-MEDIUMcorrect-

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

FileDescription
references/_sections.mdCategory definitions and impact ordering
assets/templates/_template.mdTemplate for new rules
metadata.jsonVersion and reference information
发现
标签

此技能尚未发布标签。

版本
最新版本元数据

版本

v2026.09.24

发布时间

2026年9月24日

分类

未分类

许可证

MIT

源路径

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

默认分支

master

最新提交

cf93c57

Tree SHA

afbb575