summaryrefslogtreecommitdiff
path: root/src/sim
diff options
context:
space:
mode:
Diffstat (limited to 'src/sim')
-rw-r--r--src/sim/cell/materials/fire.rs9
-rw-r--r--src/sim/cell/materials/mod.rs8
-rw-r--r--src/sim/cell_sim/sim.rs8
-rw-r--r--src/sim/particle_sim/mod.rs11
4 files changed, 21 insertions, 15 deletions
diff --git a/src/sim/cell/materials/fire.rs b/src/sim/cell/materials/fire.rs
index dd1ff8c..f582a0c 100644
--- a/src/sim/cell/materials/fire.rs
+++ b/src/sim/cell/materials/fire.rs
@@ -5,7 +5,7 @@ use crate::sim::{
cell_sim::sim::UpdateCtx,
};
-trait FireCellView {
+pub trait FireCellView {
fn get_ticks_lived(self) -> u16;
fn set_ticks_lived(&mut self, ticks: u16) -> ();
fn is_flammable(self) -> bool;
@@ -31,12 +31,13 @@ pub fn sim_update(ctx: &mut UpdateCtx) {
let ticks_lived = ctx.cell.get_ticks_lived();
// 2 seconds
if ticks_lived > 240 {
- // we have a chance to live longer--roughly 50% chance of living an extra second
- if ctx.rng.random_range(0.0..1.0) > 0.995 {
+ // we have a chance to live longer--roughly ?% chance of living an extra second
+ if ctx.rng.random_range(0.0..1.0) > 0.9 {
// kill ourselves, with a chance to turn into ash
+ ctx.do_rewrite = false;
if ctx.rng.random_range(0.0..1.0) > 0.8 {
// TODO ash material
- ctx.set_cell(0, 0, Cell::from_material(MaterialId::Sand));
+ // ctx.set_cell(0, 0, Cell::from_material(MaterialId::Sand));
} else {
ctx.set_cell(0, 0, Cell::void());
}
diff --git a/src/sim/cell/materials/mod.rs b/src/sim/cell/materials/mod.rs
index 9bcf5e4..e2b5fc6 100644
--- a/src/sim/cell/materials/mod.rs
+++ b/src/sim/cell/materials/mod.rs
@@ -1,9 +1,9 @@
use crate::sim::cell_sim::sim::UpdateCtx;
-mod fire;
-mod gas;
-mod liquid;
-mod powder;
+pub mod fire;
+pub mod gas;
+pub mod liquid;
+pub mod powder;
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
diff --git a/src/sim/cell_sim/sim.rs b/src/sim/cell_sim/sim.rs
index 9b07b98..3fc3a0f 100644
--- a/src/sim/cell_sim/sim.rs
+++ b/src/sim/cell_sim/sim.rs
@@ -171,7 +171,7 @@ pub struct UpdateCtx<'a, 'b, 'c> {
pub material: &'c MaterialDef,
pub rng: &'c mut dyn Rng,
- swapped: bool,
+ pub do_rewrite: bool,
}
impl UpdateCtx<'_, '_, '_> {
@@ -202,7 +202,7 @@ impl UpdateCtx<'_, '_, '_> {
self.cell.match_parity(self.seqno + 1);
self.set_cell(0, 0, candidate_cell);
self.set_cell(dx, dy, *self.cell);
- self.swapped = true;
+ self.do_rewrite = false;
return true;
}
}
@@ -245,12 +245,12 @@ pub fn sim_tick_chunk(chunks: &mut [Option<&mut Chunk>; 9], seqno: u64) {
// TODO this is platform-dependent, will break for multiplayer
rng: &mut rng,
- swapped: false,
+ do_rewrite: true,
};
update(&mut update_ctx);
- if !update_ctx.swapped {
+ if update_ctx.do_rewrite {
// the cell didn't move, so it's more settled, and we also need to update its state for parity
cell.increment_settled();
set_cell(chunks, x, y, cell);
diff --git a/src/sim/particle_sim/mod.rs b/src/sim/particle_sim/mod.rs
index 8bad61d..08febfb 100644
--- a/src/sim/particle_sim/mod.rs
+++ b/src/sim/particle_sim/mod.rs
@@ -3,7 +3,10 @@ use glam::{IVec2, Vec2};
use crate::{
config::PIXELS_TO_METRES,
sim::{
- cell::{cell::Cell, materials::MaterialId},
+ cell::{
+ cell::Cell,
+ materials::{MaterialForm, MaterialId},
+ },
cell_sim::world::World,
particle_sim::particle::Particle,
},
@@ -56,7 +59,8 @@ impl ParticleManager {
let mut prev = cur;
if let Some(cell) = world.get_cell_from_game_position(prev.x, prev.y)
- && cell.material != MaterialId::Void
+ && [MaterialForm::Solid, MaterialForm::Powder]
+ .contains(&cell.material.def().form)
{
// already occupied, die
self.particles.swap_remove(i);
@@ -71,7 +75,8 @@ impl ParticleManager {
t_max.y += delta.y;
}
if let Some(cell) = world.get_cell_from_game_position(cur.x, cur.y)
- && cell.material != MaterialId::Void
+ && [MaterialForm::Solid, MaterialForm::Powder]
+ .contains(&cell.material.def().form)
{
// write ourselves to the board
world.set_cell_from_game_position(