Overhead light checks persistent state

This commit is contained in:
Rob Kelly 2025-04-22 15:26:31 -06:00
parent e4a2f31de9
commit f560b88de8
3 changed files with 19 additions and 10 deletions

View File

@ -2,6 +2,15 @@ extends Node3D
@export var threshold := 100.0 @export var threshold := 100.0
@onready var spot_light_3d: SpotLight3D = %SpotLight3D @onready var spot_light_3d: SpotLight3D = %SpotLight3D
@onready var gunk_body: GunkBody = %GunkBody
func _ready() -> void:
_deferred_init.call_deferred()
func _deferred_init() -> void:
gunk_body.trigger_recompute()
func _on_clear_total_updated(clear_total: float) -> void: func _on_clear_total_updated(clear_total: float) -> void:

View File

@ -116,6 +116,7 @@ libraries = {
autoplay = "flicker" autoplay = "flicker"
[node name="GunkBody" parent="MeshInstance3D" instance=ExtResource("6_3gl0p")] [node name="GunkBody" parent="MeshInstance3D" instance=ExtResource("6_3gl0p")]
unique_name_in_owner = true
mask_dim = 32 mask_dim = 32
source_gunk_material = ExtResource("8_3gl0p") source_gunk_material = ExtResource("8_3gl0p")

View File

@ -76,14 +76,6 @@ func _deferred_init() -> void:
mask_texture.visible = true mask_texture.visible = true
func _trigger_recompute_deferred() -> void:
_mutex.lock()
_mask_tx = mask_viewport.get_texture()
#_mask_img = mask_viewport.get_texture().get_image()
_mutex.unlock()
_semaphore.post()
func _async_compute_clear_total() -> void: func _async_compute_clear_total() -> void:
# Ignore first two calls (initial mask clear & texture) # Ignore first two calls (initial mask clear & texture)
# NOTE: this technically could put us in a glitched state if that mask clear & texture don't happen # NOTE: this technically could put us in a glitched state if that mask clear & texture don't happen
@ -263,10 +255,10 @@ 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)
# 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: if _prev_clear_total >= 0:
clear_total_updated.emit(new_total)
# XXX due to fp error, this will drift from the "true count" over time # XXX due to fp error, this will drift from the "true count" over time
# but it probably won't matter :shrug: # but it probably won't matter :shrug:
World.instance.manager.collect_grunk(delta) World.instance.manager.collect_grunk(delta)
@ -288,9 +280,16 @@ func _process(_delta: float) -> void:
_multiline_buffer = PackedVector2Array() _multiline_buffer = PackedVector2Array()
func trigger_recompute() -> void:
_mutex.lock()
_mask_tx = mask_viewport.get_texture()
_mutex.unlock()
_semaphore.post()
func _on_mask_painted() -> void: func _on_mask_painted() -> void:
# XXX any problem with posting each frame? # XXX any problem with posting each frame?
_trigger_recompute_deferred.call_deferred() trigger_recompute.call_deferred()
func serialize() -> Dictionary: func serialize() -> Dictionary: