oh my god it compiles. A month of brainstorming comes out to a single enum

This commit is contained in:
2020-02-06 23:38:28 -08:00
parent 1597f0e380
commit cd0c1e6052
4 changed files with 148 additions and 56 deletions

View File

@@ -1,4 +1,4 @@
use crate::util::vertex_3d::{Vertex3D};
use crate::util::vertex_3d::Vertex3D;
use std::sync::Arc;
use std::collections::HashMap;
use std::hash::Hash;
@@ -7,63 +7,95 @@ use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef;
use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle, Handle};
use crate::canvas::managed::shader::text_shader::GlyphInstance;
use vulkano::pipeline::vertex::Vertex;
use std::any::Any;
// I don't think this is going to work without getting into Box'ing
pub trait DrawableTest<V, H> where H: Handle{
pub trait DrawableTest<V, H> where H: Handle {
fn get_vertices(&self) -> Vec<V>;
fn get_handle(&self) -> H;
}
pub struct DrawableTestee {
pub vertices: Vec<ImplVertexData>,
pub handle: Arc<CanvasTextureHandle>
}
impl<V, H: Handle> DrawableTest<V, H> for DrawableTestee {
fn get_vertices(&self) -> Vec<V> {
unimplemented!()
mod dynhash {
use std::any::Any;
use std::hash::{Hash, Hasher};
pub trait DynEq: Any {
fn dyn_eq(&self, other: &dyn DynEq) -> bool;
fn as_any(&self) -> &dyn Any;
}
fn get_handle(&self) -> H {
unimplemented!()
pub trait DynHash: DynEq {
fn dyn_hash(&self, hasher: &mut dyn Hasher);
fn as_dyn_eq(&self) -> &dyn DynEq;
}
impl<H: Eq + Any> DynEq for H {
fn dyn_eq(&self, other: &dyn DynEq) -> bool {
if let Some(other) = other.as_any().downcast_ref::<H>() {
self == other
} else {
false
}
}
fn as_any(&self) -> &dyn Any {
self
}
}
impl<H: Hash + DynEq> DynHash for H {
fn dyn_hash(&self, mut hasher: &mut dyn Hasher) {
H::hash(self, &mut hasher)
}
fn as_dyn_eq(&self) -> &dyn DynEq {
self
}
}
impl PartialEq for dyn DynHash {
fn eq(&self, other: &dyn DynHash) -> bool {
self.dyn_eq(other.as_dyn_eq())
}
}
impl Eq for dyn DynHash {}
impl Hash for dyn DynHash {
fn hash<H: Hasher>(&self, hasher: &mut H) {
self.dyn_hash(hasher)
}
}
}
use crate::canvas::canvas_frame::dynhash::DynHash;
pub struct ImplVertexData {
pub x: i32,
pub y: i32,
}
impl VertexData for ImplVertexData {
}
pub trait VertexData : Sized {
}
// CanvasFrameTest will be drawn to by objects implementing DrawableTest
pub struct CanvasFrameTest<V: VertexData + Sized, H: Handle + Sized> {
pub map: HashMap<H, Vec<V>>,
pub struct CanvasFrameTest<VTypes> {
pub map: HashMap<Box<dyn DynHash>, Vec<VTypes>>,
}
impl<V: VertexData + Sized, H: Handle + Sized + Eq + Hash> CanvasFrameTest<V, H> {
pub fn draw(&mut self, drawable: &dyn DrawableTest<V, H>) {
drawable.get_vertices();
self.map.insert(drawable.get_handle(), drawable.get_vertices());
impl<VTypes> CanvasFrameTest<VTypes> {
pub fn draw(&mut self, drawable: Vec<VTypes>) {
self.map.insert(Box::new(10), drawable);
}
}
pub trait Drawable {
fn get_vertices(&self) -> Vec<(f32, f32, f32)>;
fn get_color(&self) -> (f32, f32, f32, f32);
fn get_ti_coords(&self) -> Vec<(f32, f32)>;
fn get_texture_handle(&self) -> Option<Arc<CanvasTextureHandle>>;
fn get_image_handle(&self) -> Option<Arc<CanvasImageHandle>>;
// fn get_text_handle(&self) -> Option<Arc<CanvasTextHandle>>;
// fn get_text_handle(&self) -> Option<Arc<CanvasTextHandle>>;
// These needs to return a vector of raw-ass data in addition to the definition for this data
fn collect(&self) -> Vec<RuntimeVertexDef> {
@@ -74,36 +106,30 @@ pub trait Drawable {
// color: [color.0, color.1, color.2, color.3],
// ti_position: [b.0, b.1],
// }).collect()
// TODO
// TODO
vec![RuntimeVertexDef::from_primitive(0)]
}
}
pub trait VertexDefinitionAndData {
}
pub trait VertexDefinitionAndData {}
pub struct CanvasFrame {
pub colored_drawables: Vec<RuntimeVertexDef>,
pub textured_drawables: HashMap<Arc<CanvasTextureHandle>, Vec<Vec<RuntimeVertexDef>>>,
pub image_drawables: HashMap<Arc<CanvasImageHandle>, Vec<Vec<RuntimeVertexDef>>>,
pub text_drawables: HashMap<Arc<CanvasFontHandle>, Vec<GlyphInstance>>
pub text_drawables: HashMap<Arc<CanvasFontHandle>, Vec<GlyphInstance>>,
}
impl CanvasFrame {
/// Creates a bare canvas frame with empty accumulators a
pub fn new() -> CanvasFrame {
CanvasFrame {
colored_drawables: vec![],
textured_drawables: Default::default(),
image_drawables: Default::default(),
text_drawables: Default::default()
text_drawables: Default::default(),
}
}