Apply Fix 3: track and kill shader tweens on rebuild
Adds _active_tweens list to UnitMeshBuilder. Both materialize and dissolve shader tweens are appended on creation and auto-erased via CONNECT_ONE_SHOT on finish. rebuild_units() kills all tracked tweens before diffing so ShaderMaterial refs are released immediately instead of up to 1.35s later. _exit_tree() kills remaining tweens on scene teardown to prevent refs surviving a mid-animation forfeit or disconnect. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -33,12 +33,22 @@ var turn_glow_rings: Dictionary = {} # iid → MeshInstance3D
|
||||
var materialize_until: Dictionary = {} # iid → Time.get_ticks_msec deadline
|
||||
var unit_owner_ids: Dictionary = {} # iid → accountId
|
||||
|
||||
var _active_tweens: Array[Tween] = [] # shader tweens tracked for kill-on-rebuild
|
||||
|
||||
# ── Incremental rebuild ───────────────────────────────────────────────────────
|
||||
|
||||
## Incremental diff: add/remove units without recreating unchanged ones.
|
||||
## Recreating a unit body interrupts its running animation (idle/move/attack),
|
||||
## causing a one-frame bind-pose flash on every state echo.
|
||||
func rebuild_units(state: Dictionary) -> void:
|
||||
# Kill all in-flight shader tweens so ShaderMaterial refs are released now.
|
||||
for t: Tween in _active_tweens:
|
||||
if is_instance_valid(t):
|
||||
t.kill()
|
||||
_active_tweens.clear()
|
||||
if OS.is_debug_build():
|
||||
print("UnitMeshBuilder: rebuild - killed %d shader tweens" % _active_tweens.size())
|
||||
|
||||
# Kill any in-flight movement tweens.
|
||||
for iid: String in move_anims:
|
||||
var t: Tween = move_anims[iid] as Tween
|
||||
@@ -612,6 +622,8 @@ func _play_materialize_shader_timed(visual: Node3D, team_color: Color, duration:
|
||||
var target_scale: Vector3 = visual.scale
|
||||
visual.scale = target_scale * 0.92
|
||||
var tween: Tween = create_tween()
|
||||
_active_tweens.append(tween)
|
||||
tween.finished.connect(func() -> void: _active_tweens.erase(tween), CONNECT_ONE_SHOT)
|
||||
tween.set_trans(Tween.TRANS_CUBIC)
|
||||
tween.set_ease(Tween.EASE_OUT)
|
||||
tween.parallel().tween_property(visual, "scale", target_scale, duration)
|
||||
@@ -655,6 +667,8 @@ func _play_dissolve_shader_timed(visual: Node3D, team_color: Color, duration: fl
|
||||
dissolve_mats.append(mat)
|
||||
|
||||
var tween: Tween = create_tween()
|
||||
_active_tweens.append(tween)
|
||||
tween.finished.connect(func() -> void: _active_tweens.erase(tween), CONNECT_ONE_SHOT)
|
||||
tween.set_trans(Tween.TRANS_CUBIC)
|
||||
tween.set_ease(Tween.EASE_IN)
|
||||
tween.tween_method(func(v: float) -> void:
|
||||
@@ -664,6 +678,13 @@ func _play_dissolve_shader_timed(visual: Node3D, team_color: Color, duration: fl
|
||||
, 1.0, 0.0, duration)
|
||||
|
||||
|
||||
func _exit_tree() -> void:
|
||||
for t: Tween in _active_tweens:
|
||||
if is_instance_valid(t):
|
||||
t.kill()
|
||||
_active_tweens.clear()
|
||||
|
||||
|
||||
func _collect_materialize_surfaces(node: Node, surfaces: Array[Dictionary]) -> void:
|
||||
if node is MeshInstance3D:
|
||||
var mi: MeshInstance3D = node as MeshInstance3D
|
||||
|
||||
Reference in New Issue
Block a user