forked from feather-rs/feather
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflat.rs
More file actions
54 lines (47 loc) · 1.35 KB
/
flat.rs
File metadata and controls
54 lines (47 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use base::{BlockId, Chunk, ChunkPosition, CHUNK_WIDTH};
use super::{ChunkLoadResult, LoadedChunk, WorldSource};
/// A world source used for debugging that emits
/// only flat chunks and does no IO.
pub struct FlatWorldSource {
archetype: Chunk,
loaded: Vec<LoadedChunk>,
}
impl Default for FlatWorldSource {
fn default() -> Self {
Self::new()
}
}
impl FlatWorldSource {
pub fn new() -> Self {
let mut archetype = Chunk::new(ChunkPosition::new(0, 0));
for y in 0..64 {
for z in 0..CHUNK_WIDTH {
for x in 0..CHUNK_WIDTH {
let block = if y == 63 {
BlockId::grass_block()
} else {
BlockId::stone()
};
archetype.set_block_at(x, y, z, block);
}
}
}
Self {
archetype,
loaded: Vec::new(),
}
}
}
impl WorldSource for FlatWorldSource {
fn queue_load(&mut self, pos: base::ChunkPosition) {
let mut chunk = self.archetype.clone();
chunk.set_position(pos);
self.loaded.push(LoadedChunk {
pos,
result: ChunkLoadResult::Loaded { chunk },
});
}
fn poll_loaded_chunk(&mut self) -> Option<super::LoadedChunk> {
self.loaded.pop()
}
}