graphics rewrite
This commit is contained in:
parent
2ee041ff66
commit
a1fa2c2781
12
src/map.rs
12
src/map.rs
@ -1,14 +1,14 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::model;
|
||||
use crate::gameplay_modes;
|
||||
use crate::gameplay_attributes;
|
||||
//this is the current map data loaded in memory
|
||||
pub struct Map{
|
||||
//this is a temporary struct to try to get the code running again
|
||||
//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 indexed_models:HashMap<model::IndexedModelId,model::IndexedModel>,
|
||||
pub models:HashMap<model::ModelId,model::Model>,
|
||||
pub attributes:Vec<gameplay_attributes::CollisionAttributes>,
|
||||
pub meshes:Vec<model::Mesh>,
|
||||
pub models:Vec<model::Model>,
|
||||
//RenderPattern
|
||||
pub textures:Vec<Vec<u8>>,
|
||||
pub render_configs:Vec<model::RenderConfig>,
|
||||
}
|
||||
|
63
src/model.rs
63
src/model.rs
@ -22,41 +22,64 @@ pub struct IndexedVertex{
|
||||
}
|
||||
#[derive(Clone,Copy,Hash,id::Id,PartialEq,Eq)]
|
||||
pub struct VertexId(u32);
|
||||
pub struct IndexedVertexList{
|
||||
vertices:Vec<VertexId>,
|
||||
pub type IndexedVertexList=Vec<VertexId>;
|
||||
pub trait PolygonIter{
|
||||
fn polys(&self)->impl Iterator<Item=&[VertexId]>;
|
||||
}
|
||||
impl IndexedVertexList{
|
||||
pub const fn new(vertices:Vec<VertexId>)->Self{
|
||||
Self{vertices}
|
||||
pub trait MapVertexId{
|
||||
fn map_vertex_id<F:Fn(VertexId)->VertexId>(self,f:F)->Self;
|
||||
}
|
||||
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)]
|
||||
pub struct PolygonGroupId(u32);
|
||||
pub enum PolygonGroup{
|
||||
PolygonList(Vec<IndexedVertexList>),
|
||||
//TriangleStrip(Vec<VertexId>),
|
||||
PolygonList(PolygonList),
|
||||
//TriangleStrip(TriangleStrip),
|
||||
}
|
||||
impl PolygonGroup{
|
||||
pub fn polys(&self)->impl Iterator<Item=&[VertexId]>{
|
||||
impl PolygonIter for PolygonGroup{
|
||||
fn polys(&self)->impl Iterator<Item=&[VertexId]>{
|
||||
match self{
|
||||
PolygonGroup::PolygonList(polys)=>return polys.iter().map(|poly|poly.vertices.as_slice()),
|
||||
//PolygonGroup::TriangleStrip(strip)=>return strip.windows(3).enumerate().map(|(i,s)|if i&0!=0{return s.iter().rev()}else{return s.iter()}),
|
||||
PolygonGroup::PolygonList(list)=>list.polys(),
|
||||
//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{
|
||||
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
|
||||
#[derive(Clone,Copy,Hash,id::Id,Eq,PartialEq)]
|
||||
pub struct RenderGroupId(u32);
|
||||
#[derive(Clone,Copy,Hash,id::Id,Eq,PartialEq)]
|
||||
pub struct TextureId(u32);
|
||||
#[derive(Clone,Copy,Hash,id::Id,Eq,PartialEq)]
|
||||
pub struct RenderConfigId(u32);
|
||||
#[derive(Default)]
|
||||
pub struct RenderConfig{
|
||||
texture:Option<TextureId>,
|
||||
pub texture:Option<TextureId>,
|
||||
}
|
||||
impl RenderConfig{
|
||||
pub const fn texture(texture:TextureId)->Self{
|
||||
@ -67,7 +90,7 @@ impl RenderConfig{
|
||||
}
|
||||
pub struct IndexedGraphicsGroup{
|
||||
//Render pattern material/texture/shader/flat color
|
||||
pub render:RenderGroupId,
|
||||
pub render:RenderConfigId,
|
||||
pub groups:Vec<PolygonGroupId>,
|
||||
}
|
||||
#[derive(Default)]
|
||||
@ -77,8 +100,8 @@ pub struct IndexedPhysicsGroup{
|
||||
}
|
||||
//This is a superset of PhysicsModel and GraphicsModel
|
||||
#[derive(Clone,Copy,Hash,id::Id,Eq,PartialEq)]
|
||||
pub struct IndexedModelId(u32);
|
||||
pub struct IndexedModel{
|
||||
pub struct MeshId(u32);
|
||||
pub struct Mesh{
|
||||
pub unique_pos:Vec<Planar64Vec3>,//Unit32Vec3
|
||||
pub unique_normal:Vec<Planar64Vec3>,//Unit32Vec3
|
||||
pub unique_tex:Vec<TextureCoordinate>,
|
||||
@ -95,7 +118,7 @@ pub struct IndexedModel{
|
||||
#[derive(Debug,Clone,Copy,Hash,id::Id,Eq,PartialEq)]
|
||||
pub struct ModelId(u32);
|
||||
pub struct Model{
|
||||
pub model:IndexedModelId,
|
||||
pub mesh:MeshId,
|
||||
pub attributes:gameplay_attributes::CollisionAttributesId,
|
||||
pub color:Color4,//transparency is in here
|
||||
pub transform:Planar64Affine3,
|
||||
|
Loading…
Reference in New Issue
Block a user