Support multiple non-interacting chunk entities
This commit is contained in:
parent
c31ddd9bea
commit
b1fd987955
|
@ -82,7 +82,7 @@ impl Chunk {
|
|||
dirty_rect: DirtyRect::default(),
|
||||
};
|
||||
|
||||
let max_y = height / 10;
|
||||
let max_y = height / rand::thread_rng().gen_range(2..10);
|
||||
for y in 0..=max_y {
|
||||
for x in 0..width {
|
||||
initial.set_cell(x, y, Element::Water);
|
||||
|
@ -121,29 +121,17 @@ impl Chunk {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn place_sand_system(mut chunk: Query<&mut Chunk>) {
|
||||
// We know for now there's only one chunk
|
||||
let chunk = chunk.get_single_mut();
|
||||
if chunk.is_err() {
|
||||
return;
|
||||
}
|
||||
|
||||
let mut chunk = chunk.unwrap();
|
||||
pub fn place_sand_system(mut query: Query<&mut Chunk>) {
|
||||
for mut chunk in &mut query {
|
||||
let frac = chunk.width / 2;
|
||||
let x = (chunk.width - frac) / 2 + rand::thread_rng().gen_range(0..frac);
|
||||
let y = chunk.height - 1;
|
||||
chunk.set_cell(x, y, Element::Sand);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn simulate_chunk_system(rules: Res<FallingSandRules>, mut chunk: Query<&mut Chunk>) {
|
||||
// We know for now there's only one chunk
|
||||
let chunk = chunk.get_single_mut();
|
||||
if chunk.is_err() {
|
||||
return;
|
||||
}
|
||||
|
||||
let mut chunk = chunk.unwrap();
|
||||
|
||||
pub fn simulate_chunk_system(rules: Res<FallingSandRules>, mut query: Query<&mut Chunk>) {
|
||||
for mut chunk in &mut query {
|
||||
// Determine which Margolus neighbourhood offset we're using this update
|
||||
let offset = if chunk.step == 0 {
|
||||
(0, 0)
|
||||
|
@ -192,19 +180,14 @@ pub fn simulate_chunk_system(rules: Res<FallingSandRules>, mut chunk: Query<&mut
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_chunk_texture_system(
|
||||
mut images: ResMut<Assets<Image>>,
|
||||
mut chunk: Query<(&mut Chunk, &Handle<Image>)>,
|
||||
mut query: Query<(&mut Chunk, &Handle<Image>)>,
|
||||
) {
|
||||
// We know for now there's only one chunk
|
||||
let chunk = chunk.get_single_mut();
|
||||
if chunk.is_err() {
|
||||
return;
|
||||
}
|
||||
|
||||
let (mut chunk, image_handle) = chunk.unwrap();
|
||||
for (mut chunk, image_handle) in &mut query {
|
||||
if !chunk.dirty_rect.is_dirty() {
|
||||
return;
|
||||
}
|
||||
|
@ -232,6 +215,7 @@ pub fn update_chunk_texture_system(
|
|||
}
|
||||
|
||||
chunk.dirty_rect.reset();
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
|
|
Loading…
Reference in New Issue