game: cache some calculations for enemies
This commit is contained in:
@@ -27,6 +27,7 @@ var is_dead: bool = false
|
||||
var health: float
|
||||
|
||||
var _path_update_timer: float = 0.0
|
||||
var _compute_cache: KeyedCache = KeyedCache.new()
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -177,17 +178,19 @@ func _on_animation_player_animation_finished(anim_name: StringName) -> void:
|
||||
|
||||
func get_calculated(key: String) -> Variant:
|
||||
# set max move speed to players move speed
|
||||
if key == "move_speed":
|
||||
return clampf(
|
||||
EnemyMod.get_calculated(self, key),
|
||||
0,
|
||||
player.player_stats.get_final("move_speed", player.modifiers)
|
||||
)
|
||||
return EnemyMod.get_calculated(self, key)
|
||||
var compute_func = func():
|
||||
if key == "move_speed":
|
||||
return clampf(
|
||||
EnemyMod.get_calculated(self, key),
|
||||
0,
|
||||
player.player_stats.get_final("move_speed", player.modifiers)
|
||||
)
|
||||
return EnemyMod.get_calculated(self, key)
|
||||
|
||||
return _compute_cache.get_or_compute(key, compute_func)
|
||||
|
||||
|
||||
func has_property(key: String) -> bool:
|
||||
for prop in get_property_list():
|
||||
if prop.name == key:
|
||||
return true
|
||||
return false
|
||||
var cache_key = "prop_%s" % key
|
||||
var compute_func = func(): return get(key) != null
|
||||
return _compute_cache.get_or_compute(key, compute_func)
|
||||
|
Reference in New Issue
Block a user