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
64 lines (55 loc) · 1.55 KB
/
Copy pathflat.rs
File metadata and controls
64 lines (55 loc) · 1.55 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
55
56
57
58
59
60
61
62
63
64
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 archetype = Self::generate();
Self {
archetype,
loaded: Vec::new(),
}
}
fn generate() -> Chunk {
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 {
archetype.set_block_at(x, y, z, Self::select_block(y));
}
}
}
archetype
}
fn select_block(height: usize) -> BlockId {
match height {
0 => BlockId::bedrock(),
1..=57 => BlockId::stone(),
58..=62 => BlockId::dirt(),
63 => BlockId::grass_block(),
_ => BlockId::air(),
}
}
}
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()
}
}