feat: implement span interface
This commit is contained in:
parent
b391894f4f
commit
b597bffc0e
|
@ -66,7 +66,8 @@ pub fn op_plant(instruction: &u16, tree: &mut Tree, next_tree_id: &mut u16, tree
|
||||||
trunk: Vec::with_capacity((new_stack_size / 2) as usize),
|
trunk: Vec::with_capacity((new_stack_size / 2) as usize),
|
||||||
asleep: false,
|
asleep: false,
|
||||||
resume_from: 0,
|
resume_from: 0,
|
||||||
position: ((tree.position.0 + relative_x) % land.width, (tree.position.1 + relative_y) % land.height)
|
position: ((tree.position.0 + relative_x) % land.width, (tree.position.1 + relative_y) % land.height),
|
||||||
|
span: [[0u16; 8]; 8], // TODO: should take from current state of land!
|
||||||
});
|
});
|
||||||
|
|
||||||
*next_tree_id += 1;
|
*next_tree_id += 1;
|
||||||
|
|
|
@ -103,7 +103,8 @@ fn parse_rom(path: &String) -> io::Result<(state::Land, Vec<state::Rule>, HashMa
|
||||||
asleep: false,
|
asleep: false,
|
||||||
resume_from: 0,
|
resume_from: 0,
|
||||||
stack_size: original_stack_size,
|
stack_size: original_stack_size,
|
||||||
position: (seed_cell_x % land.width, seed_cell_y % land.height)
|
position: (seed_cell_x % land.width, seed_cell_y % land.height),
|
||||||
|
span: [[0u16; 8]; 8],
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok((land, rules, trees))
|
Ok((land, rules, trees))
|
||||||
|
|
19
src/state.rs
19
src/state.rs
|
@ -42,7 +42,12 @@ pub struct Tree {
|
||||||
pub asleep: bool,
|
pub asleep: bool,
|
||||||
pub resume_from: u16,
|
pub resume_from: u16,
|
||||||
pub stack_size: usize,
|
pub stack_size: usize,
|
||||||
pub position: (u16, u16)
|
pub position: (u16, u16),
|
||||||
|
pub span: [[u16; 8]; 8],
|
||||||
|
}
|
||||||
|
|
||||||
|
fn derelativize_span_coordinates(x: i16, y: i16) -> (usize, usize) {
|
||||||
|
return ((x + 4) as usize, (y + 4) as usize);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Tree {
|
impl Tree {
|
||||||
|
@ -91,4 +96,16 @@ impl Tree {
|
||||||
self.pull_trunk()
|
self.pull_trunk()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn sow(&mut self, relative_x: i16, relative_y: i16, value: u16) {
|
||||||
|
let (x, y) = derelativize_span_coordinates(relative_x, relative_y);
|
||||||
|
self.span[x][y] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn reap(&mut self, relative_x: i16, relative_y: i16) -> u16 {
|
||||||
|
let (x, y) = derelativize_span_coordinates(relative_x, relative_y);
|
||||||
|
let value = self.span[x][y];
|
||||||
|
self.sow(relative_x, relative_y, 0);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue