perf: harden runtime for weaker hardware
This commit is contained in:
@@ -5,6 +5,7 @@ var combatant: CombatantStateRecord
|
||||
var simulation_manager: Node
|
||||
var _flash_tween: Tween
|
||||
var _spawn_tween: Tween
|
||||
var _last_health := 0.0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -24,22 +25,21 @@ func bind(combatant_id_value: StringName, manager: Node) -> void:
|
||||
global_position = combatant.get_position()
|
||||
sim_position = combatant.get_position()
|
||||
_build_from_definition()
|
||||
_last_health = combatant.get_health()
|
||||
combatant.changed.connect(_on_combatant_changed)
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
func _on_combatant_changed(_state: CombatantStateRecord) -> void:
|
||||
if is_dead_visual or combatant == null or not is_instance_valid(combatant):
|
||||
return
|
||||
if not combatant.is_alive():
|
||||
play_death()
|
||||
return
|
||||
set_sim_position(combatant.get_position())
|
||||
|
||||
|
||||
func _on_combatant_changed(_state: CombatantStateRecord) -> void:
|
||||
if combatant == null or combatant.get_health() >= combatant.get_max_health():
|
||||
return
|
||||
_flash_hit()
|
||||
var current_health := combatant.get_health()
|
||||
if current_health < _last_health:
|
||||
_flash_hit()
|
||||
_last_health = current_health
|
||||
|
||||
|
||||
func _flash_hit() -> void:
|
||||
@@ -51,6 +51,8 @@ func _flash_hit() -> void:
|
||||
|
||||
|
||||
func play_death() -> void:
|
||||
if is_dead_visual:
|
||||
return
|
||||
is_dead_visual = true
|
||||
super.play_death()
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ const HOSTILE_SCENE := preload("res://world/combat/HostileCombatant.tscn")
|
||||
@export var wolf_spawn_positions: PackedVector3Array = PackedVector3Array()
|
||||
|
||||
var hostiles: Dictionary = {}
|
||||
var _initialized := false
|
||||
var _wolves_spawned := false
|
||||
|
||||
|
||||
@@ -20,7 +19,6 @@ func _ready() -> void:
|
||||
simulation_manager.combatant_spawned.connect(_on_combatant_spawned)
|
||||
simulation_manager.combatant_died.connect(_on_combatant_died)
|
||||
simulation_manager.state_restored.connect(_on_state_restored)
|
||||
_initialized = true
|
||||
call_deferred("_spawn_wolves")
|
||||
_refresh_from_state()
|
||||
|
||||
@@ -34,14 +32,6 @@ func _spawn_wolves() -> void:
|
||||
simulation_manager.spawn_wolf(position)
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if not _initialized:
|
||||
return
|
||||
for combatant_id in _hostile_ids():
|
||||
if not hostiles.has(combatant_id):
|
||||
_spawn_visual(combatant_id)
|
||||
|
||||
|
||||
func _hostile_ids() -> Array:
|
||||
var ids: Array[StringName] = []
|
||||
var living: Array = simulation_manager.get_living_hostile_combatants()
|
||||
|
||||
Reference in New Issue
Block a user