Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/dmm-tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ lodepng = "3.10.7"
indexmap = "2.6.0"
foldhash = "0.2.0"
either = "1.13.0"
glam = "0.30"
derive_more = {version = "2.1.1", features = ["deref"]}

[dependencies.bytemuck]
version = "1.19.0"
Expand Down
82 changes: 30 additions & 52 deletions crates/dmm-tools/src/dmm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use std::fs::File;
use std::io;
use std::path::Path;

use derive_more::Deref;
use foldhash::fast::RandomState;
use glam::{IVec2, IVec3};
use indexmap::IndexMap;
use ndarray::{self, Array3, Axis};

Expand All @@ -28,60 +30,49 @@ pub struct Key(KeyType);
/// An XY coordinate pair in the BYOND coordinate system.
///
/// The lower-left corner is `{ x: 1, y: 1 }`.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct Coord2 {
pub x: i32,
pub y: i32,
}
#[derive(Deref)]
pub struct Coord2(IVec2);

impl Coord2 {
#[inline]
pub fn new(x: i32, y: i32) -> Coord2 {
Coord2 { x, y }
}

#[inline]
pub fn z(self, z: i32) -> Coord3 {
Coord3 {
x: self.x,
y: self.y,
z,
}
self.extend(z).into()
}

#[inline]
fn to_raw(self, (dim_y, dim_x): (usize, usize)) -> (usize, usize) {
assert!(
self.x >= 1 && self.x <= dim_x as i32,
(1..=(dim_x as i32)).contains(&self.x),
"x={} not in [1, {}]",
self.x,
dim_x
);
assert!(
self.y >= 1 && self.y <= dim_y as i32,
(1..=(dim_y as i32)).contains(&self.y),
"y={} not in [1, {}]",
self.y,
dim_y
);
(dim_y - self.y as usize, self.x as usize - 1)
}

#[inline]
fn from_raw((y, x): (usize, usize), (dim_y, _dim_x): (usize, usize)) -> Coord2 {
Coord2 {
x: x as i32 + 1,
y: (dim_y - y) as i32,
}
Coord2(IVec2::new(x as i32 + 1, (dim_y - y) as i32))
}
}

impl std::ops::Add<Dir> for Coord2 {
type Output = Coord2;

fn add(self, rhs: Dir) -> Coord2 {
let (x, y) = rhs.offset();
Coord2 {
x: self.x + x,
y: self.y + y,
}
Coord2(self.0 + rhs.offset())
}
}

impl From<IVec2> for Coord2 {
fn from(value: IVec2) -> Self {
Self(value)
}
}

Expand All @@ -91,42 +82,26 @@ impl std::ops::Add<Dir> for Coord2 {
///
/// Note that BYOND by default considers "UP" to be Z+1, but this does not
/// necessarily apply to a given game's logic.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct Coord3 {
pub x: i32,
pub y: i32,
pub z: i32,
}
#[derive(Deref)]
pub struct Coord3(IVec3);

impl Coord3 {
#[inline]
pub fn new(x: i32, y: i32, z: i32) -> Coord3 {
Coord3 { x, y, z }
}

#[inline]
pub fn xy(self) -> Coord2 {
Coord2 {
x: self.x,
y: self.y,
}
}

fn to_raw(self, (dim_z, dim_y, dim_x): (usize, usize, usize)) -> (usize, usize, usize) {
assert!(
self.x >= 1 && self.x <= dim_x as i32,
(1..=(dim_x as i32)).contains(&self.x),
"x={} not in [1, {}]",
self.x,
dim_x
);
assert!(
self.y >= 1 && self.y <= dim_y as i32,
(1..=(dim_y as i32)).contains(&self.y),
"y={} not in [1, {}]",
self.y,
dim_y
);
assert!(
self.z >= 1 && self.z <= dim_z as i32,
(1..=(dim_z as i32)).contains(&self.z),
"y={} not in [1, {}]",
self.z,
dim_z
Expand All @@ -139,15 +114,18 @@ impl Coord3 {
}

#[allow(dead_code)]
#[inline]
fn from_raw(
(z, y, x): (usize, usize, usize),
(_dim_z, dim_y, _dim_x): (usize, usize, usize),
) -> Coord3 {
Coord3 {
x: x as i32 + 1,
y: (dim_y - y) as i32,
z: z as i32 + 1,
}
Coord3(IVec3::new(x as i32 + 1, (dim_y - y) as i32, z as i32 + 1))
}
}

impl From<IVec3> for Coord3 {
fn from(value: IVec3) -> Self {
Self(value)
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/dreammaker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ derivative = "2.2.0"
get-size = "0.1.4"
get-size-derive = "0.1.3"
beef = "0.5.2"
glam = "0.30"

[dev-dependencies]
walkdir = "2.5.0"
19 changes: 10 additions & 9 deletions crates/dreammaker/src/dmi.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! DMI metadata parsing and representation.

use foldhash::{HashMap, HashMapExt};
use glam::IVec2;
use std::collections::BTreeMap;
use std::fmt::Display;
use std::io;
Expand Down Expand Up @@ -190,16 +191,16 @@ impl Dir {
}

/// Get this direction's offset in BYOND's coordinate system.
pub fn offset(self) -> (i32, i32) {
pub fn offset(self) -> IVec2 {
match self {
Dir::North => (0, 1),
Dir::South => (0, -1),
Dir::East => (1, 0),
Dir::West => (-1, 0),
Dir::Northeast => (1, 1),
Dir::Northwest => (-1, 1),
Dir::Southeast => (1, -1),
Dir::Southwest => (-1, -1),
Dir::North => IVec2::new(0, 1),
Dir::South => IVec2::new(0, -1),
Dir::East => IVec2::new(1, 0),
Dir::West => IVec2::new(-1, 0),
Dir::Northeast => IVec2::new(1, 1),
Dir::Northwest => IVec2::new(-1, 1),
Dir::Southeast => IVec2::new(1, -1),
Dir::Southwest => IVec2::new(-1, -1),
}
}
}
Expand Down