summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs36
1 files changed, 32 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs
index 976a272..ccc5ec5 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,6 +4,7 @@ mod renderer;
mod sim;
use futures::executor;
+use fxhash::FxHashMap;
use rand::random_range;
use std::{collections::VecDeque, sync::Arc, time::Instant};
use winit::{
@@ -23,8 +24,11 @@ use crate::{
renderer::RendererState,
sim::{
cell::{cell::Cell, materials::MaterialId},
- cell_sim::{sim::sim_tick, world::World},
- rb_sim::{PhysicsManager, RbSimManager},
+ cell_sim::{
+ sim::{sim_tick, write_rb_entity_to_world},
+ world::World,
+ },
+ rb_sim::RbSimManager,
},
};
@@ -34,6 +38,7 @@ pub type Result<T> = std::result::Result<T, Error>;
struct Config {
brush_radius: f32,
brush_material: MaterialId,
+ dropper_material: MaterialId,
use_threading: bool,
}
@@ -102,7 +107,7 @@ impl App {
&& let Some(rbsm) = &mut self.rb_sim_manager
{
self.input.trigger_test_1 = false;
- rbsm.test_spawn_box(lm.0, lm.1);
+ rbsm.test_spawn_box(lm.0, lm.1, self.config.dropper_material);
}
// --TEST DRAWING--
@@ -125,8 +130,8 @@ impl App {
&& r > 0.9
{
let mut cell = Cell::from_material(self.config.brush_material);
+ cell.match_parity(self.sim_seqno);
// ensure we simulate on the first tick
- cell.flags = (self.sim_seqno as u8) & 0b1;
if let Some(world) = &mut self.world {
world.set_cell_from_game_position(
x, y, cell, false, // wake the chunk
@@ -196,6 +201,7 @@ impl Default for App {
use_threading: true,
brush_radius: 10.0,
brush_material: MaterialId::Sand,
+ dropper_material: MaterialId::Sand,
},
diagnostics: Diagnostics {
fps: 0.0,
@@ -263,6 +269,28 @@ impl ApplicationHandler for App {
KeyCode::KeyS => self.input.is_down_pressed = pressed,
KeyCode::KeyD => self.input.is_right_pressed = pressed,
KeyCode::KeyC => self.world = Some(World::from_default_size()),
+ KeyCode::KeyV => {
+ self.rb_sim_manager
+ .as_mut()
+ .map(|rbsm| rbsm.rb_entities = FxHashMap::default());
+ }
+ KeyCode::KeyP if pressed && !repeat => {
+ if let Some(rbsm) = self.rb_sim_manager.as_mut() {
+ for &id in rbsm.rb_entities.keys() {
+ write_rb_entity_to_world(
+ self.world.as_mut().unwrap(),
+ rbsm,
+ id,
+ self.sim_seqno,
+ );
+ }
+
+ let entity_ids: Vec<u32> = rbsm.rb_entities.keys().copied().collect();
+ for entity_id in entity_ids {
+ rbsm.destroy_rb_entity(entity_id);
+ }
+ }
+ }
KeyCode::Space if pressed => self.sim_paused = !self.sim_paused,
KeyCode::KeyX if pressed => self.ignore_pause_next_tick = true,
KeyCode::KeyQ if pressed && !repeat => self.input.trigger_test_1 = true,