Phase 1: Safety & performance foundation for Grid/Entity overhaul

- Fix Entity3D self-reference cycle: replace raw `self` pointer with
  `pyobject` strong-ref pattern matching UIEntity (closes #266)
- TileLayer inherits Grid texture when none set, in all three attachment
  paths: constructor, add_layer(), and .grid property (closes #254)
- Add SpatialHash::queryCell() for O(1) entity-at-cell lookup; fix
  missing spatial_hash.insert() in Entity.__init__ grid= kwarg path;
  use queryCell in GridPoint.entities (closes #253)
- Add FOV dirty flag and parameter cache to skip redundant computeFOV
  calls when map unchanged and params match (closes #292)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
John McCardle 2026-03-15 21:48:24 -04:00
commit 94f5f5a3fd
13 changed files with 436 additions and 47 deletions

View file

@ -135,6 +135,13 @@ public:
TCOD_fov_algorithm_t fov_algorithm; // Default FOV algorithm (from mcrfpy.default_fov)
int fov_radius; // Default FOV radius
// #292 - FOV deduplication: skip redundant computations
bool fov_dirty = true; // Set true when TCOD map changes
int fov_last_x = -1, fov_last_y = -1; // Last FOV computation parameters
int fov_last_radius = -1;
bool fov_last_light_walls = true;
TCOD_fov_algorithm_t fov_last_algo = FOV_BASIC;
// #142, #230 - Grid cell mouse events
// Cell hover callbacks take only (cell_pos); cell click still takes (cell_pos, button, action)
std::unique_ptr<PyCellHoverCallable> on_cell_enter_callable;