diff --git a/Cargo.lock b/Cargo.lock index 72bf388f..8343dee2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -390,6 +390,7 @@ version = "0.1.0" dependencies = [ "bumpalo 2.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "dreammaker 0.1.0", + "gfx_core 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", "inflate 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "lodepng 2.5.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/editor/Cargo.toml b/src/editor/Cargo.toml index eaf40ce4..3a9d37fc 100644 --- a/src/editor/Cargo.toml +++ b/src/editor/Cargo.toml @@ -9,7 +9,7 @@ path = "main.rs" [dependencies] dreammaker = { path = "../dreammaker" } -dmm-tools = { path = "../tools" } +dmm-tools = { path = "../tools", features = ["gfx_core"] } glutin = "0.21.1" gfx_gl = "0.6.0" gfx = "0.18" diff --git a/src/editor/map_renderer.rs b/src/editor/map_renderer.rs index 67cb522b..ff82ae6b 100644 --- a/src/editor/map_renderer.rs +++ b/src/editor/map_renderer.rs @@ -10,7 +10,7 @@ use slice_of_array::prelude::*; use dm::objtree::ObjectTree; use dmm_tools::dmm::Prefab; -use dmm_tools::minimap::Sprite; +use dmm_tools::minimap::{Sprite, Category, Layer}; use dmi::*; use map_repr::AtomMap; @@ -30,9 +30,9 @@ gfx_defines! { transform: [[f32; 4]; 4] = "transform", } - #[derive(PartialOrd, Default)] + #[derive(Default)] constant RenderPop { - category: u32 = "category", + category: Category = "category", texture: u32 = "texture", // icon size: [f32; 2] = "size", // icon @@ -43,7 +43,7 @@ gfx_defines! { ofs_y: i32 = "ofs_y", // pixel_y + pixel_z + step_y plane: i32 = "plane", - layer: i32 = "layer", + layer: Layer = "layer", } pipeline pipe { @@ -78,7 +78,7 @@ pub struct RenderedMap { #[derive(Debug, Clone)] pub struct DrawCall { - pub category: u32, + pub category: Category, pub texture: u32, pub len: u32, } @@ -205,7 +205,7 @@ impl RenderedMap { let mut start = 0; for call in map.levels[z as usize].draw_calls.iter() { - if !parent.layers[call.category as usize] { + if !call.category.matches_basic_layers(&parent.layers) { start += call.len; continue; } @@ -271,12 +271,6 @@ impl RenderedMap { // forgive me impl ::std::cmp::Eq for RenderPop {} -impl ::std::cmp::Ord for RenderPop { - fn cmp(&self, other: &Self) -> ::std::cmp::Ordering { - self.partial_cmp(other).expect("in RenderPop::cmp, a field was NaN") - } -} - impl ::std::hash::Hash for RenderPop { fn hash(&self, state: &mut H) { self.category.hash(state); @@ -327,7 +321,7 @@ impl RenderPop { ]; Some(RenderPop { - category: sprite.category.encode(), + category: sprite.category, texture: texture_id as u32, uv, color, @@ -335,7 +329,7 @@ impl RenderPop { ofs_x: sprite.ofs_x, ofs_y: sprite.ofs_y, plane: sprite.plane, - layer: sprite.layer.encode(), + layer: sprite.layer, }) } diff --git a/src/tools/Cargo.toml b/src/tools/Cargo.toml index 20c95302..6417c5aa 100644 --- a/src/tools/Cargo.toml +++ b/src/tools/Cargo.toml @@ -19,5 +19,9 @@ bumpalo = "2.6.0" version = "0.15.0" optional = true +[dependencies.gfx_core] +version = "0.9.2" +optional = true + [dev-dependencies] walkdir = "2.0.1" diff --git a/src/tools/lib.rs b/src/tools/lib.rs index ce2a35c0..87abc8fe 100644 --- a/src/tools/lib.rs +++ b/src/tools/lib.rs @@ -12,6 +12,8 @@ extern crate linked_hash_map; extern crate rand; extern crate bumpalo; +#[cfg(feature="gfx_core")] extern crate gfx_core; + pub mod dmm; mod icon_cache; pub mod minimap; diff --git a/src/tools/minimap.rs b/src/tools/minimap.rs index ae778380..4b0e66c9 100644 --- a/src/tools/minimap.rs +++ b/src/tools/minimap.rs @@ -403,7 +403,7 @@ impl<'a> GetVar<'a> for TypeRef<'a> { // Renderer-agnostic sprite structure /// Information about when a sprite should be shown or hidden. -#[derive(Default, Debug, Clone, Copy, Eq, PartialEq)] +#[derive(Default, Debug, Clone, Copy, Eq, PartialEq, Hash)] pub struct Category { raw: u32, } @@ -430,8 +430,15 @@ impl Category { } /// Encode this category for FFI representation. - pub fn encode(self) -> u32 { - self.raw + pub fn matches_basic_layers(self, visible: &[bool]) -> bool { + visible.get(self.raw as usize).copied().unwrap_or(false) + } +} + +#[cfg(feature="gfx_core")] +impl gfx_core::shade::BaseTyped for Category { + fn get_base_type() -> gfx_core::shade::BaseType { + u32::get_base_type() } } @@ -442,13 +449,6 @@ pub struct Layer { frac: u16, } -impl Layer { - /// Encode this layer as an `i32` for FFI representation. - pub fn encode(self) -> i32 { - ((self.whole as i32) << 16) | (self.frac as i32) - } -} - impl From for Layer { fn from(whole: i16) -> Layer { Layer { whole, frac: 0 } @@ -468,6 +468,13 @@ impl From for Layer { } } +#[cfg(feature="gfx_core")] +impl gfx_core::shade::BaseTyped for Layer { + fn get_base_type() -> gfx_core::shade::BaseType { + i32::get_base_type() + } +} + /// A Sprite is a fragment of an atom's appearance. /// /// Every atom has a default sprite, which may be disabled, and a list of