You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the problem related to your feature request.
For some applications written in Valence, it is desirable to load and unload chunks from memory automatically as players explore the environment. This could include:
Chunks from a terrain generation algorithm.
Chunks from/to a file format like Anvil.
However, Valence doesn't make this easy. Loading and unloading must be done manually by the programmer in a tedious and error-prone way.
valence_anvil does the required work of loading and unloading for us, but this functionality is locked behind valence_anvil and must be recreated for any "chunk producer" or "chunk consumer" we might want to make. This hinders interoperability.
What solution would you like?
Create a new crate called valence_chunk_manager (name TBD) which has...
ChunkManagerPlugin
ChunkProducer component for chunk layers containing a boxed trait object named ProduceChunk.
ChunkConsumer component for chunk layers containing a boxed trait object named ConsumeChunk.
EmptyChunkProducer, CompositeChunkProducer, maybe more.
Systems and other public functions needed to make this work.
The ProduceChunk trait looks something like this:
pubtraitProduceChunk{// `height` and `min_y` are from the dimension type. Used as hints. (maybe pass in the whole dimension info?)fnproduce_chunk(&mutself,pos:ChunkPos,height:u32,min_y:i32) -> ProduceChunkResult;// Called once per tick.fnpoll_pending(&mutself,pending:&mutVec<(ChunkPos,Option<UnloadedChunk>)>);}pubenumProduceChunkResult{/// The chunk is available now. Contains the chunk or `None` if there is no chunk at this position.Now(Option<UnloadedChunk>),/// The chunk isn't available this tick, but will be produced later by [`ProduceChunk::poll_pending`].Pending,}
ConsumeChunk looks like
/// Called by the chunk manager when a chunk is removed from the layer, usually because the chunk is out of range of players.pubtraitConsumeChunk{fnconsume_chunk(&mutself,pos:ChunkPos,chunk:UnloadedChunk);}
For convenience, the library should provide trivial implementations of these traits. This is useful for simple "void worlds" and the examples.
Next, we need some way to compose chunk providers together. This enables us to, for example, separate terrain generation from file formats.
We can do this without introducing any new primitives:
/// An implementation of [`ChunkProducer`] which combines the producers `A` and `B` together./// If `A` fails to produce a chunk at some position, then `B` is used to fill the gap.pubstructCompositeChunkProducer<A,B>{puba:A,pubb:B,
...
}impl<A,B>ChunkProducerforCompositeChunkProducer<A,B>whereA:ChunkProducer,B:ChunkProducer{ ... }
Finally, we can use this new approach in the examples.
What alternative(s) have you considered?
Better name for "chunk manager"?
How does this integrate with entities and EntityLayer?
Is there a more "ECS friendly" way to design this API?
Describe the problem related to your feature request.
For some applications written in Valence, it is desirable to load and unload chunks from memory automatically as players explore the environment. This could include:
However, Valence doesn't make this easy. Loading and unloading must be done manually by the programmer in a tedious and error-prone way.
valence_anvil
does the required work of loading and unloading for us, but this functionality is locked behindvalence_anvil
and must be recreated for any "chunk producer" or "chunk consumer" we might want to make. This hinders interoperability.What solution would you like?
valence_chunk_manager
(name TBD) which has...ChunkManagerPlugin
ChunkProducer
component for chunk layers containing a boxed trait object namedProduceChunk
.ChunkConsumer
component for chunk layers containing a boxed trait object namedConsumeChunk
.EmptyChunkProducer
,CompositeChunkProducer
, maybe more.The
ProduceChunk
trait looks something like this:ConsumeChunk
looks likeFor convenience, the library should provide trivial implementations of these traits. This is useful for simple "void worlds" and the examples.
Next, we need some way to compose chunk providers together. This enables us to, for example, separate terrain generation from file formats.
We can do this without introducing any new primitives:
Finally, we can use this new approach in the examples.
What alternative(s) have you considered?
EntityLayer
?Additional context
Possibly relevant for #504
The text was updated successfully, but these errors were encountered: