Dynamically adapt POOL SIZE for ring effect
This commit is contained in:
@@ -2,10 +2,11 @@ class_name Water
|
||||
extends TextureRect
|
||||
|
||||
const WATER_RING_SCENE: PackedScene = preload("res://sources/utils/fx/water_ring.tscn")
|
||||
# Up to MAX_TURTLE_COUNT (5) turtles each loop the swim animation roughly
|
||||
# every 0.7s, so ~7-8 rings/second. The pool absorbs the bursts without
|
||||
# instantiate/queue_free churn on every loop.
|
||||
const POOL_SIZE: int = 12
|
||||
# Rings are checked out for the full 3.0s particle lifetime.
|
||||
# Worst case: 5 turtles (MAX_TURTLE_COUNT) each looping the swim animation
|
||||
# every 8/12 = 0.667s emit ~7.5 rings/sec → ~23 concurrent in flight.
|
||||
# We pre-allocate 24 and grow on demand if real usage ever exceeds that.
|
||||
const POOL_SIZE: int = 24
|
||||
|
||||
@export var ring_color: Color
|
||||
|
||||
@@ -14,19 +15,21 @@ var _available_rings: Array[WaterRingFX] = []
|
||||
|
||||
func _ready() -> void:
|
||||
for _index: int in POOL_SIZE:
|
||||
var fx: WaterRingFX = WATER_RING_SCENE.instantiate()
|
||||
fx.modulate = ring_color
|
||||
fx.hide()
|
||||
add_child(fx)
|
||||
_available_rings.append(fx)
|
||||
_available_rings.append(_make_ring())
|
||||
|
||||
|
||||
func spawn_water_ring(pos: Vector2) -> void:
|
||||
if _available_rings.is_empty():
|
||||
return
|
||||
var fx: WaterRingFX = _available_rings.pop_back()
|
||||
var fx: WaterRingFX = _available_rings.pop_back() if not _available_rings.is_empty() else _make_ring()
|
||||
fx.position = pos
|
||||
fx.show()
|
||||
await fx.play()
|
||||
fx.hide()
|
||||
_available_rings.append(fx)
|
||||
|
||||
|
||||
func _make_ring() -> WaterRingFX:
|
||||
var fx: WaterRingFX = WATER_RING_SCENE.instantiate()
|
||||
fx.modulate = ring_color
|
||||
fx.hide()
|
||||
add_child(fx)
|
||||
return fx
|
||||
|
||||
Reference in New Issue
Block a user