Browse Source

Small steps towards proper fixed belts

belt_ext
Weird Constructor 2 months ago
parent
commit
9cdc86be71
  1. 157
      src/belt.rs
  2. 4
      src/transport.rs

157
src/belt.rs

@ -118,7 +118,9 @@ where
}
fn update_t_origin(&mut self) {
self.t_origin = self.dir.tile_front_px(self.front_tile);
self.t_origin = self
.dir
.tile_front_px_offs(self.front_tile, self.t.extension_len() as i32);
}
pub fn dir(&self) -> Dir {
@ -136,11 +138,11 @@ where
pub fn back_pos(&self) -> (i32, i32) {
self.dir
.tile_front_px_offs(self.front_tile, -(self.t.length() as i32 - 1))
.tile_front_px_offs(self.front_tile, -(self.t.length_core() as i32 - 1))
}
pub fn tile_length(&self) -> usize {
self.t.length() as usize / (BELT_TILE_SIZE_PX as usize)
self.t.length_core() as usize / (BELT_TILE_SIZE_PX as usize)
}
pub fn tile_on_same_axis(&self, pos: (i32, i32)) -> bool {
@ -199,7 +201,7 @@ where
}
}
pub fn enable_extension(&mut self) {
pub fn enable_load_ext(&mut self) {
let ents = self.t.set_extension((BELT_TILE_SIZE_PX / 2) as u32);
assert!(
ents.is_none(),
@ -209,13 +211,13 @@ where
self.update_t_origin();
}
pub fn disable_extension(&mut self) -> Option<Vec<Entity>> {
pub fn disable_load_ext(&mut self) -> Option<Vec<Entity>> {
let ents = self.t.set_extension(0);
self.update_t_origin();
ents
}
pub fn is_extended(&self) -> bool {
pub fn has_load_ext(&self) -> bool {
self.t.extension_len() > 0
}
@ -239,6 +241,11 @@ where
(false, self.front_tile, other.end_tile())
};
assert!(
self.t.length_core() == self.t.length(),
"I have not yet implemented this!"
);
let new_len = ((self.dir.diff(front_tile, end_tile).abs() + 1) * BELT_TILE_SIZE_PX) as u32;
if new_len < self.t.length() {
return false;
@ -296,11 +303,11 @@ where
}
pub fn iter_tiles<F: FnMut(Dir, (i32, i32))>(&self, f: &mut F) {
if self.t.length() == 0 {
if self.t.length_core() == 0 {
return;
}
let tile_count = self.t.length() / (BELT_TILE_SIZE_PX as u32);
let tile_count = self.t.length_core() / (BELT_TILE_SIZE_PX as u32);
let mut cur = self.front_tile;
let walk_dir = self.dir.reverse();
@ -441,7 +448,7 @@ where
}
pub fn end_tile(&self) -> (i32, i32) {
let tile_count = self.t.length() / (BELT_TILE_SIZE_PX as u32);
let tile_count = self.tile_length();
self.dir
.reverse()
.offs_tile_by_n(self.front_tile, tile_count.max(1) as i32 - 1)
@ -460,7 +467,8 @@ where
}
pub fn end_target_pos(&self) -> (i32, i32) {
self.dir.tile_front_px_offs(self.front_tile, 1)
self.dir
.tile_front_px_offs(self.front_tile, self.t.extension_len().max(1) as i32)
}
pub fn end_target_tile_pos(&self) -> (i32, i32) {
@ -2940,4 +2948,133 @@ mod test {
fn check_belts_under_move_off_no_jump() {
assert!(false);
}
#[test]
fn check_belt_load_ext_l_0() {
let mut e = Belt::<Chem>::new(0, Dir::L);
e.extend(1);
e.set_front((0, 0));
e.enable_load_ext();
assert_eq!(e.front_pos(), (-32, 0));
assert_eq!(e.back_pos(), (15, 0));
assert_eq!(e.end_tile(), (0, 0));
assert_eq!(e.end_target_tile_pos(), (-1, 0));
assert_eq!(e.end_target_pos(), (-32, 0));
}
#[test]
fn check_belt_load_ext_u_0() {
let mut e = Belt::<Chem>::new(0, Dir::U);
e.extend(1);
e.set_front((0, 0));
e.enable_load_ext();
assert_eq!(e.front_pos(), (0, -32));
assert_eq!(e.back_pos(), (0, 15));
assert_eq!(e.end_tile(), (0, 0));
assert_eq!(e.end_target_tile_pos(), (0, -1));
assert_eq!(e.end_target_pos(), (0, -32));
}
#[test]
fn check_belt_load_ext_r_0() {
let mut e = Belt::<Chem>::new(0, Dir::R);
e.extend(1);
e.set_front((0, 0));
e.enable_load_ext();
assert_eq!(e.front_pos(), (31, 0));
assert_eq!(e.back_pos(), (-16, 0));
assert_eq!(e.end_tile(), (0, 0));
assert_eq!(e.end_target_tile_pos(), (1, 0));
assert_eq!(e.end_target_pos(), (31, 0));
}
#[test]
fn check_belt_load_ext_d_0() {
let mut e = Belt::<Chem>::new(0, Dir::D);
e.extend(1);
e.set_front((0, 0));
e.enable_load_ext();
assert_eq!(e.front_pos(), (0, 31));
assert_eq!(e.back_pos(), (0, -16));
assert_eq!(e.end_tile(), (0, 0));
assert_eq!(e.end_target_tile_pos(), (0, 1));
assert_eq!(e.end_target_pos(), (0, 31));
}
#[test]
fn check_belt_load_ext_extend_to_u() {
let mut e = Belt::new(0, Dir::U);
e.set_front((0, 0));
e.extend(2);
e.enable_load_ext();
assert_eq!(e_tiles(&e), vec![(Dir::U, (0, 0)), (Dir::U, (0, 1))]);
e.extend(-1);
assert_eq!(
e_tiles(&e),
vec![(Dir::U, (0, -1)), (Dir::U, (0, 0)), (Dir::U, (0, 1))]
);
assert_eq!(e.end_target_pos(), (0, -64));
}
#[test]
fn check_belt_load_ext_insert() {
let mut e = Belt::<Chem>::new(0, Dir::R);
e.extend(2);
e.set_front((0, 0));
e.enable_load_ext();
assert!(!e.insert_entity((32, 0), Chem::H2));
assert!(e.insert_entity((31, 0), Chem::H2));
assert!(e.insert_entity((14, 0), Chem::O2));
assert!(e.insert_entity((-1, 0), Chem::Fe2O3));
assert_eq!(
e_ents(&e),
vec![(31, 0, Chem::H2), (14, 0, Chem::O2), (-2, 0, Chem::Fe2O3)],
);
}
#[test]
fn check_belt_load_ext_fill() {
let mut e = Belt::<Chem>::new(0, Dir::R);
e.extend(3);
e.set_front((0, 0));
let mut e_orig = e.clone();
e.enable_load_ext();
e.fill_from_pattern(&[Chem::O2, Chem::H2, Chem::Fe2O3]);
e_orig.fill_from_pattern(&[Chem::O2, Chem::H2, Chem::Fe2O3]);
assert_eq!(
e_ents(&e_orig),
vec![
(15, 0, Chem::O2),
(-1, 0, Chem::H2),
(-17, 0, Chem::Fe2O3),
(-33, 0, Chem::O2),
(-49, 0, Chem::H2),
(-65, 0, Chem::Fe2O3)
],
);
assert_eq!(
e_ents(&e),
vec![
(31, 0, Chem::O2),
(15, 0, Chem::H2),
(-1, 0, Chem::Fe2O3),
(-17, 0, Chem::O2),
(-33, 0, Chem::H2),
(-49, 0, Chem::Fe2O3),
(-65, 0, Chem::O2)
],
);
}
}

4
src/transport.rs

@ -446,6 +446,10 @@ where
self.length_px
}
pub fn length_core(&self) -> u32 {
self.length_px - self.ext_px
}
pub fn length_with_overhang(&self) -> u32 {
let start_of_next_elem = if let Some((pos, _, _)) = self.contents.back() {
*pos + self.slot_size

Loading…
Cancel
Save