diff --git a/Cargo.toml b/Cargo.toml index 3c78cd4..26130b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,6 @@ rfactor_sm_reader = { git = "https://gavania.de/hodasemi/rfactor_sm_reader.git" ui = { git = "https://gavania.de/hodasemi/ui.git" } anyhow = { version = "1.0.68", features = ["backtrace"] } -safer-ffi = { version = "0.0.10", features = ["proc_macros"] } paste = "1.0.11" serde = "1.0.152" serde_json = "1.0.91" diff --git a/src/overlay/elements/leaderboard/bg_generator.rs b/src/overlay/elements/leaderboard/bg_generator.rs index c9860d8..b4ffb6c 100644 --- a/src/overlay/elements/leaderboard/bg_generator.rs +++ b/src/overlay/elements/leaderboard/bg_generator.rs @@ -7,7 +7,7 @@ use std::{ time::Duration, }; -use crate::overlay::elements::PositionOnlyVertex; +use crate::overlay::elements::{ColorBuffer, PositionOnlyVertex}; pub struct BackgroundGenerator; @@ -107,7 +107,7 @@ impl BackgroundGenerator { let color_buffer = Buffer::builder() .set_usage(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT) .set_memory_usage(MemoryUsage::CpuOnly) - .set_data(&color) + .set_data(&ColorBuffer::from_array(color)) .build(device.clone())?; let desc_pool = DescriptorPool::builder() diff --git a/src/overlay/elements/mod.rs b/src/overlay/elements/mod.rs index 4bcc077..32218cd 100644 --- a/src/overlay/elements/mod.rs +++ b/src/overlay/elements/mod.rs @@ -6,18 +6,36 @@ mod watermark; pub use leaderboard::*; pub use pedals::*; pub use radar::*; +use utilities::impl_reprc; pub use watermark::*; use std::mem; use vulkan_rs::prelude::*; -#[derive_ReprC] -#[repr(C)] -#[derive(Clone)] -pub struct PositionOnlyVertex { - pub position: cgmath::Vector4, +impl_reprc!( + pub struct ColorBuffer { + #[assume_reprc] + c: f32, + } +); + +impl ColorBuffer { + pub fn from_array(a: [f32; N]) -> [Self; N] { + a.into_iter() + .map(|c| Self { c }) + .collect::>() + .try_into() + .unwrap_or_else(|_: Vec| unreachable!("create array from vec from an array")) + } } +impl_reprc!( + pub struct PositionOnlyVertex { + #[assume_reprc] + position: cgmath::Vector4, + } +); + impl PositionOnlyVertex { /// /// corners[0] - bottom left diff --git a/src/overlay/elements/pedals/mod.rs b/src/overlay/elements/pedals/mod.rs index 9114ac8..e5916dc 100644 --- a/src/overlay/elements/pedals/mod.rs +++ b/src/overlay/elements/pedals/mod.rs @@ -10,6 +10,7 @@ use ui::prelude::*; use vulkan_rs::prelude::*; use crate::overlay::{ + elements::ColorBuffer, rfactor_data::{DataReceiver, GamePhase}, UiOverlay, }; @@ -96,10 +97,10 @@ impl Pedals { .set_descriptor_set_count(2) .build(device.clone())?; - let brake_color_buffer: Arc> = Buffer::builder() + let brake_color_buffer = Buffer::builder() .set_usage(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT) .set_memory_usage(MemoryUsage::CpuOnly) - .set_data(&[0.9, 0.0, 0.0, 1.0]) + .set_data(&ColorBuffer::from_array([0.9, 0.0, 0.0, 1.0])) .build(device.clone())?; write_log!("allocate brake descriptor"); @@ -107,10 +108,10 @@ impl Pedals { let brake_descriptor = descriptor_pool.prepare_set().allocate()?; brake_descriptor.update(&[DescriptorWrite::uniform_buffers(0, &[&brake_color_buffer])])?; - let throttle_color_buffer: Arc> = Buffer::builder() + let throttle_color_buffer = Buffer::builder() .set_usage(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT) .set_memory_usage(MemoryUsage::CpuOnly) - .set_data(&[0.0, 0.9, 0.0, 1.0]) + .set_data(&ColorBuffer::from_array([0.0, 0.9, 0.0, 1.0])) .build(device.clone())?; write_log!("allocate throttle descriptor"); diff --git a/src/overlay/elements/radar/mod.rs b/src/overlay/elements/radar/mod.rs index eb685d2..9a2b3b2 100644 --- a/src/overlay/elements/radar/mod.rs +++ b/src/overlay/elements/radar/mod.rs @@ -21,7 +21,7 @@ use crate::{ write_log, }; -use super::PositionOnlyVertex; +use super::{ColorBuffer, PositionOnlyVertex}; fn convert_vec(v: rF2Vec3) -> Vector3 { vec3(v.x as f32, v.y as f32, v.z as f32) @@ -385,7 +385,7 @@ struct RadarObject { descriptor_set: Arc, // uniform buffer - color_buffer: Arc>, + color_buffer: Arc>, // vertex buffer position_buffer: Arc>, @@ -401,7 +401,7 @@ impl RadarObject { let color_buffer = Buffer::builder() .set_usage(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT) .set_memory_usage(MemoryUsage::CpuOnly) - .set_data(&color) + .set_data(&ColorBuffer::from_array(color)) .build(device.clone())?; let position_buffer = Buffer::builder() @@ -445,7 +445,12 @@ impl RadarObject { car_width, car_height, ))?; - self.color_buffer.fill(&color) + self.color_buffer.fill( + &color + .iter() + .map(|&c| ColorBuffer { c }) + .collect::>(), + ) } }