mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Implemented setting blocks with the wiring system
This commit is contained in:
parent
eb08b6a153
commit
9864344cfe
@ -1944,6 +1944,7 @@ fn handle_spawn_wiring(
|
||||
inputs: HashMap::new(),
|
||||
outputs: outputs1,
|
||||
})
|
||||
.with(comp::Density(100_f32))
|
||||
.with(comp::Sticky);
|
||||
let ent1 = builder1.build();
|
||||
|
||||
@ -1965,6 +1966,16 @@ fn handle_spawn_wiring(
|
||||
},
|
||||
}],
|
||||
},
|
||||
WiringAction {
|
||||
formula: wiring::OutputFormula::Input {
|
||||
name: String::from("deaths_accumulated"),
|
||||
},
|
||||
threshold: 1.0,
|
||||
effects: vec![WiringActionEffect::SetBlock {
|
||||
coords: vek::Vec3::new(0, 0, pos.0.z as i32),
|
||||
block: Block::new(BlockKind::Water, vek::Rgb::new(0, 0, 0)),
|
||||
}],
|
||||
},
|
||||
WiringAction {
|
||||
formula: wiring::OutputFormula::Constant { value: 1.0 },
|
||||
threshold: 1.0,
|
||||
@ -1983,7 +1994,8 @@ fn handle_spawn_wiring(
|
||||
],
|
||||
inputs: HashMap::new(),
|
||||
outputs: HashMap::new(),
|
||||
});
|
||||
})
|
||||
.with(comp::Density(100_f32));
|
||||
let ent2 = builder2.build();
|
||||
|
||||
pos.0.x += 3.0;
|
||||
@ -1994,6 +2006,7 @@ fn handle_spawn_wiring(
|
||||
inputs: HashMap::new(),
|
||||
outputs: HashMap::new(),
|
||||
})
|
||||
.with(comp::Density(comp::object::Body::TrainingDummy.density().0))
|
||||
.with(Circuit {
|
||||
wires: vec![
|
||||
Wire {
|
||||
|
@ -5,9 +5,10 @@ use common::{
|
||||
resources::EntitiesDiedLastTick,
|
||||
};
|
||||
use common_ecs::{Job, Origin, Phase, System};
|
||||
use common_state::BlockChange;
|
||||
use hashbrown::HashMap;
|
||||
use specs::{
|
||||
join::Join, shred::ResourceId, Entities, Entity, Read, ReadStorage, SystemData, World,
|
||||
join::Join, shred::ResourceId, Entities, Entity, Read, ReadStorage, SystemData, World, Write,
|
||||
WriteStorage,
|
||||
};
|
||||
mod compute_outputs;
|
||||
@ -28,6 +29,7 @@ pub struct WiringData<'a> {
|
||||
|
||||
pub event_bus: Read<'a, EventBus<ServerEvent>>,
|
||||
pub entities_died_last_tick: Read<'a, EntitiesDiedLastTick>,
|
||||
pub block_change: Write<'a, BlockChange>,
|
||||
}
|
||||
|
||||
/// This system is responsible for handling wiring (signals and wiring systems)
|
||||
|
@ -6,11 +6,13 @@ use common::{
|
||||
comp::{object, Body, LightEmitter, PhysicsState, Pos, ProjectileConstructor},
|
||||
event::{Emitter, ServerEvent},
|
||||
resources::EntitiesDiedLastTick,
|
||||
terrain::{block::Block, TerrainChunkSize},
|
||||
util::Dir,
|
||||
vol::RectVolSize,
|
||||
};
|
||||
use common_state::BlockChange;
|
||||
use hashbrown::HashMap;
|
||||
use specs::{join::Join, Entity, Read};
|
||||
use tracing::warn;
|
||||
use specs::{join::Join, Entity, Read, Write};
|
||||
use vek::Rgb;
|
||||
|
||||
pub fn dispatch_actions(system_data: &mut WiringData) {
|
||||
@ -21,6 +23,7 @@ pub fn dispatch_actions(system_data: &mut WiringData) {
|
||||
physics_states,
|
||||
light_emitters,
|
||||
entities_died_last_tick,
|
||||
block_change,
|
||||
pos,
|
||||
..
|
||||
} = system_data;
|
||||
@ -57,6 +60,7 @@ pub fn dispatch_actions(system_data: &mut WiringData) {
|
||||
&mut light_emitter,
|
||||
physics_state,
|
||||
entities_died_last_tick,
|
||||
block_change,
|
||||
pos,
|
||||
);
|
||||
})
|
||||
@ -75,13 +79,14 @@ fn dispatch_action(
|
||||
light_emitter: &mut Option<impl DerefMut<Target = LightEmitter>>,
|
||||
physics_state: Option<&PhysicsState>,
|
||||
entities_died_last_tick: &Read<EntitiesDiedLastTick>,
|
||||
block_change: &mut Write<BlockChange>,
|
||||
pos: Option<&Pos>,
|
||||
) {
|
||||
action_effects
|
||||
.iter()
|
||||
.for_each(|action_effect| match action_effect {
|
||||
WiringActionEffect::SetBlockCollidability { .. } => {
|
||||
warn!("Not implemented WiringActionEffect::SetBlockCollidability")
|
||||
WiringActionEffect::SetBlock { coords, block } => {
|
||||
dispatch_action_set_block(*coords, *block, block_change, pos);
|
||||
},
|
||||
WiringActionEffect::SpawnProjectile { constr } => {
|
||||
dispatch_action_spawn_projectile(entity, constr, server_emitter)
|
||||
@ -140,3 +145,28 @@ fn dispatch_action_set_light(
|
||||
light_emitter.col = Rgb::new(computed_r, computed_g, computed_b);
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn dispatch_action_set_block(
|
||||
coord: vek::Vec3<i32>,
|
||||
block: Block,
|
||||
block_change: &mut Write<BlockChange>,
|
||||
pos: Option<&Pos>,
|
||||
) {
|
||||
let chunk_origin = match pos {
|
||||
Some(opos) => vek::Vec3::new(
|
||||
(opos.0.x as i32 / TerrainChunkSize::RECT_SIZE.x as i32)
|
||||
* TerrainChunkSize::RECT_SIZE.x as i32,
|
||||
(opos.0.y as i32 / TerrainChunkSize::RECT_SIZE.y as i32)
|
||||
* TerrainChunkSize::RECT_SIZE.y as i32,
|
||||
0,
|
||||
),
|
||||
None => vek::Vec3::new(0, 0, 0),
|
||||
};
|
||||
let offset_pos = chunk_origin
|
||||
.iter()
|
||||
.zip(coord.iter())
|
||||
.map(|(p, c)| p + c)
|
||||
.collect();
|
||||
block_change.set(offset_pos, block);
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
use common::comp::ProjectileConstructor;
|
||||
use core::f32;
|
||||
use common::{comp::ProjectileConstructor, terrain::Block};
|
||||
use hashbrown::HashMap;
|
||||
use specs::{Component, Entity};
|
||||
use specs_idvs::IdvStorage;
|
||||
@ -50,9 +49,9 @@ pub enum WiringActionEffect {
|
||||
SpawnProjectile {
|
||||
constr: ProjectileConstructor,
|
||||
},
|
||||
SetBlockCollidability {
|
||||
SetBlock {
|
||||
coords: Vec3<i32>,
|
||||
collidable: bool,
|
||||
block: Block,
|
||||
},
|
||||
SetLight {
|
||||
r: OutputFormula,
|
||||
|
Loading…
Reference in New Issue
Block a user