Deduplicate redundant FOV computation #292

Closed
opened 2026-03-08 20:18:41 +00:00 by john · 1 comment
Owner

Problem

FOV is computed 2-3x per visibility update cycle:

  1. apply_perspective()drawFOV() calls grid->computeFOV()
  2. entity.update_visibility() calls grid->computeFOV() again
  3. updatePerspective()drawFOV() triggers a third computation

This is pure redundant work — entity position hasn't changed between these calls.

Discovered during

7DRL 2026 jam — observable as unnecessary CPU cost on grids with large FOV radii.

Proposed fix

Add a dirty flag to the grid's FOV state. Mark dirty when the perspective entity's position changes (or when walkable/transparent data changes). computeFOV() early-returns if not dirty. This ensures at most one FOV computation per frame regardless of how many code paths request it.

Alternative: deduplicate the call sites directly so only one path triggers computation per frame. The dirty flag approach is more robust against future call site additions.

Scope

This is independent of #252 (Grid/GridView overhaul) and can be fixed incrementally on the current codebase.

## Problem FOV is computed 2-3x per visibility update cycle: 1. `apply_perspective()` → `drawFOV()` calls `grid->computeFOV()` 2. `entity.update_visibility()` calls `grid->computeFOV()` again 3. `updatePerspective()` → `drawFOV()` triggers a third computation This is pure redundant work — entity position hasn't changed between these calls. ## Discovered during 7DRL 2026 jam — observable as unnecessary CPU cost on grids with large FOV radii. ## Proposed fix Add a dirty flag to the grid's FOV state. Mark dirty when the perspective entity's position changes (or when walkable/transparent data changes). `computeFOV()` early-returns if not dirty. This ensures at most one FOV computation per frame regardless of how many code paths request it. Alternative: deduplicate the call sites directly so only one path triggers computation per frame. The dirty flag approach is more robust against future call site additions. ## Scope This is independent of #252 (Grid/GridView overhaul) and can be fixed incrementally on the current codebase.
Author
Owner

Roadmap context

Part of the Grid & Entity Overhaul Roadmap (docs/GRID_ENTITY_OVERHAUL_ROADMAP.md), Phase 1 (Foundation). The fov_dirty flag pattern introduced here is reused by #303 (FOV optimization for behavior triggers) in Phase 3.

## Roadmap context Part of the Grid & Entity Overhaul Roadmap (`docs/GRID_ENTITY_OVERHAUL_ROADMAP.md`), **Phase 1** (Foundation). The `fov_dirty` flag pattern introduced here is reused by #303 (FOV optimization for behavior triggers) in Phase 3.
john closed this issue 2026-03-16 11:21:02 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
john/McRogueFace#292
No description provided.