perf: harden runtime for weaker hardware
This commit is contained in:
@@ -195,6 +195,18 @@ func set_hostile(value: bool) -> void:
|
||||
changed.emit(self)
|
||||
|
||||
|
||||
func set_health_and_alive(value: float, alive: bool) -> void:
|
||||
if not is_finite(value):
|
||||
return
|
||||
var next_health := clampf(value, 0.0, get_max_health()) if alive else 0.0
|
||||
var next_alive := alive and next_health > 0.0
|
||||
if is_equal_approx(next_health, get_health()) and bool(data["alive"]) == next_alive:
|
||||
return
|
||||
data["health"] = next_health
|
||||
data["alive"] = next_alive
|
||||
changed.emit(self)
|
||||
|
||||
|
||||
func tick_cooldown() -> void:
|
||||
if get_attack_cooldown() > 0:
|
||||
data["attack_cooldown"] = get_attack_cooldown() - 1
|
||||
@@ -211,14 +223,14 @@ func take_damage(amount: float) -> float:
|
||||
return previous - get_health()
|
||||
|
||||
|
||||
func mark_attacked() -> void:
|
||||
data["attack_cooldown"] = _weapon_cooldown_ticks()
|
||||
func mark_attacked(tick_interval: float = 1.2) -> void:
|
||||
data["attack_cooldown"] = _weapon_cooldown_ticks(tick_interval)
|
||||
|
||||
|
||||
func _weapon_cooldown_ticks() -> int:
|
||||
func _weapon_cooldown_ticks(tick_interval: float) -> int:
|
||||
var weapon := SimulationItems.get_weapon(get_weapon_id())
|
||||
var seconds := weapon.attack_cooldown if weapon != null else 0.6
|
||||
return maxi(int(ceil(seconds / 1.2)), 1)
|
||||
return maxi(int(ceil(seconds / maxf(tick_interval, 0.0001))), 1)
|
||||
|
||||
|
||||
func to_dictionary() -> Dictionary:
|
||||
|
||||
Reference in New Issue
Block a user