Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
34 changes: 4 additions & 30 deletions crates/bevy_ecs/src/change_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ pub const CHECK_TICK_THRESHOLD: u32 = 518_400_000;
/// Changes stop being detected once they become this old.
pub const MAX_CHANGE_AGE: u32 = u32::MAX - (2 * CHECK_TICK_THRESHOLD - 1);

pub trait ComponentMut<'a>: DetectChanges {
pub trait ComponentMut<'a> {
type Inner: ?Sized;
const ENABLED: bool;
fn build(
inner: &'a mut Self::Inner,
Expand Down Expand Up @@ -400,6 +401,7 @@ where
}

impl<'a, T> ComponentMut<'a> for Mut<'a, T> {
type Inner = T;
const ENABLED: bool = true;
fn build(
value: &'a mut Self::Inner,
Expand All @@ -424,37 +426,9 @@ change_detection_impl!(Mut<'a, T>, T, true,);
impl_methods!(Mut<'a, T>, T,);
impl_debug!(Mut<'a, T>,);

impl<'a, T: ?Sized> DetectChanges for &'a mut T {
type Inner = T;

#[inline]
fn is_added(&self) -> bool {
true
}

#[inline]
fn is_changed(&self) -> bool {
true
}

#[inline]
fn set_changed(&mut self) {}

#[inline]
fn last_changed(&self) -> u32 {
0
}

#[inline]
fn set_last_changed(&mut self, _last_change_tick: u32) {}

#[inline]
fn bypass_change_detection(&mut self) -> &mut Self::Inner {
self
}
}

impl<'a, T> ComponentMut<'a> for &'a mut T {
type Inner = T;
const ENABLED: bool = false;
fn build(
value: &'a mut Self::Inner,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ use std::{
/// [orphan rule]: https://doc.rust-lang.org/book/ch10-02-traits.html#implementing-a-trait-on-a-type
/// [newtype pattern]: https://doc.rust-lang.org/book/ch19-03-advanced-traits.html#using-the-newtype-pattern-to-implement-external-traits-on-external-types
pub trait Component: Send + Sync + 'static {
type WriteFetch<'a>: ComponentMut<'a> + DetectChanges<Inner = Self> + DerefMut<Target = Self>;
type WriteFetch<'a>: ComponentMut<'a, Inner = Self> + DerefMut<Target = Self>;
type Storage: ComponentStorage;

fn shrink<'wlong: 'wshort, 'wshort>(
Expand Down