game: cache some calculations for enemies

This commit is contained in:
2025-08-22 14:12:42 +02:00
parent d57a59e9fe
commit f53d91a9eb
4 changed files with 43 additions and 12 deletions

View File

@@ -0,0 +1,17 @@
class_name KeyedCache
extends Resource
var cache = {}
func get_or_compute(key: String, compute_func: Callable):
if key in cache:
return cache["key"]
var value = compute_func.call()
cache["key"] = value
return value
func invalidate_key(key: String):
cache.erase(key)