Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding derive Reflect for tick structs #11641

Merged
merged 6 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion crates/bevy_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -40,13 +41,21 @@ pub struct TypeRegistrationPlugin;

impl Plugin for TypeRegistrationPlugin {
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_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) {
app.register_type::<Range<f32>>()
.register_type_data::<Range<f32>, ReflectSerialize>()
Expand Down
10 changes: 7 additions & 3 deletions crates/bevy_ecs/src/component.rs
Copy link
Member

@MrGVSV MrGVSV Feb 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably also register these types into the App (although I’m not sure if the bevy_ecs has a plugin or anything that would make sense to hold that logic)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, there's no great spot to do this. Maybe bevy_core?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added them in bevy core, seems like a good place for it

Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add the appropriate registrations (e.g. #[reflect(Hash, PartialEq)])?

Same for the other items.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, should i add Clone as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is one for Clone 🤔

#[reflect(Debug, Hash, PartialEq)]
pub struct ComponentId(usize);

impl ComponentId {
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
Expand Down