diff --git a/Cargo.lock b/Cargo.lock index 23b4eda..ae15851 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -264,10 +264,23 @@ version = "0.1.0" dependencies = [ "anyhow", "image", + "lithium-loader", + "slab", "thiserror", "tokio", ] +[[package]] +name = "lithium-loader" +version = "0.1.0" +dependencies = [ + "lithium-utils", +] + +[[package]] +name = "lithium-utils" +version = "0.1.0" + [[package]] name = "lock_api" version = "0.4.11" @@ -436,6 +449,15 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + [[package]] name = "smallvec" version = "1.11.2" diff --git a/Cargo.toml b/Cargo.toml index e8851c3..9438b0d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,10 @@ authors = ["antifallobst"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +lithium-loader = { path = "lithium-loader" } + anyhow = "1.0.75" thiserror = "1.0.50" tokio = { version = "1.34.0", features = ["rt-multi-thread", "sync", "macros"] } -image = "0.24.7" \ No newline at end of file +image = "0.24.7" +slab = "0.4.9" diff --git a/lithium-loader/Cargo.lock b/lithium-loader/Cargo.lock index 3288c74..6e5c32a 100644 --- a/lithium-loader/Cargo.lock +++ b/lithium-loader/Cargo.lock @@ -5,3 +5,10 @@ version = 3 [[package]] name = "lithium-loader" version = "0.1.0" +dependencies = [ + "lithium-utils", +] + +[[package]] +name = "lithium-utils" +version = "0.1.0" diff --git a/lithium-loader/Cargo.toml b/lithium-loader/Cargo.toml index d01e847..6d0d3bb 100644 --- a/lithium-loader/Cargo.toml +++ b/lithium-loader/Cargo.toml @@ -2,7 +2,10 @@ name = "lithium-loader" version = "0.1.0" edition = "2021" +license = "MIT" +authors = ["antifallobst"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +lithium-utils = { path = "../lithium-utils" } \ No newline at end of file diff --git a/lithium-loader/src/lib.rs b/lithium-loader/src/lib.rs index 7d12d9a..e3f08a3 100644 --- a/lithium-loader/src/lib.rs +++ b/lithium-loader/src/lib.rs @@ -1,14 +1,40 @@ -pub fn add(left: usize, right: usize) -> usize { - left + right +use lithium_utils::{Vector2, Vector3, Vertex}; + +pub struct Model { + name: String, + + sub_models: Vec, + vertices: Vec, + faces: Vec<(u32, u32, u32)>, } -#[cfg(test)] -mod tests { - use super::*; +impl Model { + pub fn test() -> Self { + let vertices = vec![ + Vertex::new( + Vector3::new(0_f32, 0_f32, 0_f32), + Vector2::default(), + Vector3::default(), + ), + Vertex::new( + Vector3::new(0.5_f32, 1_f32, 0_f32), + Vector2::default(), + Vector3::default(), + ), + Vertex::new( + Vector3::new(1_f32, 0_f32, 0_f32), + Vector2::default(), + Vector3::default(), + ), + ]; - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); + let faces = vec![(0, 1, 2)]; + + Self { + name: "Test".to_string(), + sub_models: Vec::new(), + vertices, + faces, + } } } diff --git a/lithium-utils/.gitignore b/lithium-utils/.gitignore new file mode 100644 index 0000000..c41cc9e --- /dev/null +++ b/lithium-utils/.gitignore @@ -0,0 +1 @@ +/target \ No newline at end of file diff --git a/lithium-utils/Cargo.lock b/lithium-utils/Cargo.lock new file mode 100644 index 0000000..195b822 --- /dev/null +++ b/lithium-utils/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "lithium-utils" +version = "0.1.0" diff --git a/lithium-utils/Cargo.toml b/lithium-utils/Cargo.toml new file mode 100644 index 0000000..eab9e10 --- /dev/null +++ b/lithium-utils/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "lithium-utils" +version = "0.1.0" +edition = "2021" +license = "MIT" +authors = ["antifallobst"] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/lithium-utils/src/lib.rs b/lithium-utils/src/lib.rs new file mode 100644 index 0000000..9b402af --- /dev/null +++ b/lithium-utils/src/lib.rs @@ -0,0 +1,54 @@ +pub struct Vector2 { + x: f32, + y: f32, +} + +impl Default for Vector3 { + fn default() -> Self { + Self { + x: 0_f32, + y: 0_f32, + z: 0_f32, + } + } +} + +impl Vector2 { + pub fn new(x: f32, y: f32) -> Self { + Self { x, y } + } +} + +pub struct Vector3 { + x: f32, + y: f32, + z: f32, +} + +impl Default for Vector2 { + fn default() -> Self { + Self { x: 0_f32, y: 0_f32 } + } +} + +impl Vector3 { + pub fn new(x: f32, y: f32, z: f32) -> Self { + Self { x, y, z } + } +} + +pub struct Vertex { + position: Vector3, + uv: Vector2, + normal: Vector3, +} + +impl Vertex { + pub fn new(position: Vector3, uv: Vector2, normal: Vector3) -> Self { + Self { + position, + uv, + normal, + } + } +} diff --git a/src/render/coords.rs b/src/render/coords.rs deleted file mode 100644 index cf9b55d..0000000 --- a/src/render/coords.rs +++ /dev/null @@ -1,11 +0,0 @@ -pub struct Coords3d { - x: f32, - y: f32, - z: f32, -} - -impl Coords3d { - pub fn new(x: f32, y: f32, z: f32) -> Self { - Self { x, y, z } - } -} diff --git a/src/render/mod.rs b/src/render/mod.rs index 5b7475b..2df4884 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -1,38 +1,25 @@ pub mod camera; -pub mod coords; -mod vertex; use crate::output::Output; use crate::render::camera::Camera; -use crate::render::coords::Coords3d; -use crate::render::vertex::Vertex; + +use lithium_loader::Model; use slab::Slab; pub struct Renderer { - cameras: Vec, - vertices: Vec, - - vertex_id: u32, + cameras: Slab, + models: Slab, } impl Renderer { pub fn new() -> Self { Self { - cameras: Vec::new(), - vertices: Vec::new(), - vertex_id: 0, + cameras: Slab::new(), + models: Slab::new(), } } - pub fn add_vertex(&mut self, position: Coords3d) -> u32 { - let id = self.vertex_id; - self.vertex_id = self.vertex_id + 1; - - self.vertices.push(Vertex::new(id, position)); - id - } - - pub fn add_camera(&mut self, output: impl Output + 'static) { - self.cameras.push(Camera::new(output)) + pub fn add_camera(&mut self, output: impl Output + 'static) -> usize { + self.cameras.insert(Camera::new(output)) } } diff --git a/src/render/vertex.rs b/src/render/vertex.rs deleted file mode 100644 index c3e9194..0000000 --- a/src/render/vertex.rs +++ /dev/null @@ -1,12 +0,0 @@ -use crate::render::coords::Coords3d; - -pub struct Vertex { - id: u32, - position: Coords3d, -} - -impl Vertex { - pub fn new(id: u32, position: Coords3d) -> Self { - Self { id, position } - } -}