perf: index simulation event history

This commit is contained in:
Rijad Zuzo
2026-08-12 20:14:57 +02:00
parent c218909649
commit e27fc1a5c8
2 changed files with 77 additions and 14 deletions
+11
View File
@@ -147,6 +147,10 @@ func test_event_log_preserves_order_and_derives_consumption_rate() -> void:
assert_eq(int(event_log.events[0].data["event_id"]), 0)
assert_eq(int(event_log.events[1].data["event_id"]), 1)
assert_eq(event_log.get_for_actor(4).size(), 2)
assert_eq(event_log.get_by_id(1), event_log.events[1])
assert_eq(event_log.get_for_type(SimulationIds.EVENT_ITEM_CONSUMED), [event_log.events[1]])
assert_eq(event_log.get_for_tick(20), [event_log.events[1]])
assert_eq(event_log.get_world_event(1).get_event_type(), SimulationIds.EVENT_ITEM_CONSUMED)
assert_eq(float(event_log.get_consumption_rates(200)["food_per_day"]), 1.0)
var legacy_event_data := event_log.events[1].to_dictionary()
legacy_event_data["schema_version"] = EconomicEventRecord.LEGACY_SCHEMA_VERSION
@@ -155,6 +159,13 @@ func test_event_log_preserves_order_and_derives_consumption_rate() -> void:
assert_not_null(migrated_event)
assert_eq(migrated_event.get_world_position(), Vector3.ZERO)
var restored_log := SimulationEventLogScript.new()
restored_log.restore(event_log.events, event_log.next_event_id)
assert_eq(restored_log.get_by_id(0), event_log.events[0])
assert_eq(restored_log.get_for_actor(4).size(), 2)
assert_eq(restored_log.get_for_type(SimulationIds.EVENT_TASK_STARTED).size(), 1)
assert_eq(restored_log.get_world_event(1).get_event_id(), 1)
func test_food_aid_builds_directed_trust_once_per_event() -> void:
var contributor := SimNPC.new(0, "Amina", SimulationIds.PROFESSION_FARMER, 5.0, 5.0)