diff --git a/src/l2/alice/engine.h b/src/l2/alice/engine.h index b9d03e5..3048372 100644 --- a/src/l2/alice/engine.h +++ b/src/l2/alice/engine.h @@ -1060,6 +1060,7 @@ void alice_frame_drawing(Alice* alice) { Plain2dShapeRenderer_clear(&alice->plain_shape_renderer); LucyRenderer_clear(&alice->lucy_renderer); + // todo: WARNING. THIS IS VERY BAD. Please, consider fixing this shitcode if (!alice->transfer_command_buf_already_reset) { Abigail_wipe_old_staging(&alice->abigail, alice->device, alice->staging_buffers); margaret_reset_and_begin_command_buffer(alice->transfer_command_buf); diff --git a/src/l2/alice/transfer_in_mainloop.h b/src/l2/alice/transfer_in_mainloop.h index 1b6dc14..ccbb231 100644 --- a/src/l2/alice/transfer_in_mainloop.h +++ b/src/l2/alice/transfer_in_mainloop.h @@ -21,7 +21,7 @@ typedef struct { /* You know the deal, the buffer, returned in ret_dev_local_buf, cannot be deleted in the same `_another_frame` * callback as this function was called. And it should be obvious that this function can only be called when the * frame is not in flight. And ret_mapped_staging region is guaranteed to be len bytes long, also, it cannot be - * used when current init/another_frame phase is over + * used when current init/another_frame phase isn't over */ MargaretSubbuf /* ret_dev_local_buf */ Abigail_register_new_buffer(Abigail* self, U64 len, VkCommandBuffer transfer_cmd_buffer, MargaretBufAllocator* staging_buffers, MargaretBufAllocator* dev_local_buffers, @@ -37,10 +37,10 @@ MargaretSubbuf /* ret_dev_local_buf */ Abigail_register_new_buffer(Abigail* self /* Same deal as Abigail_register_new_buffer, but for textures. I say textures, because returned object also includes * VkImageView, created for this image. - * Returned device localimage cannot be deleted in the same 'no-frame-in-flight' stage. We have to wait for it + * Returned device local image cannot be deleted in the same 'no-frame-in-flight' stage. We have to wait for it * to undergo copying, only then, on another frame, can you delete it. ret_mapped_staging points to staging buffer, * it is a memory region of width * height * pixed_sz bytes long. Here pixel_sz is a size of pixel in image of format - * `foramt`. This memory can only be edited in the same `on-another-frame` phrase where it was given. But not later + * `format`. This memory can only be edited in the same `on-another-frame` phrase where it was given. But not later */ MargaretTexture /* ret_dev_local_texture */ Abigail_register_new_texture(Abigail* self, U64 width, U64 height, U64 pixel_sz, VkFormat format, VkImageUsageFlags usage, diff --git a/src/l2/allie_rs/allie.rs b/src/l2/allie_rs/allie.rs index 08386e4..28ae577 100644 --- a/src/l2/allie_rs/allie.rs +++ b/src/l2/allie_rs/allie.rs @@ -7,18 +7,13 @@ use libc::{calloc, free}; use std::mem::size_of; use std::marker::PhantomData; use crate::uint_segments::{*}; +use crate::assets::{GenericMeshVertexInc}; /* usize is u64, ok? */ -// fn safe_calloc(nobj: usize, size: usize) -> *mut c_void{ -// let p = unsafe { calloc(nobj, size) }; -// if (p.is_null()){ panic!("calloc: Not enough memory\n") } -// p -// } - fn safe_calloc(nobj: usize) ->* mut T { - let p = unsafe { calloc(nobj, size_of::()) }; - if (p.is_null()){ panic!("calloc: Not enough memory\n") } - p as *mut T + let p = unsafe { calloc(nobj, size_of::()) }; + if (p.is_null()){ panic!("calloc: Not enough memory\n") } + p as *mut T } pub type Alice = *mut c_void; @@ -79,6 +74,14 @@ pub struct LucyGlyphCachingRequest<'a> { /* Copying from Rust analog type to C allie type will be implemented outside */ +#[repr(C)] +struct GenericMeshTopology { + vertices: CVec, + indexes: CVec, +} + + + #[repr(C)] pub struct AliceCallbacks { pub guest: Alice, @@ -106,8 +109,10 @@ unsafe extern "C" { pub fn Alice_lucy_cache_add_glyphs(alice: Alice, req: CVec); #[link_name="Alice_lucy_renderer_add_simple_label"] pub fn Alice_lucy_renderer_add_simple_label( /* todo: make color cvec4 */ - alice: Alice, ffs: LucyFaceFixedSize, + alice: Alice, ffs: LucyFaceFixedSize, color: vec4, additional_y_advance: i32, text: CSpan, start_pos: ivec2); + + pub fn alice_expect_read_generic_mesh_from_file(file_path: CVec); } pub extern "C" fn AliceCallbacks_on_wl_pointer_button(dt: Alice, button: u32, act: u32){ diff --git a/src/l2/allie_rs/assets.rs b/src/l2/allie_rs/assets.rs new file mode 100644 index 0000000..5a5edb1 --- /dev/null +++ b/src/l2/allie_rs/assets.rs @@ -0,0 +1,19 @@ +use crate::geom::{vec2, vec3, cvec4}; + +#[repr(C)] +#[derive(Clone, Copy)] +pub struct GenericMeshVertexInc { + pub pos: vec3, + pub text: vec3, +} + +pub struct GenericMeshTopology { + vertices: Vec, + indexed: Vec, +} + +// struct { +// mat4 model_t; +// } GenericMeshInstanceInc; + +// normies aren't ready for matrices yet \ No newline at end of file diff --git a/src/l2/allie_rs/geom.rs b/src/l2/allie_rs/geom.rs index 82aba30..a0b9041 100644 --- a/src/l2/allie_rs/geom.rs +++ b/src/l2/allie_rs/geom.rs @@ -1,5 +1,5 @@ use super::int_primitives::{*}; -use std::ops::{Add, Sub, Mul, Div}; +use std::ops::{Add, Sub, Mul, Div, Neg}; use std::array; pub struct Assert; @@ -12,9 +12,7 @@ impl AssertTrue for Assert{} #[derive(Clone, Copy, Debug)] pub struct GeomVec (pub [T; N]) where T: Copy + Clone; -impl Add for GeomVec where - T: SignedNumber -{ +impl Add for GeomVec { type Output = GeomVec; fn add(self, rhs: Self) -> Self::Output { @@ -22,6 +20,39 @@ impl Add for GeomVec where } } +impl Sub for GeomVec { + type Output = GeomVec; + + fn sub(self, rhs: Self) -> Self::Output { + GeomVec(array::from_fn(|i| self.0[i] - rhs.0[i])) + } +} + +impl Neg for GeomVec { + type Output = GeomVec; + + fn neg(self) -> Self::Output { + GeomVec(array::from_fn(|i| -self.0[i])) + } +} + + +impl Mul for GeomVec { + type Output = GeomVec; + + fn mul(self, rhs: Self) -> Self::Output { + GeomVec(array::from_fn(|i| self.0[i] * rhs.0[i])) + } +} + +impl Mul for GeomVec { + type Output = GeomVec; + + fn mul(self, rhs: T) -> Self::Output { + GeomVec(array::from_fn(|i| self.0[i] * rhs)) + } +} + impl GeomVec where T: Copy + Clone, Assert<{N >= 1}> : AssertTrue { @@ -112,4 +143,53 @@ pub const fn cvec3(x: u8, y: u8, z: u8) -> cvec3 { pub const fn cvec4(x: u8, y: u8, z: u8, w: u8) -> cvec4 { GeomVec([x, y, z, w]) -} \ No newline at end of file +} + + + +/* Turn out for tuple struct, where clause goes after the field list */ +#[repr(C)] +#[derive(Clone, Copy, Debug)] +pub struct GeomMat (pub [GeomVec; N]); + +impl Add for GeomMat { + type Output = Self; + + fn add(self, rhs: Self) -> Self::Output { + GeomMat(array::from_fn(|i| self.0[i] + rhs.0[i])) + } +} + +impl Sub for GeomMat { + type Output = Self; + + fn sub(self, rhs: Self) -> Self::Output { + GeomMat(array::from_fn(|i| self.0[i] - rhs.0[i])) + } +} + +impl Neg for GeomMat { + type Output = Self; + + fn neg(self) -> Self::Output { + GeomMat(array::from_fn(|i| -self.0[i])) + } +} + + +impl + Mul> for GeomMat { + type Output = GeomMat; + + fn mul(self, rhs: GeomMat) -> Self::Output { + GeomMat(array::from_fn(|x| { + GeomVec(array::from_fn(|y| { + (0..K).fold(T::ZERO, |acc: T, k| acc + self.0[k].0[y] * self.0[x].0[k] ) + })) + })) + } +} + +pub type mat2 = GeomMat; +pub type mat3 = GeomMat; +pub type mat4 = GeomMat; \ No newline at end of file diff --git a/src/l2/allie_rs/int_primitives.rs b/src/l2/allie_rs/int_primitives.rs index e44a110..37fee56 100644 --- a/src/l2/allie_rs/int_primitives.rs +++ b/src/l2/allie_rs/int_primitives.rs @@ -1,7 +1,8 @@ -use std::ops::{Add, Sub, Mul, Div}; +use std::ops::{Add, Sub, Mul, Div, Neg}; pub trait SignedNumber: Copy + Clone + Add + + Neg + Sub + Mul { diff --git a/src/l2/allie_rs/lib.rs b/src/l2/allie_rs/lib.rs index a371be8..4862330 100644 --- a/src/l2/allie_rs/lib.rs +++ b/src/l2/allie_rs/lib.rs @@ -12,3 +12,4 @@ pub mod int_primitives; mod allie; pub mod alice; pub mod uint_segments; +pub mod assets;