1
Fork 0

assume schematic placement zones are traversable

This commit is contained in:
Andy Killorin 2023-12-30 11:49:22 -06:00
parent c49f5735ec
commit 5eaee49b7d
Signed by: ank
GPG key ID: B6241CA3B552BCA4
3 changed files with 19 additions and 10 deletions

View file

@ -5,7 +5,7 @@ use anyhow::{Ok, anyhow};
use nalgebra::Vector3; use nalgebra::Vector3;
use rstar::{PointDistance, RTree, RTreeObject, AABB, Envelope}; use rstar::{PointDistance, RTree, RTreeObject, AABB, Envelope};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tokio::sync::{RwLock, OwnedRwLockReadGuard}; use tokio::sync::{RwLock, OwnedRwLockReadGuard, OwnedRwLockWriteGuard};
use crate::{turtle::TurtleCommand, paths::{self, TRANSPARENT}}; use crate::{turtle::TurtleCommand, paths::{self, TRANSPARENT}};
@ -98,6 +98,10 @@ impl SharedWorld {
pub async fn lock(self) -> OwnedRwLockReadGuard<World> { pub async fn lock(self) -> OwnedRwLockReadGuard<World> {
self.state.read_owned().await self.state.read_owned().await
} }
pub async fn lock_mut(self) -> OwnedRwLockWriteGuard<World> {
self.state.write_owned().await
}
} }
#[derive(Serialize, Deserialize, Clone, Debug)] #[derive(Serialize, Deserialize, Clone, Debug)]

View file

@ -13,24 +13,20 @@ fn schematic2world(region: &Schematic) -> anyhow::Result<World> {
let mut world = World::new(); let mut world = World::new();
let min = region.origin().context("bad schematic")?; let min = region.origin().context("bad schematic")?;
let area = Vec3::new(
region.width() as i32,
region.height() as i32,
region.length() as i32,
);
info!("area {}", area);
for (position, block) in region.blocks() { for (position, block) in region.blocks() {
println!("{:#?}, {}", block, position);
let name = match block { let name = match block {
BlockState::AIR => None, BlockState::AIR => None,
BlockState(20) => None, // Glass
BlockState(102) => None, // Glass pane
BlockState(95) => None, // Stained glass
BlockState(160) => None, // Stained glass pane
// who cares // who cares
_ => Some("terrestria:hemlock_planks") _ => Some("terrestria:hemlock_planks")
}.map(|s| s.to_string()); }.map(|s| s.to_string());
if let Some(name) = name { if let Some(name) = name {
println!("{:#?}, {:?}", name, block);
let block = Block { let block = Block {
name, name,
pos: position - min, pos: position - min,
@ -98,6 +94,15 @@ impl BuildSimple {
async fn build_layer(&self, turtle: TurtleCommander, layer: i32) -> Option<()> { async fn build_layer(&self, turtle: TurtleCommander, layer: i32) -> Option<()> {
let layer_size = Vec3::new(self.size.x, 1, self.size.z); let layer_size = Vec3::new(self.size.x, 1, self.size.z);
// assume the layer is empty for better pathfinding
let mut world = turtle.world().lock_mut().await;
for point in (0..layer_size.product()).map(|n| fill(layer_size, n)) {
if let None = world.get(point) {
world.set(Block { name: "minecraft:air".into(), pos: point })
}
}
drop(world);
for point in (0..layer_size.product()) for point in (0..layer_size.product())
.map(|n| fill(layer_size, n)) { .map(|n| fill(layer_size, n)) {
let point = point + Vec3::y() * layer; let point = point + Vec3::y() * layer;

View file

@ -296,7 +296,7 @@ pub(crate) async fn build(
) -> &'static str { ) -> &'static str {
let state = state.read().await; let state = state.read().await;
let mut schedule = state.tasks.lock().await; let mut schedule = state.tasks.lock().await;
let schematic = Schematic::load(&mut fs::File::open("thethinkman.schematic").await.unwrap().into_std().await).unwrap(); let schematic = Schematic::load(&mut fs::File::open("schematics/greek-athelete1.schematic").await.unwrap().into_std().await).unwrap();
let input = Position::new( let input = Position::new(
Vec3::new(53,73,77), Vec3::new(53,73,77),