-
Notifications
You must be signed in to change notification settings - Fork 0
Less blocking terrain mesh generation #59
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
Conversation
@@ -87,7 +87,7 @@ pub mod client_block { | |||
use client_block::block_properties; | |||
use TextureName::*; | |||
|
|||
#[derive(Resource)] | |||
#[derive(Resource, Clone)] |
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.
No idea how to circumvent this.
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.
The clone shouldn't be too expensive though, as we are only cloning a hashmap with a few primitives.
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.
The atlas currently consists of 16 slots, so there are not many UVs and enum values that will be cloned.
)); | ||
}); | ||
|
||
let mut index = 0; |
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.
Ugly index, can't use enumerate() in this context.
@@ -9,6 +11,24 @@ impl SpawnAreaLoaded { | |||
} | |||
} | |||
|
|||
#[derive(Clone, PartialEq)] | |||
pub enum MeshType { |
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.
Reminder:
A logical Chunk of terrain has two geometrical representations:
A solid one, for the cubes like stone and dirt and a transparent one for the grass at the moment, perhaps glass and other stuff in the future.
src/client/terrain/systems.rs
Outdated
} | ||
let mesh_option = task_result.unwrap(); | ||
if mesh_option.is_none() { | ||
return; |
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.
Info: If chunk is empty, a None
Mesh will be created.
In that case the world should not be updated.
Mesher that does not increase frame times that much
As a follow up on a recent lecture @ ZHAW about concurrency and parallelism, I decided to optimize the mesher systems with an async task pool.
This is an attempt at improving terrain loading performance on the client by using background computations and polling task state.
This opens up the world of possibilities, as the terrain could now be infinite as generating chunk meshes on the fly won't be as blocking as before. Also the load times are significantly reduces as the meshing happens in the background.
Similar to what has been done here:
https://github.com/CuddlyBunion341/beertalk-workers/blob/main/slides.md
Note
This is my first time writing asynchronous Rust code, please be gentle ^^
Everything except for ea89014 is human written.
Before
Untitled.mp4
After
CleanShot.2025-03-16.at.22.36.55.mp4
Todo
Sources
Heavily inspired by: https://bevy-cheatbook.github.io/fundamentals/async-compute.html