Skip to content
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

Redesign layers and valence_server schedule. #533

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft

Conversation

rj00a
Copy link
Member

@rj00a rj00a commented Sep 20, 2023

Objective

Fixes #443

The current design of valence_server has some problems:

  1. "chunk layers" and "entity layers" are separate types sharing some functionality via a trait. We can't do "trait queries" within the context of the ECS, so it's not really possible to write abstractions that target both in a generic way. Also, making users care about both "visible chunk layer" and "visible entity layers" separately is cumbersome.
  2. The current approach to broadcasting packets from layers has some fundamental limitations. Because of the way that messages are organized into buckets according to chunk position, the order between messages is lost. I believe this makes it impossible to implement the clientbound explosion packet correctly in the presence of the other block packets, since the destroyed blocks can span across chunk boundaries.
  3. Iterating over every client in parallel to broadcast packets is too limiting. If we want to emit events for example, then we must introduce locking or overcomplicate the system. This is a blocker for Add events for when an entity has been loaded or unloaded by a client. #442.
  4. The schedule graph for systems is just too complicated. It's not at all clear where new systems are supposed to go and it's very easy to make a mistake when adding new systems.

The goal is to fix all of these problems.

Solution

  • Chunk layers have been renamed to dimension layers to more accurately reflect their purpose.
  • Dimension layers and entity layers have been split into additional components, which are partially shared. The shared components effectively act as a "base class" in the OOP sense. Dimension layers and entity layers are now completely decoupled from each other.
    • Because multiple components are needed to perform most operations on dimension layers, they have been grouped into a custom WorldQuery.
  • VisibleChunkLayer and VisibleEntityLayers components have been combined into a single VisibleLayers component.
  • Renamed EntityLayerId -> LayerId.
  • Renamed UnloadedChunk -> Chunk.
  • Chunk mutations are no longer buffered within loaded chunks, and are instead added to a Batch and applied by the user when specified. This greatly improves modularity by separating concerns and should be more robust to additional features like the clientbound explosion packet. This also means we no longer have to poll chunks for changes every tick.
  • Rather than iterating over clients in parallel to broadcast packets, we instead do the more obvious approach and iterate over the messages. Unfortunately we lose the ability to trivially parallelize this, but I consider this a necessary concession. I'm sure there are tricks we can use to make this faster, but perf has not been tested yet.
  • The schedule graph has been redesigned from the ground up to be simpler, thanks in part to the above changes. Every plugin/module has been organized into system sets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

More generic layers
1 participant