Skip to content

Commit

Permalink
[unstable-rust] mesh: Use ! type in place of NoTexture.
Browse files Browse the repository at this point in the history
  • Loading branch information
kpreid committed Sep 6, 2024
1 parent 37c047b commit 0fafd6f
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 32 deletions.
6 changes: 6 additions & 0 deletions all-is-cubes-base/src/util/custom_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ impl<T> Fmt<TypeName> for PhantomData<T> {
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct ConciseDebug;

impl Fmt<ConciseDebug> for ! {
fn fmt(&self, _: &mut fmt::Formatter<'_>, _: &ConciseDebug) -> fmt::Result {
match *self {}
}
}

impl<T: Fmt<ConciseDebug>, const N: usize> Fmt<ConciseDebug> for [T; N] {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>, fopt: &ConciseDebug) -> fmt::Result {
fmt.debug_list()
Expand Down
9 changes: 4 additions & 5 deletions all-is-cubes-desktop/src/glue/rerun_mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ use all_is_cubes_mesh as mesh;
use all_is_cubes_render::camera::Camera;

use mesh::dynamic::ChunkedSpaceMesh;
use mesh::texture::NoTexture;

struct Mt;
impl mesh::MeshTypes for Mt {
type Vertex = Vertex;
type Alloc = mesh::texture::NoTextures;
type Tile = NoTexture;
type Tile = !;
}
impl mesh::dynamic::DynamicMeshTypes for Mt {
type RenderData = Option<DroppingMesh>;
Expand All @@ -43,8 +42,8 @@ struct Vertex {
color: rg::components::Color,
}

impl From<mesh::BlockVertex<NoTexture>> for Vertex {
fn from(v: mesh::BlockVertex<NoTexture>) -> Self {
impl From<mesh::BlockVertex<!>> for Vertex {
fn from(v: mesh::BlockVertex<!>) -> Self {
Self {
position: v.position.to_f32().to_array().into(),
color: match v.coloring {
Expand All @@ -59,7 +58,7 @@ impl mesh::GfxVertex for Vertex {

type Coordinate = f32;

type TexPoint = NoTexture;
type TexPoint = !;

type BlockInst = Vector3D<f32, Cube>;

Expand Down
2 changes: 2 additions & 0 deletions all-is-cubes-desktop/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(never_type)]

//! Components for creating a desktop application that renders interactive [`all_is_cubes`]
//! content.
//!
Expand Down
2 changes: 2 additions & 0 deletions all-is-cubes-mesh/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(never_type)]

//! Data structures and algorithms for converting [`all_is_cubes`] voxel data to triangle
//! meshes for rendering or export.
//!
Expand Down
24 changes: 4 additions & 20 deletions all-is-cubes-mesh/src/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use all_is_cubes::block::{Evoxel, Evoxels};
use all_is_cubes::content::palette;
use all_is_cubes::euclid::Point3D;
use all_is_cubes::math::{Axis, Cube, GridAab, GridSizeCoord, Rgb, Vol};
use all_is_cubes::util::{ConciseDebug, Fmt};

/// Numeric type used to calculate texture coordinates and store them in [`BlockVertex`].
///
Expand Down Expand Up @@ -289,26 +288,18 @@ pub fn copy_voxels_into_xmaj_texture(
pub struct NoTextures;

impl Allocator for NoTextures {
type Tile = NoTexture;
type Point = NoTexture;
type Tile = !;
type Point = !;

fn allocate(&self, _: GridAab, _: Channels) -> Option<Self::Tile> {
None
}
}

/// Uninhabited [`Tile`] type; no instance of this ever exists.
///
/// TODO: this can and should be just ! (never) when that's available in stable Rust
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[allow(clippy::exhaustive_enums)]
pub enum NoTexture {}

impl Tile for NoTexture {
impl Tile for ! {
type Point = Self;
type Plane = Self;
const REUSABLE: bool = true;

fn bounds(&self) -> GridAab {
match *self {}
}
Expand All @@ -325,17 +316,10 @@ impl Tile for NoTexture {
match *self {}
}
}

impl Plane for NoTexture {
impl Plane for ! {
type Point = Self;

fn grid_to_texcoord(&self, _: Point3D<TextureCoordinate, TexelUnit>) -> Self::Point {
match *self {}
}
}

impl Fmt<ConciseDebug> for NoTexture {
fn fmt(&self, _: &mut fmt::Formatter<'_>, _: &ConciseDebug) -> fmt::Result {
match *self {}
}
}
2 changes: 2 additions & 0 deletions all-is-cubes-port/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(never_type)]

//! Data import and export between [`all_is_cubes`] types and other data formats.
//!
//! Currently supported formats:
Expand Down
10 changes: 3 additions & 7 deletions all-is-cubes-port/src/stl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ use all_is_cubes::math::{notnan, Cube, FreeCoordinate};
use all_is_cubes::space::Space;
use all_is_cubes::universe::PartialUniverse;
use all_is_cubes::util::YieldProgress;
use all_is_cubes_mesh::{
self as mesh,
texture::{NoTexture, NoTextures},
BlockVertex,
};
use all_is_cubes_mesh::{self as mesh, texture::NoTextures, BlockVertex};
use all_is_cubes_render::camera::GraphicsOptions;

pub(crate) async fn export_stl(
Expand Down Expand Up @@ -115,9 +111,9 @@ enum StlMt {}

impl mesh::MeshTypes for StlMt {
// TODO: It'd be more efficient to use a custom vertex type but we're not bothering for now.
type Vertex = BlockVertex<NoTexture>;
type Vertex = BlockVertex<!>;
type Alloc = NoTextures;
type Tile = NoTexture;
type Tile = !;
}

#[cfg(test)]
Expand Down
1 change: 1 addition & 0 deletions all-is-cubes-render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
//! * [`raytracer::RtRenderer`] does not implement [`headless::HeadlessRenderer`].
#![no_std]
#![feature(never_type)]
// Crate-specific lint settings. (General settings can be found in the workspace manifest.)
#![forbid(unsafe_code)]

Expand Down

0 comments on commit 0fafd6f

Please sign in to comment.