feat: gas simulation
parent
4a4d40e0fa
commit
67512ff926
|
|
@ -20,7 +20,7 @@ struct TerrainBrush2D {
|
||||||
|
|
||||||
impl Default for TerrainBrush2D {
|
impl Default for TerrainBrush2D {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
TerrainBrush2D { radius: 7, tile: 3 }
|
TerrainBrush2D { radius: 5, tile: 4 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -35,7 +35,8 @@ fn debug_painter(
|
||||||
mut mouse_wheel: EventReader<MouseWheel>,
|
mut mouse_wheel: EventReader<MouseWheel>,
|
||||||
camera_query: Query<(&Camera, &GlobalTransform), With<GameCamera>>,
|
camera_query: Query<(&Camera, &GlobalTransform), With<GameCamera>>,
|
||||||
) {
|
) {
|
||||||
let allow_painting = key_input.pressed(KeyCode::LControl);
|
// let allow_painting = key_input.pressed(KeyCode::LControl);
|
||||||
|
let allow_painting = true;
|
||||||
|
|
||||||
// Change brush
|
// Change brush
|
||||||
for event in mouse_wheel.iter() {
|
for event in mouse_wheel.iter() {
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ fn terrain_simulation(mut terrain: ResMut<Terrain2D>, frame_counter: Res<FrameCo
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
for chunk_index in indices.iter() {
|
for chunk_index in indices.iter() {
|
||||||
// Mark few chunks dirty in interval. Should help activate stale chunks
|
// Mark few chunks dirty in interval. Should help activate stale chunks
|
||||||
if let Some(chunk) = terrain.index_to_chunk_mut(&chunk_index) {
|
if let Some(chunk) = terrain.index_to_chunk_mut(&chunk_index) {
|
||||||
let interval = 1;
|
let interval = 1;
|
||||||
if frame_counter.frame % interval == 0 {
|
if frame_counter.frame % interval == 0 {
|
||||||
|
|
@ -124,6 +124,7 @@ fn terrain_simulation(mut terrain: ResMut<Terrain2D>, frame_counter: Res<FrameCo
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: generalise "check for empty space and move" behaviour
|
||||||
match tb.form {
|
match tb.form {
|
||||||
TexelForm::Liquid => {
|
TexelForm::Liquid => {
|
||||||
// Check if there is space below
|
// Check if there is space below
|
||||||
|
|
@ -160,6 +161,41 @@ fn terrain_simulation(mut terrain: ResMut<Terrain2D>, frame_counter: Res<FrameCo
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
TexelForm::Gas => {
|
||||||
|
// Check if there is space above
|
||||||
|
{
|
||||||
|
let above_pos = global + Vector2I::UP;
|
||||||
|
if terrain
|
||||||
|
.get_texel(&above_pos)
|
||||||
|
.map_or(true, |texel| TexelBehaviour2D::is_empty(&texel.id))
|
||||||
|
{
|
||||||
|
let above_id =
|
||||||
|
terrain.get_texel(&above_pos).map_or(0, |texel| texel.id);
|
||||||
|
terrain.set_texel(&above_pos, texel.id, Some(simulation_frame));
|
||||||
|
terrain.set_texel(&global, above_id, Some(simulation_frame));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if there is space to the side
|
||||||
|
let mut dirs = vec![Vector2I::RIGHT, Vector2I::LEFT];
|
||||||
|
if ((frame_counter.frame / 73) % 2) as i32 == global.y % 2 {
|
||||||
|
dirs.reverse();
|
||||||
|
}
|
||||||
|
for dir in dirs.iter() {
|
||||||
|
let side_pos = global + *dir;
|
||||||
|
if terrain
|
||||||
|
.get_texel(&side_pos)
|
||||||
|
.map_or(true, |texel| TexelBehaviour2D::is_empty(&texel.id))
|
||||||
|
{
|
||||||
|
let side_id =
|
||||||
|
terrain.get_texel(&side_pos).map_or(0, |texel| texel.id);
|
||||||
|
terrain.set_texel(&side_pos, texel.id, Some(simulation_frame));
|
||||||
|
terrain.set_texel(&global, side_id, Some(simulation_frame));
|
||||||
|
continue 'texel_loop;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue