Entity knowledge contents: make map data available directly through GridPointState #16

Closed
opened 2024-03-09 18:47:43 +00:00 by john · 3 comments
Owner

Notes say:
21 feat: Grid strict mode: Entity's GridPointState (discovered, visible) should include a point member: None if not discovered, a unmodified version of the GridPoint object if discovered but not visible, and a up-to-date GridPoint with .entities sub-member (entities at that visible GridPoint)

  • Strict - the entity's at method returns a GridPointState ("gps") instance with these values:
    • gps.discovered == False -> gps.point == None No knowledge
    • gps.discovered == True && gps.visible == False -> gps.point is a GridPoint instance, but that instance has no .entities collection. It's also a copy of the GridPoint when it was last seen, not as it currently is.
    • gps.visible == True -> gps.point is a GridPoint pointing at the Grid's vector, and includes a .entities collection of the Entities presently at that position (list of items, etc)
Notes say: 21 feat: Grid strict mode: Entity's GridPointState (discovered, visible) should include a point member: None if not discovered, a unmodified version of the GridPoint object if discovered but not visible, and a up-to-date GridPoint with `.entities` sub-member (entities at that visible GridPoint) * **Strict** - the entity's `at` method returns a GridPointState ("`gps`") instance with these values: * `gps.discovered == False` -> `gps.point == None` No knowledge * `gps.discovered == True && gps.visible == False` -> `gps.point` is a GridPoint instance, but that instance has no `.entities` collection. It's also a copy of the GridPoint when it was last seen, not as it currently is. * `gps.visible == True` -> `gps.point` is a GridPoint pointing at the Grid's vector, and includes a `.entities` collection of the Entities presently at that position (list of items, etc)
Author
Owner

this is being deferred as the capability can already be provided in Python: a subclass of Entity could store its own map data based on last visible state. I'm interested in providing the functionality natively, but it's going to be a while

this is being deferred as the capability can already be provided in Python: a subclass of Entity could store its own map data based on last visible state. I'm interested in providing the functionality natively, but it's going to be a while
john removed this from the Alpha Release Targets milestone 2025-11-26 10:17:09 +00:00
Author
Owner

Refined Design - Entity Knowledge / Visible Entities

New Entity Method

entity.visible_entities(fov=None)  # Returns iterable, not list
  • fov=None uses grid.fov (the grid's assigned FOV algorithm)
  • Returns an iterable over entities in FOV - no list copying
  • Raises RuntimeError if entity.grid is None

Usage Pattern

# For NPC AI - find visible enemies
visible_enemies = [e for e in entity.visible_entities() 
                   if isinstance(e, EnemyEntity)]

# With explicit FOV (asymmetric vision)
player_visible = [e for e in guard.visible_entities(mcrfpy.FOV.RESTRICTIVE)
                  if e.faction == "player"]

FOV Default Chain

mcrfpy.default_fov          # Module-level default (FOV.BASIC)
    ↓ (copied at grid creation)
grid.fov                    # Grid's FOV algorithm
    ↓ (used when fov=None)
entity.visible_entities()   # Uses grid.fov
layer.draw_fov()            # Uses grid.fov
layer.apply_perspective()   # Uses grid.fov

Implementation Notes

  • Does NOT require #115 (SpatialHash) - FOV checking is the bottleneck, not entity iteration
  • Uses grid's existing TCOD map when fov=None
  • Allocates temporary TCOD map only if explicit fov= differs from grid's

Dependencies

  • Blocked by: #114 (Perspective System provides FOV infrastructure)
  • Blocks: #156 (Agent Orchestration)
## Refined Design - Entity Knowledge / Visible Entities ### New Entity Method ```python entity.visible_entities(fov=None) # Returns iterable, not list ``` - `fov=None` uses `grid.fov` (the grid's assigned FOV algorithm) - Returns an **iterable** over entities in FOV - no list copying - Raises `RuntimeError` if `entity.grid` is None ### Usage Pattern ```python # For NPC AI - find visible enemies visible_enemies = [e for e in entity.visible_entities() if isinstance(e, EnemyEntity)] # With explicit FOV (asymmetric vision) player_visible = [e for e in guard.visible_entities(mcrfpy.FOV.RESTRICTIVE) if e.faction == "player"] ``` ### FOV Default Chain ``` mcrfpy.default_fov # Module-level default (FOV.BASIC) ↓ (copied at grid creation) grid.fov # Grid's FOV algorithm ↓ (used when fov=None) entity.visible_entities() # Uses grid.fov layer.draw_fov() # Uses grid.fov layer.apply_perspective() # Uses grid.fov ``` ### Implementation Notes - Does NOT require #115 (SpatialHash) - FOV checking is the bottleneck, not entity iteration - Uses grid's existing TCOD map when `fov=None` - Allocates temporary TCOD map only if explicit `fov=` differs from grid's ### Dependencies - Blocked by: #114 (Perspective System provides FOV infrastructure) - Blocks: #156 (Agent Orchestration)
Author
Owner

Partial Implementation Complete

The perspective/visibility system is now functional via commits c5b4200 and a529e5e:

What's implemented:

  • entity.gridstate tracks visible/discovered per cell
  • entity.update_visibility() computes FOV and updates gridstate
  • entity.visible_entities() returns entities within FOV
  • ColorLayer can bind to entity for automatic fog-of-war rendering

What remains for "strict mode":
The original issue describes entity.at(x, y) returning a GridPointState with:

  • gps.discovered == Falsegps.point == None
  • gps.discovered == True && visible == Falsegps.point is stale copy
  • gps.visible == Truegps.point is live reference with .entities

Current implementation has entity.at(x, y) but doesn't yet implement the stale-copy vs live-reference distinction. The .entities sub-member also needs work.

This could be a follow-up issue for the strict-mode semantics.

## Partial Implementation Complete The perspective/visibility system is now functional via commits `c5b4200` and `a529e5e`: **What's implemented:** - `entity.gridstate` tracks visible/discovered per cell - `entity.update_visibility()` computes FOV and updates gridstate - `entity.visible_entities()` returns entities within FOV - ColorLayer can bind to entity for automatic fog-of-war rendering **What remains for "strict mode":** The original issue describes `entity.at(x, y)` returning a GridPointState with: - `gps.discovered == False` → `gps.point == None` - `gps.discovered == True && visible == False` → `gps.point` is stale copy - `gps.visible == True` → `gps.point` is live reference with `.entities` Current implementation has `entity.at(x, y)` but doesn't yet implement the stale-copy vs live-reference distinction. The `.entities` sub-member also needs work. This could be a follow-up issue for the strict-mode semantics.
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 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#16
No description provided.