perf: harden runtime for weaker hardware
This commit is contained in:
@@ -10,8 +10,11 @@ func _initialize() -> void:
|
||||
|
||||
func _run() -> void:
|
||||
_test_combat_and_wolf()
|
||||
_test_wolf_closes_distance_before_striking()
|
||||
_test_npc_death_signals_observe_authoritative_death()
|
||||
_test_war_motivation()
|
||||
_test_player_combat_and_restore()
|
||||
_test_raid_plunder_uses_authoritative_pantry()
|
||||
_finish()
|
||||
|
||||
|
||||
@@ -98,15 +101,101 @@ func _test_war_motivation() -> void:
|
||||
weak_manager.free()
|
||||
|
||||
|
||||
func _test_wolf_closes_distance_before_striking() -> void:
|
||||
var manager := _create_manager(986)
|
||||
var target: SimNPC = manager.npcs[0]
|
||||
target.position = Vector3.ZERO
|
||||
for index in range(1, manager.npcs.size()):
|
||||
manager.npcs[index].position = Vector3(80.0 + index, 0.0, 80.0)
|
||||
manager.update_player_combatant(Vector3(120.0, 0.0, 120.0))
|
||||
var target_combatant: CombatantStateRecord = manager.get_combatant(
|
||||
SimulationIds.npc_combatant_id(target.id)
|
||||
)
|
||||
var wolf_id: StringName = manager.spawn_wolf(Vector3(10.0, 0.0, 0.0))
|
||||
var wolf: CombatantStateRecord = manager.get_combatant(wolf_id)
|
||||
var health_before := target_combatant.get_health()
|
||||
var distance_before := wolf.get_position().distance_to(target.position)
|
||||
|
||||
manager.simulate_tick()
|
||||
|
||||
_check(
|
||||
is_equal_approx(target_combatant.get_health(), health_before),
|
||||
"The 18 metre wolf hunt radius should not become a remote melee strike"
|
||||
)
|
||||
_check(
|
||||
wolf.get_position().distance_to(target.position) < distance_before,
|
||||
"An alerted wolf should move its authoritative position toward its defender"
|
||||
)
|
||||
manager.free()
|
||||
|
||||
|
||||
func _test_npc_death_signals_observe_authoritative_death() -> void:
|
||||
var manager := _create_manager(987)
|
||||
var npc: SimNPC = manager.npcs[0]
|
||||
npc.current_task = SimulationIds.ACTION_GATHER_FOOD
|
||||
npc.task_state = SimNPC.TASK_STATE_TRAVELING
|
||||
npc.target_id = &"missing_test_resource"
|
||||
npc.has_travel_target = true
|
||||
var death_observed := [false]
|
||||
var task_change_observed := [false]
|
||||
manager.npc_died.connect(
|
||||
func(dead_npc: SimNPC):
|
||||
death_observed[0] = (
|
||||
dead_npc == npc
|
||||
and dead_npc.is_dead
|
||||
and dead_npc.current_task == SimulationIds.ACTION_DEAD
|
||||
and dead_npc.target_id == &""
|
||||
and not dead_npc.has_travel_target
|
||||
)
|
||||
)
|
||||
manager.npc_task_changed.connect(
|
||||
func(changed_npc: SimNPC, old_task: StringName, new_task: StringName):
|
||||
task_change_observed[0] = (
|
||||
changed_npc == npc
|
||||
and changed_npc.is_dead
|
||||
and old_task == SimulationIds.ACTION_GATHER_FOOD
|
||||
and new_task == SimulationIds.ACTION_DEAD
|
||||
)
|
||||
)
|
||||
var combatant: CombatantStateRecord = manager.get_combatant(
|
||||
SimulationIds.npc_combatant_id(npc.id)
|
||||
)
|
||||
manager.conflict_system.call(
|
||||
"_apply_damage", combatant, combatant.get_health(), SimulationIds.PLAYER_ACTOR_ID
|
||||
)
|
||||
_check(
|
||||
death_observed[0] and task_change_observed[0],
|
||||
"NPC death and task listeners should observe an already-dead, released simulation record"
|
||||
)
|
||||
manager.free()
|
||||
|
||||
|
||||
func _test_player_combat_and_restore() -> void:
|
||||
var manager := _create_manager(984)
|
||||
var wolf_id: StringName = manager.spawn_wolf(Vector3(0.0, 0.0, 0.0))
|
||||
var friendly: SimNPC = manager.npcs[0]
|
||||
_check(
|
||||
is_equal_approx(manager.player_attack(SimulationIds.npc_combatant_id(friendly.id)), 0.0),
|
||||
"Simulation authority should reject a player attack against a friendly villager"
|
||||
)
|
||||
var distant_wolf_id: StringName = manager.spawn_wolf(Vector3(20.0, 0.0, 0.0))
|
||||
_check(
|
||||
is_equal_approx(manager.player_attack(distant_wolf_id), 0.0),
|
||||
"Simulation authority should reject an out-of-range sword strike"
|
||||
)
|
||||
var wolf_id := distant_wolf_id
|
||||
var wolf: CombatantStateRecord = manager.get_combatant(wolf_id)
|
||||
wolf.set_position(Vector3.ZERO)
|
||||
_check(
|
||||
is_equal_approx(manager.player_attack(wolf_id), 24.0),
|
||||
"The player's sword strike should deal its configured damage"
|
||||
)
|
||||
_check(is_equal_approx(wolf.get_health(), 16.0), "The wolf should survive one sword strike")
|
||||
_check(
|
||||
is_equal_approx(manager.player_attack(wolf_id), 0.0),
|
||||
"Simulation authority should enforce the configured player attack cooldown"
|
||||
)
|
||||
var sword := SimulationItems.get_weapon(SimulationIds.ITEM_SWORD)
|
||||
manager.advance_player_combat_time(sword.attack_cooldown)
|
||||
manager.player_attack(wolf_id)
|
||||
_check(not wolf.is_alive(), "A second sword strike should kill the wolf")
|
||||
_check(
|
||||
@@ -118,6 +207,8 @@ func _test_player_combat_and_restore() -> void:
|
||||
"The dead wolf should leave the living-hostile set"
|
||||
)
|
||||
|
||||
manager.get_player_state().take_damage(35.0)
|
||||
manager.call("_sync_player_combatant")
|
||||
var saved_json: String = manager.serialize_state()
|
||||
var restored := _create_manager(985)
|
||||
_check(
|
||||
@@ -129,13 +220,42 @@ func _test_player_combat_and_restore() -> void:
|
||||
restored.get_state_checksum() == manager.get_state_checksum()
|
||||
and restored.get_faction(SimulationIds.FACTION_TRIBE) != null
|
||||
and not restored.get_combatant(wolf_id).is_alive()
|
||||
and is_equal_approx(
|
||||
restored.get_combatant(&"player_combatant").get_health(),
|
||||
restored.get_player_state().get_health()
|
||||
)
|
||||
),
|
||||
"Restore should preserve combatant health, factions, and checksum"
|
||||
"Restore should preserve hostile state, factions, checksum, and player health parity"
|
||||
)
|
||||
restored.free()
|
||||
manager.free()
|
||||
|
||||
|
||||
func _test_raid_plunder_uses_authoritative_pantry() -> void:
|
||||
var manager := _create_manager(988)
|
||||
var pantry: StorageStateRecord = manager.get_pantry()
|
||||
pantry.withdraw(SimulationIds.RESOURCE_FOOD, pantry.get_amount(SimulationIds.RESOURCE_FOOD))
|
||||
pantry.deposit(SimulationIds.RESOURCE_FOOD, 10.0)
|
||||
manager.economy.sync_resource(SimulationIds.RESOURCE_FOOD)
|
||||
var village_faction: FactionStateRecord = manager.get_faction(SimulationIds.FACTION_VILLAGE)
|
||||
var tribe: FactionStateRecord = manager.get_faction(SimulationIds.FACTION_TRIBE)
|
||||
village_faction.set_food(10.0)
|
||||
var tribe_food_before := tribe.get_food()
|
||||
|
||||
manager.conflict_system.call("_finish_war", SimulationIds.WAR_PLAN_ABORTED, &"village_lost")
|
||||
|
||||
_check(
|
||||
(
|
||||
is_equal_approx(pantry.get_amount(SimulationIds.RESOURCE_FOOD), 4.0)
|
||||
and is_equal_approx(manager.village.food, 4.0)
|
||||
and is_equal_approx(village_faction.get_food(), 4.0)
|
||||
and is_equal_approx(tribe.get_food(), tribe_food_before + 6.0)
|
||||
),
|
||||
"Raid plunder should transfer real pantry food instead of mutating only faction display state"
|
||||
)
|
||||
manager.free()
|
||||
|
||||
|
||||
func _set_all_strength(manager: Node, strength: float) -> void:
|
||||
for npc in manager.npcs:
|
||||
npc.strength = strength
|
||||
|
||||
Reference in New Issue
Block a user