Code gen SRS spawn location constant
This commit is contained in:
parent
aefa1deb6a
commit
583b6b64f8
|
@ -19,6 +19,7 @@ pub fn compile_ruleset(in_path: impl AsRef<Path>, out_path: impl AsRef<Path>) ->
|
|||
struct RulesData {
|
||||
shapes: BTreeMap<String, Vec<(i16, i16)>>,
|
||||
kicks: BTreeMap<String, [Vec<(i16, i16)>; 4]>,
|
||||
spawn: (i16, i16),
|
||||
}
|
||||
|
||||
/// Output data (Rust code)
|
||||
|
@ -31,6 +32,7 @@ struct RulesCode {
|
|||
kicks_tests: Vec<(i16, i16)>,
|
||||
kicks_counts: Vec<usize>,
|
||||
kicks_indices: Vec<usize>,
|
||||
spawn: (i16, i16),
|
||||
}
|
||||
|
||||
struct Extents<E> {
|
||||
|
@ -104,6 +106,7 @@ fn compile(rules: &RulesData) -> RulesCode {
|
|||
kicks_tests,
|
||||
kicks_counts,
|
||||
kicks_indices,
|
||||
spawn: rules.spawn,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -206,6 +209,9 @@ impl RulesCode {
|
|||
let len = self.kicks_indices.len();
|
||||
writeln!(out, "pub const KICKS_INDEX: [usize; {len}] = {arr:?};")?;
|
||||
|
||||
let spawn = self.spawn;
|
||||
writeln!(out, "pub const SPAWN: (i16, i16) = {spawn:?};")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//! Implementation of SRS shapes and movement quirks.
|
||||
|
||||
use crate::input::Kicks as KicksTrait;
|
||||
use crate::piece::{Cells, Rot, Shape as ShapeTrait};
|
||||
use crate::piece::{Cells, Rot, Shape as ShapeTrait, Spawn as SpawnTrait};
|
||||
|
||||
mod code_gen {
|
||||
include!(concat!(env!("OUT_DIR"), "/srs.rs"));
|
||||
|
@ -39,6 +39,12 @@ impl KicksTrait<'static> for Shape {
|
|||
}
|
||||
}
|
||||
|
||||
impl SpawnTrait for Shape {
|
||||
fn spawn_pos(&self) -> (i16, i16) {
|
||||
code_gen::SPAWN
|
||||
}
|
||||
}
|
||||
|
||||
pub type Piece = crate::piece::Piece<Shape>;
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -51,6 +57,21 @@ mod test {
|
|||
use alloc::vec::Vec;
|
||||
use core::ops::Range;
|
||||
|
||||
#[test]
|
||||
fn test_spawn() {
|
||||
use Shape::*;
|
||||
for s in [L, O, J, I, S, T, Z] {
|
||||
assert_eq!(
|
||||
Piece::spawn(s).loc,
|
||||
Loc {
|
||||
x: 4,
|
||||
y: 19,
|
||||
r: Rot::N
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn get_cells(s: Shape, r: Rot) -> (Range<i16>, Range<i16>, Vec<(i16, i16)>) {
|
||||
let piece = Piece {
|
||||
shape: s,
|
||||
|
|
Loading…
Reference in New Issue