Adding derive Reflect for tick structs (#11641)
# Objective - Deriving `Reflect` for some public ChangeDetection/Tick structs in bevy_ecs --------- Co-authored-by: Charles Bournhonesque <cbournhonesque@snapchat.com>
This commit is contained in:
parent
57c83158bc
commit
e618426faa
@ -21,6 +21,7 @@ pub mod prelude {
|
|||||||
}
|
}
|
||||||
|
|
||||||
use bevy_app::prelude::*;
|
use bevy_app::prelude::*;
|
||||||
|
use bevy_ecs::component::{ComponentId, ComponentTicks, Tick};
|
||||||
use bevy_ecs::prelude::*;
|
use bevy_ecs::prelude::*;
|
||||||
use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
|
use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
|
||||||
use bevy_utils::{Duration, HashSet, Instant, Uuid};
|
use bevy_utils::{Duration, HashSet, Instant, Uuid};
|
||||||
@ -40,13 +41,21 @@ pub struct TypeRegistrationPlugin;
|
|||||||
|
|
||||||
impl Plugin for TypeRegistrationPlugin {
|
impl Plugin for TypeRegistrationPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.register_type::<Entity>().register_type::<Name>();
|
app.register_type::<Name>();
|
||||||
|
|
||||||
|
register_ecs_types(app);
|
||||||
register_rust_types(app);
|
register_rust_types(app);
|
||||||
register_math_types(app);
|
register_math_types(app);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn register_ecs_types(app: &mut App) {
|
||||||
|
app.register_type::<Entity>()
|
||||||
|
.register_type::<ComponentId>()
|
||||||
|
.register_type::<Tick>()
|
||||||
|
.register_type::<ComponentTicks>();
|
||||||
|
}
|
||||||
|
|
||||||
fn register_rust_types(app: &mut App) {
|
fn register_rust_types(app: &mut App) {
|
||||||
app.register_type::<Range<f32>>()
|
app.register_type::<Range<f32>>()
|
||||||
.register_type_data::<Range<f32>, ReflectSerialize>()
|
.register_type_data::<Range<f32>, ReflectSerialize>()
|
||||||
|
|||||||
@ -10,6 +10,8 @@ use crate::{
|
|||||||
};
|
};
|
||||||
pub use bevy_ecs_macros::Component;
|
pub use bevy_ecs_macros::Component;
|
||||||
use bevy_ptr::{OwningPtr, UnsafeCellDeref};
|
use bevy_ptr::{OwningPtr, UnsafeCellDeref};
|
||||||
|
#[cfg(feature = "bevy_reflect")]
|
||||||
|
use bevy_reflect::Reflect;
|
||||||
use std::cell::UnsafeCell;
|
use std::cell::UnsafeCell;
|
||||||
use std::{
|
use std::{
|
||||||
alloc::Layout,
|
alloc::Layout,
|
||||||
@ -287,6 +289,11 @@ impl ComponentInfo {
|
|||||||
/// from a `World` using [`World::component_id()`] or via [`Components::component_id()`]. Access
|
/// 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()`].
|
/// 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)]
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "bevy_reflect",
|
||||||
|
derive(Reflect),
|
||||||
|
reflect(Debug, Hash, PartialEq)
|
||||||
|
)]
|
||||||
pub struct ComponentId(usize);
|
pub struct ComponentId(usize);
|
||||||
|
|
||||||
impl ComponentId {
|
impl ComponentId {
|
||||||
@ -670,6 +677,7 @@ impl Components {
|
|||||||
/// A value that tracks when a system ran relative to other systems.
|
/// A value that tracks when a system ran relative to other systems.
|
||||||
/// This is used to power change detection.
|
/// This is used to power change detection.
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug, PartialEq))]
|
||||||
pub struct Tick {
|
pub struct Tick {
|
||||||
tick: u32,
|
tick: u32,
|
||||||
}
|
}
|
||||||
@ -763,6 +771,7 @@ impl<'a> TickCells<'a> {
|
|||||||
|
|
||||||
/// Records when a component was added and when it was last mutably dereferenced (or added).
|
/// Records when a component was added and when it was last mutably dereferenced (or added).
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug))]
|
||||||
pub struct ComponentTicks {
|
pub struct ComponentTicks {
|
||||||
pub(crate) added: Tick,
|
pub(crate) added: Tick,
|
||||||
pub(crate) changed: Tick,
|
pub(crate) changed: Tick,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user