Loading chunks in radius instead of by travel direction, bugged (not reloading chunks)

This commit is contained in:
Piotrek
2021-05-19 16:07:27 +02:00
parent e9632a20d2
commit a5d109fb0a
5 changed files with 91 additions and 40 deletions
+15 -1
View File
@@ -51,12 +51,26 @@ impl World {
*/
pub fn load_chunk(&mut self, pos: Vector3<i32>) {
if let Some(chunk) = self.chunks.get_mut(&pos) {
chunk.dirty = true;
if !chunk.loaded {
println!("Chunk {:?} exists but not loaded! Loading now", pos);
chunk.dirty = true;
}
} else {
self.loader.load(pos);
}
}
/*
*
*/
pub fn unload_chunk(&mut self, pos: Vector3<i32>) {
if let Some(chunk) = self.chunks.get_mut(&pos) {
chunk.loaded = false;
chunk.dirty = false;
// TODO: Mark chunk as "to be unloaded" and send it to renderer for freeing resources
}
}
/*
* Loads metadata
*/