Hello! Does anyone have any information on serializing and deserializing chunks in bevy? I have a working method using dynamic scenes, but unfortunately using world for the serialization and deserialization seems to cause way to much overhead, and blocks the main thread, creating a freeze temporarily each time new chunks are loaded. Any advice/places to look would be helpful!
#Chunk Serialization and Deserialization
1 messages · Page 1 of 1 (latest)
You want AsyncComputeTaskPool, I think. Would allow you to process things without blocking main thread
https://github.com/bevyengine/bevy/blob/v0.14.0/examples/async_tasks/async_compute.rs
Yeah, I'm aware of that, but all of the strategies I've attempted doing this were not feasible due to the single thread access of world. If there is a way to do it, I'm all ears!
It's possible I overlooked something
What problems were you having?
An async task has no access to the world, and ideally should prep the minimal necessary work for that period of exclusive-world access if you're doing anything to apply their effects
Well right now I'm using dynamic scenes with world to handle the serialization and deserialization of the scenes, and so I get all the way to the point where I'd like to use async for the serialization and deserialization (since this is happening for each chunk dynamically at runtime when they are loading and unloading,) and that cannot be done within an async block using world.
Is there some other method of serialization and deserialization that doesn't use world with dynamic scenes? When defining the scene builder it requires world, and I can't do the serialization and deserialization beforehand, because that is what I'm trying to prevent from blocking the main thread. It might be that I'm just taking the wrong approach, but I haven't found a better way yet.
I think the main reason this isn't a common issue is because a majority of the time when working with scenes saving and loading only occurs on occasion and the thread blocking is expected, but for dynamic saving and loading of chunks this is less than ideal, since they are constantly being loaded and unloaded at run time, any time the player is moving.
''' rust
fn serialize(&self, world: &World, type_registry: &TypeRegistryArc) -> String {
let scene_builder = DynamicSceneBuilder::from_world(world);
let scene = scene_builder
.deny_all()
.deny_all_resources()
.allow::<Tile>()
.allow::<Chunk>()
.allow::<RenderLayers>()
.allow::<LightOccluder2D>()
.allow::<Transform>()
.allow::<ImageHandlePath>()
.allow::<Sprite>()
.allow::<GlobalTransform>()
.allow::<Visibility>()
.allow::<InheritedVisibility>()
.allow::<ViewVisibility>()
.allow::<Name>()
.extract_entities(self.entities.clone().into_iter())
.build();
let serialized_scene = scene.serialize_ron(type_registry).unwrap();
return serialized_scene;
}
'''
I'm a bit confused by this approach
Have you profiled this to find which part is slow?
Once you have created the DynamicScene from the world, you no longer need the world - that DynamicScene could then be pushed to a task that does the rest of the work
But that wouldn't help if extracting the dynamic scene itself is slow