I just realized my entire library is shit nd I need to rewrite it

This commit is contained in:
Андреев Григорий 2026-04-20 19:06:40 +03:00
parent 2e9e07d568
commit 0258b946bb
7 changed files with 126 additions and 19 deletions

View File

@ -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);

View File

@ -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,

View File

@ -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<T>(nobj: usize) ->* mut T {
let p = unsafe { calloc(nobj, size_of::<T>()) };
if (p.is_null()){ panic!("calloc: Not enough memory\n") }
p as *mut T
let p = unsafe { calloc(nobj, size_of::<T>()) };
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<GenericMeshVertexInc>,
indexes: CVec<u32>,
}
#[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<LucyGlyphCachingRequest>);
#[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<u8>, start_pos: ivec2);
pub fn alice_expect_read_generic_mesh_from_file(file_path: CVec<u8>);
}
pub extern "C" fn AliceCallbacks_on_wl_pointer_button(dt: Alice, button: u32, act: u32){

19
src/l2/allie_rs/assets.rs Normal file
View File

@ -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<GenericMeshVertexInc>,
indexed: Vec<u32>,
}
// struct {
// mat4 model_t;
// } GenericMeshInstanceInc;
// normies aren't ready for matrices yet

View File

@ -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<const COND: bool>;
@ -12,9 +12,7 @@ impl AssertTrue for Assert<true>{}
#[derive(Clone, Copy, Debug)]
pub struct GeomVec<T, const N: usize> (pub [T; N]) where T: Copy + Clone;
impl<T, const N: usize> Add for GeomVec<T, N> where
T: SignedNumber
{
impl<T: SignedNumber, const N: usize> Add for GeomVec<T, N> {
type Output = GeomVec<T, N>;
fn add(self, rhs: Self) -> Self::Output {
@ -22,6 +20,39 @@ impl<T, const N: usize> Add for GeomVec<T, N> where
}
}
impl<T: SignedNumber, const N: usize> Sub for GeomVec<T, N> {
type Output = GeomVec<T, N>;
fn sub(self, rhs: Self) -> Self::Output {
GeomVec(array::from_fn(|i| self.0[i] - rhs.0[i]))
}
}
impl<T: SignedNumber, const N: usize> Neg for GeomVec<T, N> {
type Output = GeomVec<T, N>;
fn neg(self) -> Self::Output {
GeomVec(array::from_fn(|i| -self.0[i]))
}
}
impl<T: SignedNumber, const N: usize> Mul<Self> for GeomVec<T, N> {
type Output = GeomVec<T, N>;
fn mul(self, rhs: Self) -> Self::Output {
GeomVec(array::from_fn(|i| self.0[i] * rhs.0[i]))
}
}
impl<T: SignedNumber, const N: usize> Mul<T> for GeomVec<T, N> {
type Output = GeomVec<T, N>;
fn mul(self, rhs: T) -> Self::Output {
GeomVec(array::from_fn(|i| self.0[i] * rhs))
}
}
impl<T, const N: usize> GeomVec<T, N> 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])
}
}
/* Turn out for tuple struct, where clause goes after the field list */
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct GeomMat<T: Copy + Clone, const N: usize, const M: usize> (pub [GeomVec<T, M>; N]);
impl<T: SignedNumber, const N: usize, const M: usize> Add for GeomMat<T, N, M> {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
GeomMat(array::from_fn(|i| self.0[i] + rhs.0[i]))
}
}
impl<T: SignedNumber, const N: usize, const M: usize> Sub for GeomMat<T, N, M> {
type Output = Self;
fn sub(self, rhs: Self) -> Self::Output {
GeomMat(array::from_fn(|i| self.0[i] - rhs.0[i]))
}
}
impl<T: SignedNumber, const N: usize, const M: usize> Neg for GeomMat<T, N, M> {
type Output = Self;
fn neg(self) -> Self::Output {
GeomMat(array::from_fn(|i| -self.0[i]))
}
}
impl<T: SignedNumber, const N: usize, const M: usize, const K: usize>
Mul<GeomMat<T, N, K>> for GeomMat<T, K, M> {
type Output = GeomMat<T, N, M>;
fn mul(self, rhs: GeomMat<T, N, K>) -> 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<f32, 2, 2>;
pub type mat3 = GeomMat<f32, 3, 3>;
pub type mat4 = GeomMat<f32, 4, 4>;

View File

@ -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<Output = Self> +
Neg<Output = Self> +
Sub<Output = Self> +
Mul<Output = Self>
{

View File

@ -12,3 +12,4 @@ pub mod int_primitives;
mod allie;
pub mod alice;
pub mod uint_segments;
pub mod assets;