perf: harden runtime for weaker hardware
This commit is contained in:
@@ -7,6 +7,90 @@ const EventKnowledgeSystemScript := preload("res://simulation/knowledge/EventKno
|
||||
const SimulationManagerScript := preload("res://simulation/SimulationManager.gd")
|
||||
|
||||
|
||||
func test_simulation_clock_caps_frame_work_without_discarding_backlog() -> void:
|
||||
var clock := SimulationClock.new(1.0)
|
||||
clock.cycle_duration_seconds = 100.0
|
||||
|
||||
assert_eq(clock.advance(10.0, 3), 3)
|
||||
assert_eq(clock.elapsed_ticks, 3)
|
||||
assert_eq(clock.accumulator, 7.0)
|
||||
assert_true(is_equal_approx(clock.time_of_day(), 0.03))
|
||||
assert_eq(clock.advance(0.0, 3), 3)
|
||||
assert_eq(clock.elapsed_ticks, 6)
|
||||
assert_eq(clock.accumulator, 4.0)
|
||||
assert_true(is_equal_approx(clock.time_of_day(), 0.06))
|
||||
|
||||
var fractional_clock := SimulationClock.new(1.0)
|
||||
fractional_clock.cycle_duration_seconds = 100.0
|
||||
assert_eq(fractional_clock.advance(0.25, 3), 0)
|
||||
assert_true(is_equal_approx(fractional_clock.time_of_day(), 0.0025))
|
||||
|
||||
|
||||
func test_player_attack_uses_definition_reach_and_unscaled_realtime_cooldown() -> void:
|
||||
var conflict := ConflictSystem.new()
|
||||
conflict.configure(null, 0.1)
|
||||
conflict.initialize_factions()
|
||||
conflict.set_player_combatant_position(Vector3.ZERO)
|
||||
var sword := SimulationItems.get_weapon(SimulationIds.ITEM_SWORD)
|
||||
assert_not_null(sword)
|
||||
var wolf_id := conflict.spawn_wolf(Vector3(sword.reach + 0.01, 8.0, 0.0))
|
||||
var wolf := conflict.get_combatant(wolf_id)
|
||||
|
||||
assert_eq(conflict.player_attack(wolf_id), 0.0)
|
||||
wolf.set_position(Vector3(sword.reach - 0.01, 8.0, 0.0))
|
||||
assert_eq(conflict.player_attack(wolf_id), sword.damage)
|
||||
assert_false(conflict.is_player_attack_ready())
|
||||
conflict.advance(1)
|
||||
assert_false(conflict.is_player_attack_ready())
|
||||
conflict.advance_realtime(sword.attack_cooldown - 0.01)
|
||||
assert_false(conflict.is_player_attack_ready())
|
||||
conflict.advance_realtime(0.02)
|
||||
assert_true(conflict.is_player_attack_ready())
|
||||
|
||||
|
||||
func test_player_dash_duration_and_cooldown_are_enforced_separately() -> void:
|
||||
var controller := PlayerCombatController.new()
|
||||
var player := CharacterBody3D.new()
|
||||
controller.player = player
|
||||
player.add_child(controller)
|
||||
add_child_autofree(player)
|
||||
var sword := SimulationItems.get_weapon(SimulationIds.ITEM_SWORD)
|
||||
|
||||
assert_true(is_equal_approx(controller.attack_range, sword.reach))
|
||||
controller.call("_perform_dash")
|
||||
assert_true(controller.is_dashing())
|
||||
assert_true(
|
||||
is_equal_approx(controller.get_dash_cooldown_remaining(), controller.dash_cooldown_seconds)
|
||||
)
|
||||
controller.call("_advance_timers", controller.dash_duration + 0.01)
|
||||
assert_false(controller.is_dashing())
|
||||
controller.call("_perform_dash")
|
||||
assert_false(controller.is_dashing())
|
||||
controller.call("_advance_timers", controller.get_dash_cooldown_remaining())
|
||||
controller.call("_perform_dash")
|
||||
assert_true(controller.is_dashing())
|
||||
|
||||
|
||||
func test_combat_cooldown_uses_the_configured_simulation_tick() -> void:
|
||||
var combatant := CombatantStateRecord.create(
|
||||
&"cooldown_test",
|
||||
SimulationIds.COMBATANT_KIND_PLAYER,
|
||||
SimulationIds.FACTION_VILLAGE,
|
||||
"Cooldown Tester",
|
||||
Vector3.ZERO,
|
||||
100.0,
|
||||
SimulationIds.ITEM_SWORD
|
||||
)
|
||||
|
||||
combatant.mark_attacked(0.3)
|
||||
assert_eq(combatant.get_attack_cooldown(), 2)
|
||||
combatant.tick_cooldown()
|
||||
combatant.tick_cooldown()
|
||||
assert_true(combatant.is_attack_ready())
|
||||
combatant.mark_attacked(1.2)
|
||||
assert_eq(combatant.get_attack_cooldown(), 1)
|
||||
|
||||
|
||||
func test_storage_never_accepts_more_than_its_capacity() -> void:
|
||||
var storage := StorageStateRecord.create(&"test_storage", {"food": 4.5}, 5.0)
|
||||
|
||||
@@ -30,6 +114,22 @@ func test_economy_moves_inventory_into_authoritative_storage() -> void:
|
||||
assert_eq(village.food, 5.0)
|
||||
|
||||
|
||||
func test_failed_food_consumption_preserves_fractional_inventory() -> void:
|
||||
var village := SimVillage.new()
|
||||
var economy := VillageEconomyScript.new()
|
||||
economy.configure(village, false)
|
||||
var npc := SimNPC.new(8, "Fractional", SimulationIds.PROFESSION_FARMER, 5.0, 5.0)
|
||||
npc.hunger = 50.0
|
||||
npc.add_inventory(SimulationIds.RESOURCE_FOOD, 0.5)
|
||||
var event_count := [0]
|
||||
economy.economic_event_requested.connect(func(_a, _b, _c, _d, _e, _f): event_count[0] += 1)
|
||||
|
||||
assert_false(economy.consume_npc_food(npc))
|
||||
assert_eq(npc.get_inventory_amount(SimulationIds.RESOURCE_FOOD), 0.5)
|
||||
assert_eq(npc.hunger, 55.0)
|
||||
assert_eq(event_count[0], 0)
|
||||
|
||||
|
||||
func test_event_log_preserves_order_and_derives_consumption_rate() -> void:
|
||||
var event_log := SimulationEventLogScript.new()
|
||||
event_log.record_narrative(10, SimulationIds.EVENT_TASK_STARTED, 4, &"", "Study")
|
||||
|
||||
Reference in New Issue
Block a user