-
-
Notifications
You must be signed in to change notification settings - Fork 45
Add NetworkArea nodes as physics extras #451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kumpmati
wants to merge
12
commits into
foxssake:main
Choose a base branch
from
kumpmati:network-area-node
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+226
−0
Open
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
83db798
add NetworkArea nodes as physics extras
kumpmati 77c14f5
add missing uids
kumpmati a2a976d
remove unnecessary hash check
kumpmati 63cda35
Merge branch 'main' into network-area-node
kumpmati 6dfd723
implement Area2/3D functions
kumpmati cd1982d
add gddoc references to function comments, adjust wording
kumpmati a000423
fix wrong initial area entered emit
kumpmati 428caf9
add _notification comment
kumpmati 6ff73e8
Merge branch 'main' into network-area-node
kumpmati 6419bdd
Merge branch 'foxssake:main' into network-area-node
kumpmati 8821797
Merge branch 'foxssake:main' into network-area-node
kumpmati 6c34dd0
fix: update network area state during _after_prepare_tick, fix cast e…
kumpmati File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| class_name NetworkArea2D | ||
| extends Area2D | ||
|
|
||
| ## Emitted when a body enters this area. | ||
| signal rollback_body_entered(body: Node2D, tick: int) | ||
| ## Emitted when a body exits this area. | ||
| signal rollback_body_exited(body: Node2D, tick: int) | ||
|
|
||
| ## Emitted when the received area enters this area. Requires monitoring to be set to true. | ||
| signal rollback_area_entered(area: Area2D, tick: int) | ||
| ## Emitted when the received area exits this area. Requires monitoring to be set to true. | ||
| signal rollback_area_exited(area: Area2D, tick: int) | ||
|
|
||
| var _overlapping_bodies := _HistoryBuffer.new() | ||
| var _overlapping_areas := _HistoryBuffer.new() | ||
|
|
||
| func _notification(what: int): | ||
| if what == NOTIFICATION_READY: | ||
| NetworkTime.on_tick.connect(_tick) | ||
|
|
||
| func _tick(_d: float, tick: int): | ||
| _update_bodies(tick) | ||
| _update_areas(tick) | ||
|
|
||
| func _update_bodies(tick: int): | ||
| var current := self.get_overlapping_bodies() | ||
| _overlapping_bodies.set_snapshot(tick, current) | ||
|
|
||
| if not _overlapping_bodies.has(tick - 1): | ||
| for body in current: | ||
| rollback_body_entered.emit(body, tick) | ||
| return | ||
|
|
||
| var prev: Array = _overlapping_bodies.get_snapshot(tick - 1) | ||
|
|
||
| if current.hash() != prev.hash(): | ||
| for body in current: | ||
| if not prev.has(body): | ||
| rollback_body_entered.emit(body, tick) | ||
|
|
||
| for body in prev: | ||
| if not current.has(body): | ||
| rollback_body_exited.emit(body, tick) | ||
|
|
||
| _overlapping_bodies.trim(NetworkRollback.history_start) | ||
|
|
||
|
|
||
| func _update_areas(tick: int): | ||
| var current := self.get_overlapping_areas() | ||
| _overlapping_areas.set_snapshot(tick, current) | ||
|
|
||
| if not _overlapping_areas.has(tick - 1): | ||
| for body in current: | ||
| rollback_body_entered.emit(body, tick) | ||
| return | ||
|
|
||
| var prev: Array = _overlapping_areas.get_snapshot(tick - 1) | ||
|
|
||
| if current.hash() != prev.hash(): | ||
| for body in current: | ||
| if not prev.has(body): | ||
| rollback_area_entered.emit(body, tick) | ||
|
|
||
| for body in prev: | ||
| if not current.has(body): | ||
| rollback_area_exited.emit(body, tick) | ||
|
|
||
| _overlapping_areas.trim(NetworkRollback.history_start) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| uid://hdeqysxd3lql |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| class_name NetworkArea3D | ||
| extends Area3D | ||
|
|
||
| ## Emitted when a body enters this area. | ||
| signal rollback_body_entered(body: Node3D, tick: int) | ||
| ## Emitted when a body exits this area. | ||
| signal rollback_body_exited(body: Node3D, tick: int) | ||
|
|
||
| ## Emitted when the received area enters this area. Requires monitoring to be set to true. | ||
| signal rollback_area_entered(area: Area3D, tick: int) | ||
| ## Emitted when the received area exits this area. Requires monitoring to be set to true. | ||
| signal rollback_area_exited(area: Area3D, tick: int) | ||
|
|
||
| var _overlapping_bodies := _HistoryBuffer.new() | ||
| var _overlapping_areas := _HistoryBuffer.new() | ||
|
|
||
| func _notification(what: int): | ||
| if what == NOTIFICATION_READY: | ||
| NetworkTime.on_tick.connect(_tick) | ||
|
|
||
| func _tick(_d: float, tick: int): | ||
| _update_bodies(tick) | ||
| _update_areas(tick) | ||
|
|
||
| func _update_bodies(tick: int): | ||
| var current := self.get_overlapping_bodies() | ||
| _overlapping_bodies.set_snapshot(tick, current) | ||
|
|
||
| if not _overlapping_bodies.has(tick - 1): | ||
| for body in current: | ||
| rollback_body_entered.emit(body, tick) | ||
| return | ||
|
|
||
| var prev: Array = _overlapping_bodies.get_snapshot(tick - 1) | ||
|
|
||
| if current.hash() != prev.hash(): | ||
kumpmati marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| for body in current: | ||
| if not prev.has(body): | ||
| rollback_body_entered.emit(body, tick) | ||
|
|
||
| for body in prev: | ||
| if not current.has(body): | ||
| rollback_body_exited.emit(body, tick) | ||
|
|
||
| _overlapping_bodies.trim(NetworkRollback.history_start) | ||
|
|
||
|
|
||
| func _update_areas(tick: int): | ||
| var current := self.get_overlapping_areas() | ||
| _overlapping_areas.set_snapshot(tick, current) | ||
|
|
||
| if not _overlapping_areas.has(tick - 1): | ||
| for body in current: | ||
| rollback_body_entered.emit(body, tick) | ||
| return | ||
|
|
||
| var prev: Array = _overlapping_areas.get_snapshot(tick - 1) | ||
|
|
||
| if current.hash() != prev.hash(): | ||
| for body in current: | ||
| if not prev.has(body): | ||
| rollback_area_entered.emit(body, tick) | ||
|
|
||
| for body in prev: | ||
| if not current.has(body): | ||
| rollback_area_exited.emit(body, tick) | ||
|
|
||
| _overlapping_areas.trim(NetworkRollback.history_start) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| uid://bgui8a67mb51l |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This runs in the tick loop, yet the signals emitted are labeled as rollback. Could you please clarify?