game: cache some calculations for enemies
This commit is contained in:
17
scenes/utils/keyed_cache.gd
Normal file
17
scenes/utils/keyed_cache.gd
Normal 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)
|
Reference in New Issue
Block a user