From a2d899c5b6485b4b1382926b0d059d4e5323296b Mon Sep 17 00:00:00 2001 From: rollrat Date: Sun, 17 Nov 2024 14:44:28 +0900 Subject: [PATCH] wip --- src/transform/placer/mod.rs | 16 ++++++++++------ test/and-gate.nbt | Bin 453 -> 462 bytes 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/transform/placer/mod.rs b/src/transform/placer/mod.rs index 97f7e43..99f2fbc 100644 --- a/src/transform/placer/mod.rs +++ b/src/transform/placer/mod.rs @@ -15,7 +15,7 @@ use crate::{ logic::LogicType, world::{ block::{Block, BlockKind, Direction, RedstoneState}, - position::{DimSize, Position}, + position::{self, DimSize, Position}, world::World3D, }, }; @@ -90,21 +90,23 @@ impl LocalPlacer { Ok(()) } - pub fn generate(&mut self) -> Vec { + pub fn generate(&mut self, finish_index: Option) -> Vec { let orders = self.graph.topological_order(); let mut queue: VecDeque<(usize, World3D, HashMap)> = VecDeque::new(); queue.push_back((0, World3D::new(DimSize(10, 10, 10)), Default::default())); - while let Some((order_index, world, pos)) = queue.pop_front() { - if order_index == orders.len() { + while let Some((order_index, _, _)) = queue.front() { + if *order_index == orders.len() || Some(*order_index) == finish_index { break; } + let (order_index, world, pos) = queue.pop_front().unwrap(); let node_id = orders[order_index]; for (world, place_position) in self.place_and_route_next_node(node_id, &world, &pos) { let mut nodes_position = pos.clone(); nodes_position.insert(node_id, place_position); queue.push_back((order_index + 1, world, nodes_position)); + println!("{place_position:?}"); } } @@ -274,9 +276,11 @@ mod tests { println!("{}", logic_graph.to_graphviz()); let mut placer = LocalPlacer::new(logic_graph)?; - let world3d = placer.generate(); + let world3d = placer.generate(Some(1)); - let nbt: NBTRoot = world3d[0].to_nbt(); + dbg!(&world3d[2]); + + let nbt: NBTRoot = world3d[2].to_nbt(); nbt.save("test/and-gate-new.nbt"); Ok(()) diff --git a/test/and-gate.nbt b/test/and-gate.nbt index bfe46dffd768b98beb765fe0f5d560ff383e1474..bf4316462fda970548d0b6cbcaae384245df304a 100644 GIT binary patch literal 462 zcmb2|=3oE;rvFQ)UGzI-AkudGvRGp0N58!vW%qpJ++(zlQSz}ucXI44txo@Z)?*1} zZ~7zT3B%E_{rZtIh}9a%ZwDQfY6HxtbnwtKCh4)8I-vTg|Z29bKyr9qY%hh2&#|v@B zzl(r6YB)Y99%yHf2Ww)GXZ@i8vRmrI#fE;i8lDHq4D!rBW>ieuo%N~9`N90hk4m(@ zc<)Or+^m_c7qgGcU$lPHX_s%Wat`ZFd854L6t`GfXyofhR}x?Bl0M~KzNhy3-LgGj z4qmglKdrBN=CX~^WlnZwjoa@&smpnIs$zrfzkd_F&aKXpTcdq#?;p<+z1QXox4&ur zu{n0mV;i<3hrdr+-oEATqSJf)Q{GMa_c7%0Tla|V{ia(>-)jBKzdzwpjU+!00|Nk2 Cli%n7 literal 453 zcmV;$0XqI4iwFP!00002|E1Q^PQox02H?}4QxFp4oqFRtc$WS}pu*U!%19(m{F7G*c z=SO*u?WtpPnF}5ZtPcb0!@&A5;9yp5x^sW#{nJ(cpTty=`1(i6_v)Q zhvVY-isYr(DBWzztu8{bicgh(YM9dWHTa!|SZbX@t74(#R+aaGsOfawbt=lxKECT7 z2VK_DZ*{gWgPzrNJHOXJ<}uyY{v)mr=i8;G*4Brn)eUyrRsAhF4`n*^w!c5*MlGsp v7JXQ(&&D35`IOtYX5hBSeWu7y|9?zQw5Ve