graphics rewrite

This commit is contained in:
Quaternions 2024-02-07 19:46:14 -08:00
parent 2ee041ff66
commit a1fa2c2781
2 changed files with 49 additions and 26 deletions

View File

@ -1,14 +1,14 @@
use std::collections::HashMap;
use crate::model; use crate::model;
use crate::gameplay_modes; use crate::gameplay_modes;
use crate::gameplay_attributes; use crate::gameplay_attributes;
//this is the current map data loaded in memory //this is a temporary struct to try to get the code running again
pub struct Map{ //TODO: use snf::map::Region to update the data in physics and graphics instead of this
pub struct CompleteMap{
pub modes:gameplay_modes::Modes, pub modes:gameplay_modes::Modes,
pub indexed_models:HashMap<model::IndexedModelId,model::IndexedModel>,
pub models:HashMap<model::ModelId,model::Model>,
pub attributes:Vec<gameplay_attributes::CollisionAttributes>, pub attributes:Vec<gameplay_attributes::CollisionAttributes>,
pub meshes:Vec<model::Mesh>,
pub models:Vec<model::Model>,
//RenderPattern //RenderPattern
pub textures:Vec<Vec<u8>>, pub textures:Vec<Vec<u8>>,
pub render_configs:Vec<model::RenderConfig>,
} }

View File

