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(),
|
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 y in 0..=max_y {
|
||||||
for x in 0..width {
|
for x in 0..width {
|
||||||
initial.set_cell(x, y, Element::Water);
|
initial.set_cell(x, y, Element::Water);
|
||||||
|
@ -121,29 +121,17 @@ impl Chunk {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn place_sand_system(mut chunk: Query<&mut Chunk>) {
|
pub fn place_sand_system(mut query: Query<&mut Chunk>) {
|
||||||
// We know for now there's only one chunk
|
for mut chunk in &mut query {
|
||||||
let chunk = chunk.get_single_mut();
|
|
||||||
if chunk.is_err() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut chunk = chunk.unwrap();
|
|
||||||
let frac = chunk.width / 2;
|
let frac = chunk.width / 2;
|
||||||
let x = (chunk.width - frac) / 2 + rand::thread_rng().gen_range(0..frac);
|
let x = (chunk.width - frac) / 2 + rand::thread_rng().gen_range(0..frac);
|
||||||
let y = chunk.height - 1;
|
let y = chunk.height - 1;
|
||||||
chunk.set_cell(x, y, Element::Sand);
|
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
|
// Determine which Margolus neighbourhood offset we're using this update
|
||||||
let offset = if chunk.step == 0 {
|
let offset = if chunk.step == 0 {
|
||||||
(0, 0)
|
(0, 0)
|
||||||
|
@ -193,18 +181,13 @@ pub fn simulate_chunk_system(rules: Res<FallingSandRules>, mut chunk: Query<&mut
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn update_chunk_texture_system(
|
pub fn update_chunk_texture_system(
|
||||||
mut images: ResMut<Assets<Image>>,
|
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
|
for (mut chunk, image_handle) in &mut query {
|
||||||
let chunk = chunk.get_single_mut();
|
|
||||||
if chunk.is_err() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let (mut chunk, image_handle) = chunk.unwrap();
|
|
||||||
if !chunk.dirty_rect.is_dirty() {
|
if !chunk.dirty_rect.is_dirty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -233,6 +216,7 @@ pub fn update_chunk_texture_system(
|
||||||
|
|
||||||
chunk.dirty_rect.reset();
|
chunk.dirty_rect.reset();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub enum Element {
|
pub enum Element {
|
||||||
|
|
Loading…
Reference in New Issue