-
Notifications
You must be signed in to change notification settings - Fork 145
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
Superflat layer generation (#24) #108
Superflat layer generation (#24) #108
Conversation
Thanks for the work on this. For chunk generation, I would recommend a pub trait WorldGenerator: Send + Sync {
/// Generates the chunk at the given position.
fn generate_chunk(&self, position: ChunkPosition) -> Chunk;
} The chunk worker would then have a If you have any questions, feel free to ask. |
Codecov Report
@@ Coverage Diff @@
## develop #108 +/- ##
===========================================
+ Coverage 57.94% 58.13% +0.18%
===========================================
Files 58 59 +1
Lines 7718 7901 +183
===========================================
+ Hits 4472 4593 +121
- Misses 3246 3308 +62
Continue to review full report at Codecov.
|
@caelunshun Thanks, this is a bit ambitious for my Rust experience so I'm sure I'll have a few questions regarding rayon :) |
Got it to work, it generates the new chunks using the layers. Just gotta make it asynchronous and write some unit tests. Also I noticed that the Which makes the |
Yes, I guess To do the generation asynchronously, just use Rayon like a thread pool through fn generate_chunk(chunk_worker: &ChunkWorker, chunk_pos: ChunkPosition) {
let sender = chunk_worker.sender.clone();
let generator = Arc::clone(&chunk_worker.generator);
rayon::spawn(move || {
let chunk = generator.generate_chunk(chunk_pos);
sender.send((chunk_pos, Ok(chunk))).unwrap();
}
} This will cause each chunk to be generated on a thread pool, potentially in parallel. |
Test |
Right, I'll get to implementing that then. |
Sounds good. Also, I'm not super satisfied with the design of my changes in chunkworker, it seems a bit hacky to use Option/None when loading the chunk is delegated to the rayon task. It's also pretty annoying to test. Let me know if you have some ideas. |
Well, you could pass the channel to Anyway, in the Tokio rewrite (#42), the chunk worker will be rewritten to use Tokio tasks for IO and Rayon tasks for generation, which will remove the need to return an |
Alright, I'll leave it as is then. |
@Momothereal I implemented |
|
Ready for merge? |
Ah, hold on, there's still an issue with this. When a region file containing the chunk is missing, the chunk is not generated and instead an error is returned:
Consider generating the chunk if |
Ready to merge, unless there's something I can do about coverage. |
Thanks! |
generatorName
andgeneratorOptions
from levelchunkworker
loading to generate new chunksgeneratorOptions