parent
858f752842
commit
f56effc197
@ -0,0 +1,73 @@
|
|||||||
|
use std::f32::consts::PI;
|
||||||
|
|
||||||
|
use logicworld_subassembly::{lw, COMPONENT_MAP};
|
||||||
|
use vecmath::{vec3_add, Vector3};
|
||||||
|
|
||||||
|
use crate::cells::builder;
|
||||||
|
use crate::router::{Connection, ConnectionMap, SQUARE};
|
||||||
|
|
||||||
|
pub fn input_port(
|
||||||
|
bits: &Vec<usize>,
|
||||||
|
port_name: &str,
|
||||||
|
parent_address: u32,
|
||||||
|
next_address: &mut u32,
|
||||||
|
next_position: &mut Vector3<lw::Int>,
|
||||||
|
connection_map: &mut ConnectionMap,
|
||||||
|
) -> Vec<lw::Component> {
|
||||||
|
let mut components = vec![];
|
||||||
|
let mut wires = vec![]; // discard
|
||||||
|
builder(
|
||||||
|
bits.len(),
|
||||||
|
parent_address,
|
||||||
|
next_address,
|
||||||
|
next_position,
|
||||||
|
&mut components,
|
||||||
|
&mut wires,
|
||||||
|
connection_map,
|
||||||
|
|i_bit, next_address, parent, next_position_within, components, _wires, connection_map| {
|
||||||
|
let bit_id = bits[i_bit];
|
||||||
|
let label = lw::Component {
|
||||||
|
address: *next_address,
|
||||||
|
parent,
|
||||||
|
numeric_id: COMPONENT_MAP["MHG.PanelLabel"],
|
||||||
|
position: *next_position_within,
|
||||||
|
rotation: quaternion::euler_angles(0.0, -PI / 2.0, 0.0),
|
||||||
|
inputs: vec![],
|
||||||
|
outputs: vec![],
|
||||||
|
custom_data: lw::Label::new(&format!("{}[{}]", port_name, i_bit))
|
||||||
|
.with_size(2.0)
|
||||||
|
.custom_data(),
|
||||||
|
};
|
||||||
|
|
||||||
|
*next_address += 1;
|
||||||
|
|
||||||
|
let peg = lw::Component {
|
||||||
|
address: *next_address,
|
||||||
|
parent,
|
||||||
|
numeric_id: COMPONENT_MAP["MHG.Peg"],
|
||||||
|
position: vec3_add(*next_position_within, [0, 0, SQUARE]),
|
||||||
|
rotation: quaternion::id(),
|
||||||
|
inputs: vec![lw::Input::new(bit_id as lw::Int)],
|
||||||
|
outputs: vec![],
|
||||||
|
custom_data: vec![],
|
||||||
|
};
|
||||||
|
connection_map.insert(
|
||||||
|
Connection {
|
||||||
|
cell_index: bit_id,
|
||||||
|
port_name: "input",
|
||||||
|
bit_index: 0,
|
||||||
|
},
|
||||||
|
lw::PegAddress::input(peg.address, 0),
|
||||||
|
);
|
||||||
|
|
||||||
|
components.push(label);
|
||||||
|
components.push(peg);
|
||||||
|
|
||||||
|
*next_address += 1;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
next_position[0] += SQUARE / 3; // third of a square
|
||||||
|
|
||||||
|
return components;
|
||||||
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
use std::f32::consts::PI;
|
||||||
|
|
||||||
|
use logicworld_subassembly::{lw, COMPONENT_MAP};
|
||||||
|
use vecmath::{vec3_add, Vector3};
|
||||||
|
|
||||||
|
use crate::cells::builder;
|
||||||
|
use crate::router::{Connection, ConnectionMap, SQUARE};
|
||||||
|
|
||||||
|
pub fn output_port(
|
||||||
|
bits: &Vec<usize>,
|
||||||
|
port_name: &str,
|
||||||
|
parent_address: u32,
|
||||||
|
next_address: &mut u32,
|
||||||
|
next_position: &mut Vector3<lw::Int>,
|
||||||
|
connection_map: &mut ConnectionMap,
|
||||||
|
) -> Vec<lw::Component> {
|
||||||
|
let mut components = vec![];
|
||||||
|
let mut wires = vec![]; // discard
|
||||||
|
builder(
|
||||||
|
bits.len(),
|
||||||
|
parent_address,
|
||||||
|
next_address,
|
||||||
|
next_position,
|
||||||
|
&mut components,
|
||||||
|
&mut wires,
|
||||||
|
connection_map,
|
||||||
|
|i_bit, next_address, parent, next_position_within, components, _wires, connection_map| {
|
||||||
|
let bit_id = bits[i_bit];
|
||||||
|
let label = lw::Component {
|
||||||
|
address: *next_address,
|
||||||
|
parent,
|
||||||
|
numeric_id: COMPONENT_MAP["MHG.PanelLabel"],
|
||||||
|
position: vec3_add(*next_position_within, [0, 0, SQUARE]),
|
||||||
|
rotation: quaternion::euler_angles(0.0, -PI / 2.0, 0.0),
|
||||||
|
inputs: vec![],
|
||||||
|
outputs: vec![],
|
||||||
|
custom_data: lw::Label::new(&format!("{}[{}]", port_name, i_bit))
|
||||||
|
.with_size(2.0)
|
||||||
|
.custom_data(),
|
||||||
|
};
|
||||||
|
|
||||||
|
*next_address += 1;
|
||||||
|
|
||||||
|
let peg = lw::Component {
|
||||||
|
address: *next_address,
|
||||||
|
parent,
|
||||||
|
numeric_id: COMPONENT_MAP["MHG.Peg"],
|
||||||
|
position: *next_position_within,
|
||||||
|
rotation: quaternion::id(),
|
||||||
|
inputs: vec![lw::Input::new(bit_id as lw::Int)],
|
||||||
|
outputs: vec![],
|
||||||
|
custom_data: vec![],
|
||||||
|
};
|
||||||
|
|
||||||
|
connection_map.insert(
|
||||||
|
Connection {
|
||||||
|
cell_index: bit_id,
|
||||||
|
port_name: "output",
|
||||||
|
bit_index: 0,
|
||||||
|
},
|
||||||
|
lw::PegAddress::input(peg.address, 0),
|
||||||
|
);
|
||||||
|
|
||||||
|
components.push(label);
|
||||||
|
components.push(peg);
|
||||||
|
|
||||||
|
*next_address += 1;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
next_position[0] += SQUARE / 3; // third of a square
|
||||||
|
|
||||||
|
return components;
|
||||||
|
}
|
Loading…
Reference in new issue