voxel-zone/common/src/space/two_dimensional/depth_tiles.rs

58 lines
1.4 KiB
Rust

#[cfg(feature = "serde")]
use serde::{Serialize, Deserialize};
#[cfg(feature = "std")]
use strum_macros::EnumIter;
#[cfg(feature = "three_dimensional")]
use crate::space::three_dimensional::{traits::VoxelContainer, vec3generic::Vec3Generic};
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "std", derive(EnumIter))]
pub enum Direction {
North,
South,
East,
West,
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug)]
pub struct DepthTile<T>
where
T: Default,
{
pub data: T,
pub x: i32,
pub y: i32,
pub depth: i32,
}
#[cfg(feature = "std")]
#[derive(Default)]
#[cfg_attr(feature = "bevy", derive(bevy::prelude::Component))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct DepthTileContainer<T>
where
T: Default,
{
pub tiles: Vec<DepthTile<T>>,
}
#[cfg(all(feature = "block-mesh", feature = "three_dimensional"))]
/// Implementation that projects depth tiles back into voxels from the north face, mostly for visualization in the editor
impl<T> VoxelContainer<T> for DepthTileContainer<T>
where
T: Copy + Default,
{
fn get_voxel_at_pos(&self, pos: Vec3Generic<i32>) -> Option<T> {
for tile in &self.tiles {
if tile.x == pos.x && tile.y == pos.y && tile.depth == pos.z {
return Some(tile.data);
}
}
None
}
}