From 7e4b3024d3c893a3befa49dd33823700fd5f2fae Mon Sep 17 00:00:00 2001 From: Rob Kelly Date: Sat, 12 Jul 2025 13:15:07 -0600 Subject: [PATCH] Gunkable clear_total_updated signal also includes delta since last call --- src/effects/grunk_dust/grunk_dust.gd | 13 ++++++------- src/props/overhead_light/overhead_light.gd | 2 +- src/props/wall_switch/wall_switch.gd | 2 +- src/world/gunkable/gunkable.gd | 4 ++-- src/world/gunkable/gunkable.tscn | 20 +------------------- 5 files changed, 11 insertions(+), 30 deletions(-) diff --git a/src/effects/grunk_dust/grunk_dust.gd b/src/effects/grunk_dust/grunk_dust.gd index 13ea507..fdd783a 100644 --- a/src/effects/grunk_dust/grunk_dust.gd +++ b/src/effects/grunk_dust/grunk_dust.gd @@ -2,22 +2,21 @@ class_name GrunkDust extends GPUParticles3D @export var emit_scale := 0.1 -var _last_clear_total := 0.0 var _emitting_this_frame := false -func _on_gunkable_clear_total_updated(clear_total: float) -> void: - var delta := maxf(clear_total - _last_clear_total, 0) - +func _on_gunkable_clear_total_updated(_clear_total: float, delta: float) -> void: amount_ratio = clampf(delta * emit_scale, 0, 1) if delta > 0: _emitting_this_frame = true - _last_clear_total = clear_total - func _on_gunkable_painted_at_point(point: Vector3, normal: Vector3) -> void: - look_at_from_position(point, point + normal, global_basis.y) + # An arbitrary orthogonal vector + # NOTE: will not be orthogonal 100% of the time, as a consequence of the Hairy Ball Theorem + # ... No, seriously. + var ortho := Vector3(normal.y + normal.z, normal.z - normal.x, -normal.x - normal.y) + look_at_from_position(point, point + normal, ortho) func _process(_delta: float) -> void: diff --git a/src/props/overhead_light/overhead_light.gd b/src/props/overhead_light/overhead_light.gd index e468fb3..33b1228 100644 --- a/src/props/overhead_light/overhead_light.gd +++ b/src/props/overhead_light/overhead_light.gd @@ -18,5 +18,5 @@ func _deferred_init() -> void: gunkable.trigger_recompute() -func _on_clear_total_updated(clear_total: float) -> void: +func _on_clear_total_updated(clear_total: float, _delta: float) -> void: spot_light_3d.visible = clear_total > threshold diff --git a/src/props/wall_switch/wall_switch.gd b/src/props/wall_switch/wall_switch.gd index c110f4f..0659c4e 100644 --- a/src/props/wall_switch/wall_switch.gd +++ b/src/props/wall_switch/wall_switch.gd @@ -83,7 +83,7 @@ func _animation_finished(anim_name: StringName) -> void: interactive.enabled = enabled -func _on_clear_total_updated(clear_total: float) -> void: +func _on_clear_total_updated(clear_total: float, _delta: float) -> void: if not clean and clear_total >= CLEAN_THRESHOLD: _on_clean() diff --git a/src/world/gunkable/gunkable.gd b/src/world/gunkable/gunkable.gd index 791c04e..627e04b 100644 --- a/src/world/gunkable/gunkable.gd +++ b/src/world/gunkable/gunkable.gd @@ -2,7 +2,7 @@ class_name Gunkable extends Node ## Component behavior for gunkable props & geometry. ## Emitted from the main thread after the clear total is asynchronously updated. -signal clear_total_updated(clear_total: float) +signal clear_total_updated(clear_total: float, delta: float) ## Emitted from the main thread any time a point is painted signal painted_at_point(point: Vector3, normal: Vector3) @@ -263,7 +263,7 @@ func _process(_delta: float) -> void: _mutex.unlock() var delta := new_total - _prev_clear_total if abs(delta) > CLEAR_TOTAL_EPSILON: - clear_total_updated.emit(new_total) + clear_total_updated.emit(new_total, delta) # Do not fire signal on first compute after initialization # This prevents the player from collecting the grunk from the initial mask. if _prev_clear_total >= 0 and World.instance: diff --git a/src/world/gunkable/gunkable.tscn b/src/world/gunkable/gunkable.tscn index 85212e2..3666ab1 100644 --- a/src/world/gunkable/gunkable.tscn +++ b/src/world/gunkable/gunkable.tscn @@ -1,12 +1,7 @@ -[gd_scene load_steps=5 format=3 uid="uid://cdi5sl60mw1po"] +[gd_scene load_steps=3 format=3 uid="uid://cdi5sl60mw1po"] [ext_resource type="Script" uid="uid://co0g2klfmor48" path="res://src/world/gunkable/gunkable.gd" id="1_47xoo"] [ext_resource type="Script" uid="uid://bom5qysgfvap1" path="res://src/world/gunkable/draw_controller.gd" id="2_srn13"] -[ext_resource type="PackedScene" uid="uid://c3iv00vmdqxp0" path="res://src/effects/grunk_dust/grunk_dust.tscn" id="3_vad3y"] - -[sub_resource type="CapsuleMesh" id="CapsuleMesh_3mpo3"] -radius = 0.1 -height = 1.0 [node name="Gunkable" type="Node" groups=["Persistent"]] script = ExtResource("1_47xoo") @@ -47,19 +42,6 @@ grow_horizontal = 2 grow_vertical = 2 script = ExtResource("2_srn13") -[node name="GunkDust" parent="." instance=ExtResource("3_vad3y")] -top_level = true -emitting = false -amount = 64 -lifetime = 1.2 - -[node name="DebugMesh" type="MeshInstance3D" parent="GunkDust"] -transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0) -visible = false -mesh = SubResource("CapsuleMesh_3mpo3") - -[connection signal="clear_total_updated" from="." to="GunkDust" method="_on_gunkable_clear_total_updated"] -[connection signal="painted_at_point" from="." to="GunkDust" method="_on_gunkable_painted_at_point"] [connection signal="visibility_changed" from="MaskViewport/MaskClear" to="MaskViewport/MaskControl" method="_set_dirty"] [connection signal="visibility_changed" from="MaskViewport/MaskTexture" to="MaskViewport/MaskControl" method="_set_dirty"] [connection signal="draw" from="MaskViewport/MaskControl" to="." method="_on_mask_painted"]