From ac6ede3e9474190f1f816bd4c4be7069efb6997a Mon Sep 17 00:00:00 2001 From: Charles Bournhonesque Date: Wed, 31 Jan 2024 20:15:52 -0500 Subject: [PATCH 1/6] derive Reflect for tick structs --- crates/bevy_ecs/src/component.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/bevy_ecs/src/component.rs b/crates/bevy_ecs/src/component.rs index e017ea4f5498a..e4fd87af3f483 100644 --- a/crates/bevy_ecs/src/component.rs +++ b/crates/bevy_ecs/src/component.rs @@ -18,6 +18,7 @@ use std::{ marker::PhantomData, mem::needs_drop, }; +use bevy_reflect::Reflect; /// A data type that can be used to store data for an [entity]. /// @@ -669,7 +670,7 @@ impl Components { /// A value that tracks when a system ran relative to other systems. /// This is used to power change detection. -#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, Reflect)] pub struct Tick { tick: u32, } From f03ee114b4bf77f499c0895a8649b85b792238cf Mon Sep 17 00:00:00 2001 From: Charles Bournhonesque Date: Wed, 31 Jan 2024 20:16:52 -0500 Subject: [PATCH 2/6] add more reflects --- crates/bevy_ecs/src/component.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_ecs/src/component.rs b/crates/bevy_ecs/src/component.rs index e4fd87af3f483..7950982794b7f 100644 --- a/crates/bevy_ecs/src/component.rs +++ b/crates/bevy_ecs/src/component.rs @@ -287,7 +287,7 @@ impl ComponentInfo { /// Given a type `T` which implements [`Component`], the `ComponentId` for `T` can be retrieved /// from a `World` using [`World::component_id()`] or via [`Components::component_id()`]. Access /// to the `ComponentId` for a [`Resource`] is available via [`Components::resource_id()`]. -#[derive(Debug, Copy, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)] +#[derive(Debug, Copy, Clone, Hash, Ord, PartialOrd, Eq, PartialEq, Reflect)] pub struct ComponentId(usize); impl ComponentId { @@ -763,7 +763,7 @@ impl<'a> TickCells<'a> { } /// Records when a component was added and when it was last mutably dereferenced (or added). -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, Reflect)] pub struct ComponentTicks { pub(crate) added: Tick, pub(crate) changed: Tick, From ee686a176d48076612fd5f385695d9d12bd2c163 Mon Sep 17 00:00:00 2001 From: Charles Bournhonesque Date: Wed, 31 Jan 2024 20:18:33 -0500 Subject: [PATCH 3/6] fmt --- crates/bevy_ecs/src/component.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ecs/src/component.rs b/crates/bevy_ecs/src/component.rs index 7950982794b7f..1801369d64290 100644 --- a/crates/bevy_ecs/src/component.rs +++ b/crates/bevy_ecs/src/component.rs @@ -10,6 +10,7 @@ use crate::{ }; pub use bevy_ecs_macros::Component; use bevy_ptr::{OwningPtr, UnsafeCellDeref}; +use bevy_reflect::Reflect; use std::cell::UnsafeCell; use std::{ alloc::Layout, @@ -18,7 +19,6 @@ use std::{ marker::PhantomData, mem::needs_drop, }; -use bevy_reflect::Reflect; /// A data type that can be used to store data for an [entity]. /// From 98eb828cad87cf19bab9fb7a450277baf02f1ffd Mon Sep 17 00:00:00 2001 From: Charles Bournhonesque Date: Wed, 31 Jan 2024 21:43:35 -0500 Subject: [PATCH 4/6] add reflect attribute --- crates/bevy_ecs/src/component.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/bevy_ecs/src/component.rs b/crates/bevy_ecs/src/component.rs index 1801369d64290..e8a16aba64d10 100644 --- a/crates/bevy_ecs/src/component.rs +++ b/crates/bevy_ecs/src/component.rs @@ -288,6 +288,7 @@ impl ComponentInfo { /// from a `World` using [`World::component_id()`] or via [`Components::component_id()`]. Access /// to the `ComponentId` for a [`Resource`] is available via [`Components::resource_id()`]. #[derive(Debug, Copy, Clone, Hash, Ord, PartialOrd, Eq, PartialEq, Reflect)] +#[reflect(Debug, Hash, PartialEq)] pub struct ComponentId(usize); impl ComponentId { @@ -671,6 +672,7 @@ impl Components { /// A value that tracks when a system ran relative to other systems. /// This is used to power change detection. #[derive(Copy, Clone, Debug, Eq, PartialEq, Reflect)] +#[reflect(Debug, PartialEq)] pub struct Tick { tick: u32, } @@ -764,6 +766,7 @@ impl<'a> TickCells<'a> { /// Records when a component was added and when it was last mutably dereferenced (or added). #[derive(Copy, Clone, Debug, Reflect)] +#[reflect(Debug)] pub struct ComponentTicks { pub(crate) added: Tick, pub(crate) changed: Tick, From 63151fc4b81148980e04ba857510d50d5563fc30 Mon Sep 17 00:00:00 2001 From: Charles Bournhonesque Date: Wed, 31 Jan 2024 21:47:10 -0500 Subject: [PATCH 5/6] register the types --- crates/bevy_core/src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/bevy_core/src/lib.rs b/crates/bevy_core/src/lib.rs index 5c669186d7934..708b006d7d293 100644 --- a/crates/bevy_core/src/lib.rs +++ b/crates/bevy_core/src/lib.rs @@ -21,6 +21,7 @@ pub mod prelude { } use bevy_app::prelude::*; +use bevy_ecs::component::{ComponentId, ComponentTicks, Tick}; use bevy_ecs::prelude::*; use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; use bevy_utils::{Duration, HashSet, Instant, Uuid}; @@ -40,13 +41,21 @@ pub struct TypeRegistrationPlugin; impl Plugin for TypeRegistrationPlugin { fn build(&self, app: &mut App) { - app.register_type::().register_type::(); + app.register_type::(); + register_ecs_types(app); register_rust_types(app); register_math_types(app); } } +fn register_ecs_types(app: &mut App) { + app.register_type::() + .register_type::() + .register_type::() + .register_type::(); +} + fn register_rust_types(app: &mut App) { app.register_type::>() .register_type_data::, ReflectSerialize>() From 97bcad040ddd290a6cdabf70c0fe092670aa8b50 Mon Sep 17 00:00:00 2001 From: Charles Bournhonesque Date: Wed, 31 Jan 2024 22:11:52 -0500 Subject: [PATCH 6/6] feature gate reflect derives --- crates/bevy_ecs/src/component.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/crates/bevy_ecs/src/component.rs b/crates/bevy_ecs/src/component.rs index e8a16aba64d10..cae48be957bd0 100644 --- a/crates/bevy_ecs/src/component.rs +++ b/crates/bevy_ecs/src/component.rs @@ -10,6 +10,7 @@ use crate::{ }; pub use bevy_ecs_macros::Component; use bevy_ptr::{OwningPtr, UnsafeCellDeref}; +#[cfg(feature = "bevy_reflect")] use bevy_reflect::Reflect; use std::cell::UnsafeCell; use std::{ @@ -287,8 +288,12 @@ impl ComponentInfo { /// Given a type `T` which implements [`Component`], the `ComponentId` for `T` can be retrieved /// from a `World` using [`World::component_id()`] or via [`Components::component_id()`]. Access /// to the `ComponentId` for a [`Resource`] is available via [`Components::resource_id()`]. -#[derive(Debug, Copy, Clone, Hash, Ord, PartialOrd, Eq, PartialEq, Reflect)] -#[reflect(Debug, Hash, PartialEq)] +#[derive(Debug, Copy, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)] +#[cfg_attr( + feature = "bevy_reflect", + derive(Reflect), + reflect(Debug, Hash, PartialEq) +)] pub struct ComponentId(usize); impl ComponentId { @@ -671,8 +676,8 @@ impl Components { /// A value that tracks when a system ran relative to other systems. /// This is used to power change detection. -#[derive(Copy, Clone, Debug, Eq, PartialEq, Reflect)] -#[reflect(Debug, PartialEq)] +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug, PartialEq))] pub struct Tick { tick: u32, } @@ -765,8 +770,8 @@ impl<'a> TickCells<'a> { } /// Records when a component was added and when it was last mutably dereferenced (or added). -#[derive(Copy, Clone, Debug, Reflect)] -#[reflect(Debug)] +#[derive(Copy, Clone, Debug)] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug))] pub struct ComponentTicks { pub(crate) added: Tick, pub(crate) changed: Tick,