-
-
Notifications
You must be signed in to change notification settings - Fork 145
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
Visibility Layers #424
Merged
Visibility Layers #424
Conversation
This file contains 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
5 tasks
Alright, this should be ready to go. @dyc3 If you'd like to merge the ctf example we can do that now. |
Hmm mysterious CI failures. |
dyc3
requested changes
Aug 1, 2023
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.
Looks good.
The CI failures might be related to |
This was referenced Aug 2, 2023
dyc3
approved these changes
Aug 2, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Objective
The objective of this PR is to solve the following problems with a holistic redesign of instances.
Closes #342, #362, but deviates greatly from the solution described in the issue.
If an entity is within the view distance of a client, packets for that entity are sent to the client unconditionally. However, there is often a need to limit the visibility of entities to certain clients depending on the situation. Some examples:
It is possible to work around the problem by using invisibility effects or sending packets manually. But these are hacky solutions that are incomplete, inefficient, and inconvenient.
Updating clients involves looking up every chunk in the client's view distance every tick for every client. This wastes CPU time and doesn't scale well with larger view distances1.
Sometimes we want to broadcast packets to all clients matching some condition. Conditions could include...
It isn't really possible to add all of these conditions in an efficient way using the current design.
Solution
Split the existing
Instance
component into two new components:ChunkLayer
andEntityLayer
. Chunk layers contain all of the chunks in a world along with some global configuration, like the world's dimension. Entity layers contain Minecraft entities. ALayerBundle
containing both is provided for convenience. BothChunkLayer
andEntityLayer
implement the commonLayer
trait.The key idea is this: Clients can only view one chunk layer2, but can view any number of entity layers. These are the
VisibleChunkLayer
andVisibleEntityLayers
components respectively. The client will receive entity packets from only the layers it can see. Clients can add and remove entity layers at any time to spawn and despawn the entities in the layer.Every layer contains a "message buffer" for broadcasting information to all viewers. Every message contains a "key" and a payload of bytes (its meaning depends on the message). Clients walk through the list of messages and use this to update themselves.
There are a few things done to make this faster:
TODOs
valence_anvil
.weather
module.valence_world_border
.Footnotes
At least the work is completely parallelized ¯\_(ツ)_/¯. ↩
Viewing multiple chunk layers has some technical problems and I don't see it as a design worth pursuing. ↩