mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
(Wiring) Parametrize OutputFormulas with OutputFormulas
This commit is contained in:
parent
a2999ce96f
commit
4adb963c8e
@ -4,7 +4,7 @@
|
||||
|
||||
use crate::{
|
||||
settings::{BanRecord, EditableSetting},
|
||||
wiring::{Logic, OutputFormula},
|
||||
wiring::{BoxConst, Const, Input, Logic, OutputFormula},
|
||||
Server, SpawnPoint, StateExt,
|
||||
};
|
||||
use assets::AssetExt;
|
||||
@ -1723,57 +1723,40 @@ fn handle_spawn_wiring(
|
||||
pos.0.x += 3.0;
|
||||
|
||||
let mut outputs1 = HashMap::new();
|
||||
outputs1.insert(
|
||||
"deaths_last_tick".to_string(),
|
||||
wiring::OutputFormula::OnDeath {
|
||||
value: 1.0,
|
||||
radius: 30.0,
|
||||
},
|
||||
);
|
||||
outputs1.insert("deaths_last_tick".to_string(), OutputFormula::OnDeath {
|
||||
value: BoxConst(1.0),
|
||||
radius: BoxConst(30.0),
|
||||
});
|
||||
outputs1.insert(
|
||||
"deaths_accumulated".to_string(),
|
||||
OutputFormula::Logic(Box::new(Logic {
|
||||
kind: wiring::LogicKind::Sum,
|
||||
left: OutputFormula::Logic(Box::new(Logic {
|
||||
kind: wiring::LogicKind::Sub,
|
||||
left: OutputFormula::Input {
|
||||
name: "deaths_accumulated".to_string(),
|
||||
},
|
||||
left: Input("deaths_accumulated"),
|
||||
right: OutputFormula::Logic(Box::new(Logic {
|
||||
kind: wiring::LogicKind::Min,
|
||||
left: OutputFormula::Input {
|
||||
name: "pressed".to_string(),
|
||||
},
|
||||
right: OutputFormula::Input {
|
||||
name: "deaths_accumulated".to_string(),
|
||||
},
|
||||
left: Input("pressed"),
|
||||
right: Input("deaths_accumulated"),
|
||||
})),
|
||||
})),
|
||||
right: OutputFormula::Input {
|
||||
name: "deaths_last_tick".to_string(),
|
||||
},
|
||||
right: Input("deaths_last_tick"),
|
||||
})),
|
||||
);
|
||||
outputs1.insert("pressed".to_string(), OutputFormula::OnCollide {
|
||||
value: f32::MAX,
|
||||
value: Box::new(OutputFormula::Constant { value: f32::MAX }),
|
||||
});
|
||||
|
||||
let builder1 = server
|
||||
.state
|
||||
.create_wiring(pos, comp::object::Body::Coins, WiringElement {
|
||||
actions: vec![WiringAction {
|
||||
formula: wiring::OutputFormula::Constant { value: 1.0 },
|
||||
threshold: 1.0,
|
||||
formula: Const(1.0),
|
||||
threshold: Const(1.0),
|
||||
effects: vec![WiringActionEffect::SetLight {
|
||||
r: wiring::OutputFormula::Input {
|
||||
name: String::from("color"),
|
||||
},
|
||||
g: wiring::OutputFormula::Input {
|
||||
name: String::from("color"),
|
||||
},
|
||||
b: wiring::OutputFormula::Input {
|
||||
name: String::from("color"),
|
||||
},
|
||||
r: Input("color"),
|
||||
g: Input("color"),
|
||||
b: Input("color"),
|
||||
}],
|
||||
}],
|
||||
inputs: HashMap::new(),
|
||||
@ -1788,10 +1771,8 @@ fn handle_spawn_wiring(
|
||||
.create_wiring(pos, comp::object::Body::Coins, WiringElement {
|
||||
actions: vec![
|
||||
WiringAction {
|
||||
formula: wiring::OutputFormula::Input {
|
||||
name: String::from("deaths_accumulated"),
|
||||
},
|
||||
threshold: 5.0,
|
||||
formula: Input("deaths_accumulated"),
|
||||
threshold: Const(5.0),
|
||||
effects: vec![WiringActionEffect::SpawnProjectile {
|
||||
constr: comp::ProjectileConstructor::Arrow {
|
||||
damage: 1.0,
|
||||
@ -1801,18 +1782,12 @@ fn handle_spawn_wiring(
|
||||
}],
|
||||
},
|
||||
WiringAction {
|
||||
formula: wiring::OutputFormula::Constant { value: 1.0 },
|
||||
threshold: 1.0,
|
||||
formula: Const(1.0),
|
||||
threshold: Const(1.0),
|
||||
effects: vec![WiringActionEffect::SetLight {
|
||||
r: wiring::OutputFormula::Input {
|
||||
name: String::from("color"),
|
||||
},
|
||||
g: wiring::OutputFormula::Input {
|
||||
name: String::from("color"),
|
||||
},
|
||||
b: wiring::OutputFormula::Input {
|
||||
name: String::from("color"),
|
||||
},
|
||||
r: Input("color"),
|
||||
g: Input("color"),
|
||||
b: Input("color"),
|
||||
}],
|
||||
},
|
||||
],
|
||||
|
@ -46,7 +46,13 @@ pub fn dispatch_actions(system_data: &mut WiringData) {
|
||||
physics_state,
|
||||
entities_died_last_tick,
|
||||
pos,
|
||||
) >= wiring_action.threshold
|
||||
) >= compute_output(
|
||||
&wiring_action.threshold,
|
||||
&wiring_element.inputs,
|
||||
physics_state,
|
||||
entities_died_last_tick,
|
||||
pos,
|
||||
)
|
||||
})
|
||||
.for_each(|wiring_action| {
|
||||
dispatch_action(
|
||||
|
@ -22,14 +22,28 @@ pub struct Circuit {
|
||||
}
|
||||
|
||||
pub enum OutputFormula {
|
||||
Constant { value: f32 },
|
||||
Input { name: String },
|
||||
Constant {
|
||||
value: f32,
|
||||
},
|
||||
Input {
|
||||
name: String,
|
||||
},
|
||||
Logic(Box<Logic>),
|
||||
|
||||
SineWave { amplitude: f32, frequency: f32 },
|
||||
OnCollide { value: f32 },
|
||||
OnInteract { value: f32 },
|
||||
OnDeath { value: f32, radius: f32 },
|
||||
SineWave {
|
||||
amplitude: Box<OutputFormula>,
|
||||
frequency: Box<OutputFormula>,
|
||||
},
|
||||
OnCollide {
|
||||
value: Box<OutputFormula>,
|
||||
},
|
||||
OnInteract {
|
||||
value: Box<OutputFormula>,
|
||||
},
|
||||
OnDeath {
|
||||
value: Box<OutputFormula>,
|
||||
radius: Box<OutputFormula>,
|
||||
},
|
||||
}
|
||||
|
||||
pub enum LogicKind {
|
||||
@ -42,7 +56,7 @@ pub enum LogicKind {
|
||||
|
||||
pub struct WiringAction {
|
||||
pub formula: OutputFormula,
|
||||
pub threshold: f32,
|
||||
pub threshold: OutputFormula,
|
||||
pub effects: Vec<WiringActionEffect>,
|
||||
}
|
||||
|
||||
@ -75,3 +89,19 @@ impl Component for WiringElement {
|
||||
impl Component for Circuit {
|
||||
type Storage = IdvStorage<Self>;
|
||||
}
|
||||
|
||||
pub fn BoxConst(constant_value: f32) -> Box<OutputFormula> { Box::new(Const(constant_value)) }
|
||||
|
||||
pub fn Const(constant_value: f32) -> OutputFormula {
|
||||
OutputFormula::Constant {
|
||||
value: constant_value,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn BoxInput(name: &str) -> Box<OutputFormula> { Box::new(Input(name)) }
|
||||
|
||||
pub fn Input(name: &str) -> OutputFormula {
|
||||
OutputFormula::Input {
|
||||
name: name.to_string(),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user