mirror of
https://github.com/Steffo99/swear-jar.git
synced 2024-11-24 08:34:19 +00:00
Optimize area checks
This commit is contained in:
parent
97bbc8c33c
commit
64f2e5a155
3 changed files with 7 additions and 10 deletions
|
@ -32,3 +32,8 @@ z_index = 10
|
||||||
[node name="OverlapFreer" parent="." instance=ExtResource("6_y1rxa")]
|
[node name="OverlapFreer" parent="." instance=ExtResource("6_y1rxa")]
|
||||||
|
|
||||||
[node name="PlaceableAreaChecker" parent="." instance=ExtResource("7_wemqm")]
|
[node name="PlaceableAreaChecker" parent="." instance=ExtResource("7_wemqm")]
|
||||||
|
|
||||||
|
[connection signal="area_entered" from="." to="PlaceableAreaChecker" method="update_is_overlapping_with"]
|
||||||
|
[connection signal="area_exited" from="." to="PlaceableAreaChecker" method="update_is_overlapping_with"]
|
||||||
|
[connection signal="body_entered" from="." to="OverlapChecker" method="update_is_overlapping_with"]
|
||||||
|
[connection signal="body_exited" from="." to="OverlapChecker" method="update_is_overlapping_with"]
|
||||||
|
|
|
@ -31,7 +31,7 @@ func get_first_overlapping_body() -> Node2D:
|
||||||
return null
|
return null
|
||||||
|
|
||||||
## Update the [is_overlapping_with] variable.
|
## Update the [is_overlapping_with] variable.
|
||||||
func _update_is_overlapping_with() -> void:
|
func update_is_overlapping_with() -> void:
|
||||||
var current_overlap = get_first_overlapping_body()
|
var current_overlap = get_first_overlapping_body()
|
||||||
if current_overlap != is_overlapping_with:
|
if current_overlap != is_overlapping_with:
|
||||||
overlap_changing.emit(current_overlap)
|
overlap_changing.emit(current_overlap)
|
||||||
|
@ -39,7 +39,3 @@ func _update_is_overlapping_with() -> void:
|
||||||
|
|
||||||
## Emitted when the value of [is_overlapping_with] changes because of [_update_is_overlapping_with].
|
## Emitted when the value of [is_overlapping_with] changes because of [_update_is_overlapping_with].
|
||||||
signal overlap_changing(to: Node2D)
|
signal overlap_changing(to: Node2D)
|
||||||
|
|
||||||
## Calculate overlap on every physics frame.
|
|
||||||
func _physics_process(_delta):
|
|
||||||
_update_is_overlapping_with()
|
|
||||||
|
|
|
@ -20,12 +20,8 @@ func get_first_overlapping_placeable_area() -> PlaceableArea:
|
||||||
## Emitted when the value of [is_overlapping_with] changes because of [_update_is_overlapping_with].
|
## Emitted when the value of [is_overlapping_with] changes because of [_update_is_overlapping_with].
|
||||||
signal overlap_changing(to: PlaceableArea)
|
signal overlap_changing(to: PlaceableArea)
|
||||||
|
|
||||||
func _update_is_overlapping_with() -> void:
|
func update_is_overlapping_with() -> void:
|
||||||
var current_overlap = get_first_overlapping_placeable_area()
|
var current_overlap = get_first_overlapping_placeable_area()
|
||||||
if current_overlap != is_overlapping_with:
|
if current_overlap != is_overlapping_with:
|
||||||
overlap_changing.emit(current_overlap)
|
overlap_changing.emit(current_overlap)
|
||||||
is_overlapping_with = current_overlap
|
is_overlapping_with = current_overlap
|
||||||
|
|
||||||
## Calculate overlap on every physics frame.
|
|
||||||
func _physics_process(_delta):
|
|
||||||
_update_is_overlapping_with()
|
|
||||||
|
|
Loading…
Reference in a new issue