refactor: clarify simulation ownership

This commit is contained in:
Rijad Zuzo
2026-07-10 11:02:11 +02:00
parent 0f7b12080e
commit ce8f71082b
29 changed files with 793 additions and 587 deletions
+30 -19
View File
@@ -375,40 +375,46 @@ glyphs.
### `simulation/SimNPC.gd`
`SimNPC` is a `RefCounted` simulation model. It owns needs, task selection,
task progression, profession affinity, starvation, and death.
task state, profession affinity, carried inventory, starvation, and death.
This separation from the visual node is an important architectural seed and
should be preserved.
### `simulation/SimVillage.gd`
`SimVillage` is a `RefCounted` aggregate for shared resources, modifiers,
priorities, and applying completed NPC work.
`SimVillage` is a `RefCounted` aggregate for synchronized village resource
views, modifiers, and priorities.
### `simulation/SimulationManager.gd`
`SimulationManager` is currently a scene-tree `Node` that:
- owns the village and NPC array;
- advances a tick approximately every 1.2 seconds;
- advances deterministic ticks through `SimulationClock`;
- creates NPCs;
- coordinates task completion;
- coordinates selection, travel, reservations, and task completion;
- emits village, task, and death signals;
- exposes direct resource-changing methods to the player.
- exposes the bounded player/simulation command API.
It currently combines clock, orchestration, event publication, population
creation, and some gameplay API responsibilities.
Focused `RefCounted` collaborators keep rule ownership visible:
- action systems own selection, execution progress, and target resolution;
- `VillageEconomy` owns storage/inventory transactions and synchronized
village resource views;
- `SimulationEventLog` owns deterministic event history and queries.
`SimulationManager` remains the scene-tree façade and signal boundary rather
than duplicating these responsibilities across additional manager nodes.
### `world/world_view_manager.gd`
`WorldViewManager` bridges simulation data to visible NPC nodes. It:
- instantiates `NpcVisual` scenes;
- resolves resource nodes, random wander targets, and remaining activity
markers;
- writes the selected ResourceNode ID onto the NPC as a transitional behavior;
- sends targets to visuals;
- supplies active visual positions for simulation-owned target resolution;
- sends resolved travel destinations to visuals;
- reports arrival and navigation failure back to `SimulationManager`;
- synchronizes successful visual movement into authoritative NPC position;
- applies visual death state.
### `player/npc/NpcVisual.gd`
@@ -456,7 +462,9 @@ NpcVisual navigates through the active world
| Later ticks complete work
| |
| v
| ResourceStateRecord.extract() -> village.apply_resource_delta()
| ResourceStateRecord.extract() -> NPC inventory
| -> VillageEconomy transfers inventory/storage as actions complete
| -> SimulationEventLog appends completed facts
| |
| v
| village_changed signal updates the UI
@@ -488,6 +496,9 @@ NpcVisual navigates through the active world
│ ├── SimulationManager.gd
│ ├── actions/ Selection, execution, and target resolution
│ ├── definitions/ Stable IDs and custom definition resources
│ ├── economy/ Inventory and storage transactions
│ ├── events/ Ordered event history and queries
│ ├── persistence/ Validated local save-slot storage
│ └── state/ Versioned simulation-state records
├── tests/
│ ├── action_system_boundaries_test.gd
@@ -538,9 +549,9 @@ These are expected prototype constraints, not necessarily isolated bugs:
- Automated coverage includes deterministic same-seed and save/restore
continuation checks, player-parity/resource-contention, flat-map, and Jajce
scaffold scenarios; broader gameplay coverage is still missing.
- Resources are global floating-point counters rather than items in locations
and inventories, except food, which now moves through sources, NPC inventory,
and the village pantry.
- Food and wood now move through finite sources, NPC inventory, and typed
village storage. Other village metrics remain aggregate values rather than
located items.
- NPCs do not have homes, schedules, possessions, memories, relationships,
goals, or social knowledge.
- The reason inspector exposes current decisions, but deeper historical traces
@@ -549,9 +560,9 @@ These are expected prototype constraints, not necessarily isolated bugs:
- Unloaded traveling NPCs preserve their state but do not yet advance through
abstract travel time.
- There is no spatial query/index layer for large populations.
- SimulationManager still orchestrates multiple systems and player-facing
mutation APIs, but selection, execution, target resolution, and active-world
queries now have focused collaborators.
- SimulationManager still coordinates the tick lifecycle and bounded
player-facing commands, while action rules, active-world queries, economic
transactions, and event history have focused collaborators.
- Path failure and interruption emit a `navigation_failed` signal and send the NPC to wander; this is functional but not yet polished.
- The old greybox navigation source has been replaced by a project-owned
Terrain3D-derived navigation resource. The current bake is still a first