diff --git a/src/world/gunk_body/draw_controller.gd b/src/world/gunk_body/draw_controller.gd index 8a68386..3672ca5 100644 --- a/src/world/gunk_body/draw_controller.gd +++ b/src/world/gunk_body/draw_controller.gd @@ -1,8 +1,5 @@ class_name DrawController extends Control -## Emitted the frame after at least one paint operation was done. -signal painted - var _draw_queue: Array[Callable] = [] var _dirty := false @@ -33,10 +30,13 @@ func _process(_delta: float) -> void: if _dirty: queue_redraw() _dirty = false - painted.emit() # show clear rect for one frame mask_clear.visible = _clear _clear = false mask_texture.visible = _show_texture _show_texture = false + + +func _set_dirty() -> void: + _dirty = true diff --git a/src/world/gunk_body/gunk_body.gd b/src/world/gunk_body/gunk_body.gd index cd27d9a..20fa6b9 100644 --- a/src/world/gunk_body/gunk_body.gd +++ b/src/world/gunk_body/gunk_body.gd @@ -27,7 +27,7 @@ var _multiline_buffer := PackedVector2Array() var _multiline_width := 1.0 var _clear_total := 0.0 -var _prev_clear_total := 0.0 +var _prev_clear_total := -1.0 # _clear_total is async computed in separate thread var _mask_tx: Texture2D @@ -83,6 +83,12 @@ func _trigger_recompute_deferred() -> void: func _async_compute_clear_total() -> void: + # 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 + # and the thread wouldn't be able to hit the exit condition. + # If the application hangs in a weird way immediately after loading a scene, maybe this is why! + _semaphore.wait() + _semaphore.wait() while true: _semaphore.wait() @@ -184,7 +190,6 @@ func _get_uv(point: Vector3, normal: Vector3) -> Vector2: ## Returns Vector2.INF if the given point+normal does not lie on this mesh within tolerance. func _get_px(point: Vector3, normal: Vector3) -> Vector2: debug_draw.draw_vector(normal, point) - #print_debug("POINT: ", point, "; NORMAL: ", normal) return _get_uv(point * global_transform, normal * global_basis) * mask_control.size @@ -241,10 +246,13 @@ 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) - # XXX due to fp error, this will drift from the "true count" over time - # but it probably won't matter :shrug: - Game.manager.collect_grunk(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: + clear_total_updated.emit(new_total) + # XXX due to fp error, this will drift from the "true count" over time + # but it probably won't matter :shrug: + Game.manager.collect_grunk(delta) _prev_clear_total = new_total # If paint_continuous wasn't called last frame, stop the current polyline. @@ -265,4 +273,4 @@ func _process(_delta: float) -> void: func _on_mask_painted() -> void: # XXX any problem with posting each frame? - call_deferred("_trigger_recompute_deferred") + _trigger_recompute_deferred.call_deferred() diff --git a/src/world/gunk_body/gunk_body.tscn b/src/world/gunk_body/gunk_body.tscn index 91bcaeb..95a1920 100644 --- a/src/world/gunk_body/gunk_body.tscn +++ b/src/world/gunk_body/gunk_body.tscn @@ -56,4 +56,6 @@ grow_vertical = 2 mouse_filter = 2 script = ExtResource("3_m8wx4") -[connection signal="painted" from="MaskViewport/MaskControl" to="." method="_on_mask_painted"] +[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"]