-
Notifications
You must be signed in to change notification settings - Fork 147
Closed
Labels
Milestone
Description
Currently, entity movements, actions, and such are broadcasted to all online players, regardless of distance. Ideally, players would only be notified of entities within their view distance, and entities leaving that radius should be destroyed on the client.
Much of the functionality to do this is already implemented. In particular:
- The chunks a player keeps loaded (and thus those within their view distance) are already stored in the
ChunkHolderstype. Given the position of the chunk an entity is in, we can easily find which players can see the chunk using this type. As a result, it is easy to determine which players to send entity actions to. - The entities for each chunk are stored in
ChunkEntities, so when a player joins, we can loop over the chunks within the view distance and only send them the entities in those chunks.
This implementation consists of a few steps:
- Implement a convenient way to broadcast packets to players who can see a given chunk. This would probably take the form of e.g.
fn broadcast_packet<P: Packet>(chunk: ChunkPosition, chunk_holders: &ChunkHolders, entities: &Entities, packet: P, neq: Option<Entity>), similar to the structure ofsend_packet_to_all_players().- It might be slightly annoying to have to pass all those parameters to the function. For cleanliness, it's possible to investigate moving
ChunkHoldersintoUtiland having the function be a member function ofUtil.
- It might be slightly annoying to have to pass all those parameters to the function. For cleanliness, it's possible to investigate moving
- Detect when a player leaves a chunk and destroy entities client-side in chunks which are no longer within the view distance.
- Only send the inventories, positions, etc. of entities within the view distance when a player joins.
Reactions are currently unavailable