From ece39718f62bcbea827fd7c425aa435401b0acca Mon Sep 17 00:00:00 2001 From: Charles Bournhonesque Date: Wed, 31 Jan 2024 22:00:43 -0500 Subject: [PATCH] Adding derive Reflect for tick structs (#11641) # Objective - Deriving `Reflect` for some public ChangeDetection/Tick structs in bevy_ecs --------- Co-authored-by: Charles Bournhonesque --- crates/bevy_core/src/lib.rs | 11 ++++++++++- crates/bevy_ecs/src/component.rs | 10 +++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/crates/bevy_core/src/lib.rs b/crates/bevy_core/src/lib.rs index 5c669186d79345..708b006d7d293e 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>() diff --git a/crates/bevy_ecs/src/component.rs b/crates/bevy_ecs/src/component.rs index e017ea4f5498a6..e8a16aba64d106 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, @@ -286,7 +287,8 @@ 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)] +#[reflect(Debug, Hash, PartialEq)] pub struct ComponentId(usize); impl ComponentId { @@ -669,7 +671,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)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, Reflect)] +#[reflect(Debug, PartialEq)] pub struct Tick { tick: u32, } @@ -762,7 +765,8 @@ 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)] +#[reflect(Debug)] pub struct ComponentTicks { pub(crate) added: Tick, pub(crate) changed: Tick,