summaryrefslogtreecommitdiff
path: root/engine/src
diff options
context:
space:
mode:
Diffstat (limited to 'engine/src')
-rw-r--r--engine/src/reflection.rs43
-rw-r--r--engine/src/renderer/opengl/graphics_mesh.rs6
2 files changed, 38 insertions, 11 deletions
diff --git a/engine/src/reflection.rs b/engine/src/reflection.rs
index 3ce424e..7c5ee5c 100644
--- a/engine/src/reflection.rs
+++ b/engine/src/reflection.rs
@@ -1,5 +1,6 @@
use std::alloc::Layout;
use std::any::{TypeId, type_name};
+use std::fmt::Debug;
pub use engine_macros::Reflection;
@@ -50,7 +51,15 @@ pub struct StructField
pub byte_offset: usize,
pub type_id: TypeId,
pub type_name: &'static str,
- pub reflection: &'static Reflection,
+ pub get_reflection: FnWithDebug<Option<&'static Reflection>>,
+}
+
+impl StructField
+{
+ pub fn reflection(&self) -> Option<&'static Reflection>
+ {
+ self.get_reflection.get()
+ }
}
#[derive(Debug, Clone)]
@@ -157,14 +166,32 @@ impl<T: With> With for &'static [T]
}
}
-// Used by the Reflection derive macro
-#[doc(hidden)]
-pub mod __private
+#[derive(Clone)]
+pub struct FnWithDebug<Value>
{
- pub const fn get_type_reflection<T>() -> &'static super::Reflection
- where
- T: super::With,
+ func: fn() -> Value,
+}
+
+impl<Value> FnWithDebug<Value>
+{
+ pub const fn new(func: fn() -> Value) -> Self
+ {
+ Self { func }
+ }
+
+ pub fn get(&self) -> Value
+ {
+ (self.func)()
+ }
+}
+
+impl<Value: Debug> Debug for FnWithDebug<Value>
+{
+ fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
{
- T::REFLECTION
+ formatter
+ .debug_tuple("FnWithDebug")
+ .field(&self.get())
+ .finish()
}
}
diff --git a/engine/src/renderer/opengl/graphics_mesh.rs b/engine/src/renderer/opengl/graphics_mesh.rs
index 5d081c7..d62cd3e 100644
--- a/engine/src/renderer/opengl/graphics_mesh.rs
+++ b/engine/src/renderer/opengl/graphics_mesh.rs
@@ -105,8 +105,8 @@ impl GraphicsMesh
vertex_arr.set_attrib_format(
current_context,
attrib_index,
- match vertex_subset_field.reflection.reflection {
- Reflection::Literal(_) => {
+ match vertex_subset_field.reflection.reflection() {
+ Some(Reflection::Literal(_)) => {
if vertex_subset_field.reflection.type_id != TypeId::of::<f32>() {
panic!("Unsupported vertex field data type");
}
@@ -118,7 +118,7 @@ impl GraphicsMesh
offset: vertex_subset_field.offset.try_into().unwrap(),
}
}
- Reflection::Array(array_vertex_field) => {
+ Some(Reflection::Array(array_vertex_field)) => {
let Reflection::Literal(array_vertex_field_item) =
array_vertex_field.item_reflection
else {