@ -22,41 +22,64 @@ pub struct IndexedVertex{
} }
#[derive(Clone,Copy,Hash,id::Id,PartialEq,Eq)] #[derive(Clone,Copy,Hash,id::Id,PartialEq,Eq)]
pub struct VertexId(u32); pub struct VertexId(u32);
pub struct IndexedVertexList{ pub type IndexedVertexList=Vec<VertexId>;
vertices:Vec<VertexId>, pub trait PolygonIter{
fn polys(&self)->impl Iterator<Item=&[VertexId]>;
} }
impl IndexedVertexList{ pub trait MapVertexId{
pub const fn new(vertices:Vec<VertexId>)->Self{ fn map_vertex_id<F:Fn(VertexId)->VertexId>(self,f:F)->Self;
Self{vertices} }
pub struct PolygonList(Vec<IndexedVertexList>);
impl PolygonList{
pub const fn new(list:Vec<IndexedVertexList>)->Self{
Self(list)
} }
} }
impl PolygonIter for PolygonList{
fn polys(&self)->impl Iterator<Item=&[VertexId]>{
self.0.iter().map(|poly|poly.as_slice())
}
}
impl MapVertexId for PolygonList{
fn map_vertex_id<F:Fn(VertexId)->VertexId>(self,f:F)->Self{
Self(self.0.into_iter().map(|ivl|ivl.into_iter().map(&f).collect()).collect())
}
}
// pub struct TriangleStrip(IndexedVertexList);
// impl PolygonIter for TriangleStrip{
// fn polys(&self)->impl Iterator<Item=&[VertexId]>{
// self.0.vertices.windows(3).enumerate().map(|(i,s)|if i&0!=0{return s.iter().rev()}else{return s.iter()})
// }
// }
#[derive(Clone,Copy,Hash,id::Id,PartialEq,Eq)] #[derive(Clone,Copy,Hash,id::Id,PartialEq,Eq)]
pub struct PolygonGroupId(u32); pub struct PolygonGroupId(u32);
pub enum PolygonGroup{ pub enum PolygonGroup{
PolygonList(Vec<IndexedVertexList>), PolygonList(PolygonList),
//TriangleStrip(Vec<VertexId>), //TriangleStrip(TriangleStrip),
} }
impl PolygonGroup{ impl PolygonIter for PolygonGroup{
pub fn polys(&self)->impl Iterator<Item=&[VertexId]>{ fn polys(&self)->impl Iterator<Item=&[VertexId]>{
match self{ match self{
PolygonGroup::PolygonList(polys)=>return polys.iter().map(|poly|poly.vertices.as_slice()), PolygonGroup::PolygonList(list)=>list.polys(),
//PolygonGroup::TriangleStrip(strip)=>return strip.windows(3).enumerate().map(|(i,s)|if i&0!=0{return s.iter().rev()}else{return s.iter()}), //PolygonGroup::TriangleStrip(strip)=>strip.polys(),
} }
} }
pub fn map_vertex_id<F:Fn(VertexId)->VertexId>(self,f:F)->Self{ }
impl MapVertexId for PolygonGroup{
fn map_vertex_id<F:Fn(VertexId)->VertexId>(self,f:F)->Self{
match self{ match self{
PolygonGroup::PolygonList(polys)=>Self::PolygonList(polys.into_iter().map(|ivl|IndexedVertexList{vertices:ivl.vertices.into_iter().map(&f).collect()}).collect()), PolygonGroup::PolygonList(polys)=>Self::PolygonList(polys.map_vertex_id(f)),
} }
} }
} }
/// Ah yes, a group of things to render at the same time /// Ah yes, a group of things to render at the same time
#[derive(Clone,Copy,Hash,id::Id,Eq,PartialEq)] #[derive(Clone,Copy,Hash,id::Id,Eq,PartialEq)]
pub struct RenderGroupId(u32);
#[derive(Clone,Copy,Hash,id::Id,Eq,PartialEq)]
pub struct TextureId(u32); pub struct TextureId(u32);
#[derive(Clone,Copy,Hash,id::Id,Eq,PartialEq)]
pub struct RenderConfigId(u32);
#[derive(Default)] #[derive(Default)]
pub struct RenderConfig{ pub struct RenderConfig{
texture:Option<TextureId>, pub texture:Option<TextureId>,
} }
impl RenderConfig{ impl RenderConfig{
pub const fn texture(texture:TextureId)->Self{ pub const fn texture(texture:TextureId)->Self{
@ -67,7 +90,7 @@ impl RenderConfig{
} }
pub struct IndexedGraphicsGroup{ pub struct IndexedGraphicsGroup{
//Render pattern material/texture/shader/flat color //Render pattern material/texture/shader/flat color
pub render:RenderGroupId, pub render:RenderConfigId,
pub groups:Vec<PolygonGroupId>, pub groups:Vec<PolygonGroupId>,
} }
#[derive(Default)] #[derive(Default)]
@ -77,8 +100,8 @@ pub struct IndexedPhysicsGroup{
} }
//This is a superset of PhysicsModel and GraphicsModel //This is a superset of PhysicsModel and GraphicsModel
#[derive(Clone,Copy,Hash,id::Id,Eq,PartialEq)] #[derive(Clone,Copy,Hash,id::Id,Eq,PartialEq)]
pub struct IndexedModelId(u32); pub struct MeshId(u32);
pub struct IndexedModel{ pub struct Mesh{
pub unique_pos:Vec<Planar64Vec3>,//Unit32Vec3 pub unique_pos:Vec<Planar64Vec3>,//Unit32Vec3
pub unique_normal:Vec<Planar64Vec3>,//Unit32Vec3 pub unique_normal:Vec<Planar64Vec3>,//Unit32Vec3
pub unique_tex:Vec<TextureCoordinate>, pub unique_tex:Vec<TextureCoordinate>,
@ -95,7 +118,7 @@ pub struct IndexedModel{
#[derive(Debug,Clone,Copy,Hash,id::Id,Eq,PartialEq)] #[derive(Debug,Clone,Copy,Hash,id::Id,Eq,PartialEq)]
pub struct ModelId(u32); pub struct ModelId(u32);
pub struct Model{ pub struct Model{
pub model:IndexedModelId, pub mesh:MeshId,
pub attributes:gameplay_attributes::CollisionAttributesId, pub attributes:gameplay_attributes::CollisionAttributesId,
pub color:Color4,//transparency is in here pub color:Color4,//transparency is in here
pub transform:Planar64Affine3, pub transform:Planar64Affine3,