CellView API #114

Closed
opened 2025-07-12 19:02:29 +00:00 by john · 2 comments
Owner

Create ergonomic .at((x,y)) access pattern for grid cells.
Definition of Done:

  • grid.at((x, y)) returns CellView object
  • CellView provides convenient access to tile properties
  • Supports chaining operations
  • Backward compatible with existing grid access
Create ergonomic .at((x,y)) access pattern for grid cells. Definition of Done: - grid.at((x, y)) returns CellView object - CellView provides convenient access to tile properties - Supports chaining operations - Backward compatible with existing grid access
john added the
Major Feature
label 2025-07-12 19:02:29 +00:00
john added the
Refactoring & Cleanup
system:performance
labels 2025-10-26 00:44:39 +00:00
john added the
priority:tier1-active
system:grid
labels 2025-10-26 00:48:54 +00:00
Author
Owner

Refined Design - CellView API Integration

After design discussion, #114 is being expanded to encompass the Perspective System for layer-based FOV rendering.

New Scope

Phase 1: FOV Foundation

  • Create mcrfpy.FOV enum (BASIC, DIAMOND, SHADOW, PERMISSIVE_0-8, RESTRICTIVE)
  • Add mcrfpy.default_fov module property (copied to new grids at creation)
  • Add grid.fov and grid.fov_radius properties
  • Remove deprecated module-level FOV_* constants

Phase 3: Perspective Binding (after #113)

  • layer.apply_perspective(fov=None, visible=, discovered=, unknown=) - binds layer to perspective updates
  • entity.updateVisibility() updates all bound layers, marks dirty chunks
  • grid.perspective_enabled toggles ALL perspective-bound layers visible/invisible
  • Per-layer TCOD map allocation when layer FOV differs from grid's FOV

Key Design Decisions

  1. Manual visibility updates are intentional - animations may move entities frequently, so updateVisibility() is called explicitly by game logic (e.g., after movement animation completes)

  2. grid.perspective = entity calls updateVisibility() once as cleanup when switching perspective entities

  3. Dirty region optimization - when entity moves, only mark chunks within old/new FOV radius as dirty, not entire layer

Data Structure (Layer Perspective Binding)

struct PerspectiveBinding {
    bool bound = false;
    TCOD_fov_algorithm_t fov_algorithm;
    bool use_grid_fov = true;
    sf::Vector2i last_entity_pos;
    
    // For ColorLayer
    sf::Color visible_color, discovered_color, unknown_color;
    
    // For TileLayer  
    int visible_tile, discovered_tile, unknown_tile;
};

Dependencies

  • Blocked by: #113 (batch layer operations)
  • Blocks: #156 (Agent Orchestration)
## Refined Design - CellView API Integration After design discussion, #114 is being expanded to encompass the **Perspective System** for layer-based FOV rendering. ### New Scope **Phase 1: FOV Foundation** - Create `mcrfpy.FOV` enum (BASIC, DIAMOND, SHADOW, PERMISSIVE_0-8, RESTRICTIVE) - Add `mcrfpy.default_fov` module property (copied to new grids at creation) - Add `grid.fov` and `grid.fov_radius` properties - Remove deprecated module-level `FOV_*` constants **Phase 3: Perspective Binding** (after #113) - `layer.apply_perspective(fov=None, visible=, discovered=, unknown=)` - binds layer to perspective updates - `entity.updateVisibility()` updates all bound layers, marks dirty chunks - `grid.perspective_enabled` toggles ALL perspective-bound layers visible/invisible - Per-layer TCOD map allocation when layer FOV differs from grid's FOV ### Key Design Decisions 1. **Manual visibility updates are intentional** - animations may move entities frequently, so `updateVisibility()` is called explicitly by game logic (e.g., after movement animation completes) 2. **`grid.perspective = entity` calls `updateVisibility()` once** as cleanup when switching perspective entities 3. **Dirty region optimization** - when entity moves, only mark chunks within old/new FOV radius as dirty, not entire layer ### Data Structure (Layer Perspective Binding) ```cpp struct PerspectiveBinding { bool bound = false; TCOD_fov_algorithm_t fov_algorithm; bool use_grid_fov = true; sf::Vector2i last_entity_pos; // For ColorLayer sf::Color visible_color, discovered_color, unknown_color; // For TileLayer int visible_tile, discovered_tile, unknown_tile; }; ``` ### Dependencies - Blocked by: #113 (batch layer operations) - Blocks: #156 (Agent Orchestration)
Author
Owner

Commit 018e735 implements Phase 1:

  • Created mcrfpy.FOV IntEnum with all TCOD FOV algorithms (BASIC, DIAMOND, SHADOW, PERMISSIVE_0-8, RESTRICTIVE, SYMMETRIC_SHADOWCAST)
  • Added mcrfpy.default_fov module property (defaults to FOV.BASIC)
  • Added grid.fov and grid.fov_radius properties for per-grid defaults
  • Breaking change: Removed deprecated FOV_* module-level constants - use mcrfpy.FOV.BASIC etc. instead

Example usage:

import mcrfpy

# Module property
print(mcrfpy.default_fov)  # FOV.BASIC

# Grid properties
grid = mcrfpy.Grid(grid_size=(20, 20))
grid.fov = mcrfpy.FOV.SHADOW
grid.fov_radius = 15

# In compute_fov
grid.compute_fov(5, 5, radius=10, algorithm=mcrfpy.FOV.SYMMETRIC_SHADOWCAST)

Tests updated and all 141 pass.

Commit 018e735 implements Phase 1: - Created `mcrfpy.FOV` IntEnum with all TCOD FOV algorithms (BASIC, DIAMOND, SHADOW, PERMISSIVE_0-8, RESTRICTIVE, SYMMETRIC_SHADOWCAST) - Added `mcrfpy.default_fov` module property (defaults to FOV.BASIC) - Added `grid.fov` and `grid.fov_radius` properties for per-grid defaults - **Breaking change**: Removed deprecated `FOV_*` module-level constants - use `mcrfpy.FOV.BASIC` etc. instead Example usage: ```python import mcrfpy # Module property print(mcrfpy.default_fov) # FOV.BASIC # Grid properties grid = mcrfpy.Grid(grid_size=(20, 20)) grid.fov = mcrfpy.FOV.SHADOW grid.fov_radius = 15 # In compute_fov grid.compute_fov(5, 5, radius=10, algorithm=mcrfpy.FOV.SYMMETRIC_SHADOWCAST) ``` Tests updated and all 141 pass.
john closed this issue 2025-12-02 02:04:12 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
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#114
No description provided.