Gunkable clear_total_updated signal also includes delta since last call

This commit is contained in:
Rob Kelly 2025-07-12 13:15:07 -06:00
parent 9bf5fa6f53
commit 7e4b3024d3
5 changed files with 11 additions and 30 deletions

View File

@ -2,22 +2,21 @@ class_name GrunkDust extends GPUParticles3D
@export var emit_scale := 0.1 @export var emit_scale := 0.1
var _last_clear_total := 0.0
var _emitting_this_frame := false var _emitting_this_frame := false
func _on_gunkable_clear_total_updated(clear_total: float) -> void: func _on_gunkable_clear_total_updated(_clear_total: float, delta: float) -> void:
var delta := maxf(clear_total - _last_clear_total, 0)
amount_ratio = clampf(delta * emit_scale, 0, 1) amount_ratio = clampf(delta * emit_scale, 0, 1)
if delta > 0: if delta > 0:
_emitting_this_frame = true _emitting_this_frame = true
_last_clear_total = clear_total
func _on_gunkable_painted_at_point(point: Vector3, normal: Vector3) -> void: 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: func _process(_delta: float) -> void:

View File

@ -18,5 +18,5 @@ func _deferred_init() -> void:
gunkable.trigger_recompute() 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 spot_light_3d.visible = clear_total > threshold

View File

@ -83,7 +83,7 @@ func _animation_finished(anim_name: StringName) -> void:
interactive.enabled = enabled 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: if not clean and clear_total >= CLEAN_THRESHOLD:
_on_clean() _on_clean()

View File

@ -2,7 +2,7 @@ class_name Gunkable extends Node
## Component behavior for gunkable props & geometry. ## Component behavior for gunkable props & geometry.
## Emitted from the main thread after the clear total is asynchronously updated. ## 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 ## Emitted from the main thread any time a point is painted
signal painted_at_point(point: Vector3, normal: Vector3) signal painted_at_point(point: Vector3, normal: Vector3)
@ -263,7 +263,7 @@ func _process(_delta: float) -> void:
_mutex.unlock() _mutex.unlock()
var delta := new_total - _prev_clear_total var delta := new_total - _prev_clear_total
if abs(delta) > CLEAR_TOTAL_EPSILON: 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 # Do not fire signal on first compute after initialization
# This prevents the player from collecting the grunk from the initial mask. # This prevents the player from collecting the grunk from the initial mask.
if _prev_clear_total >= 0 and World.instance: if _prev_clear_total >= 0 and World.instance:

View File

@ -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://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="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"]] [node name="Gunkable" type="Node" groups=["Persistent"]]
script = ExtResource("1_47xoo") script = ExtResource("1_47xoo")
@ -47,19 +42,6 @@ grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
script = ExtResource("2_srn13") 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/MaskClear" to="MaskViewport/MaskControl" method="_set_dirty"]
[connection signal="visibility_changed" from="MaskViewport/MaskTexture" 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"] [connection signal="draw" from="MaskViewport/MaskControl" to="." method="_on_mask_painted"]