Implementation:4thfever Cultivation world simulator finalize step
| Knowledge Sources | |
|---|---|
| Domains | Simulation, Game_Engine |
| Last Updated | 2026-10-22 14:00 GMT |
Overview
Concrete tool for finalizing a simulation step by deduplicating events, enriching close-relation observations, persisting events, logging, and advancing the world time, provided by the Cultivation World Simulator engine.
Description
The finalize_step function is the last phase (phase 29) in the simulation pipeline. It:
- Records metrics for tracked avatars
- Deduplicates events by ID
- Enriches major events (excluding story events and special kinds) with close-relation observation data
- Persists all final events to `world.event_manager`
- Logs each event
- Increments `world.month_stamp` by 1
This function does NOT do a final reset check (its `reset_check_after` is `False`), ensuring the step completes atomically.
Usage
Import and call this function when:
- Simulation pipeline: called automatically as the final phase by `SimulationPhaseRunner.run()`
- Testing: can be called directly with a mock context to test event finalization
Code Reference
Source Location
- Repository: cultivation-world-simulator
- File: src/sim/simulator_engine/finalizer.py
Signature
def finalize_step(ctx: SimulationStepContext) -> list[Event]:
"""Finalize events, persist them, and advance the month stamp."""
def log_events(events: list[Event]) -> None:
"""Log each event via the game logger."""
Import
from src.sim.simulator_engine.finalizer import finalize_step
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| ctx | SimulationStepContext | Yes | Shared step context with accumulated events and world |
Outputs
| Name | Type | Description |
|---|---|---|
| return | Deduplicated, finalized events; same as persisted to event_manager | |
| (side effects) | Events persisted to world.event_manager; world.month_stamp incremented by 1; metrics recorded |
Usage Examples
Direct Call (for testing)
from src.sim.simulator_engine.context import SimulationStepContext
from src.sim.simulator_engine.finalizer import finalize_step
ctx = SimulationStepContext.create(world)
ctx.events = test_events # inject test events
final_events = finalize_step(ctx)
assert world.month_stamp == original_stamp + 1