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
121 changes: 57 additions & 64 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ license = "MIT OR Apache-2.0"
repository = "https://github.com/JoJoJet/bevy-trait-query/"

[workspace.dependencies]
bevy_app = { version = "0.18.0" }
bevy_ecs = { version = "0.18.0" }
bevy_app = { git = "https://github.com/bevyengine/bevy.git", rev = "refs/pull/22670/head" }
bevy_ecs = { git = "https://github.com/bevyengine/bevy.git", rev = "refs/pull/22670/head" }
tracing = { version = "0.1.41" }

# proc macro
Expand All @@ -22,5 +22,5 @@ quote = { version = "1.0.42" }
syn = { features = ["full"], version = "2.0.111" }

# dev deps
bevy = { default-features = false, version = "0.18.0" }
bevy = { default-features = false, git = "https://github.com/bevyengine/bevy.git", rev = "refs/pull/22670/head" }
criterion = { version = "0.8.1" }
4 changes: 2 additions & 2 deletions bevy-trait-query-impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ fn impl_trait_query(arg: TokenStream, item: TokenStream) -> Result<TokenStream2>
}

#[inline]
fn init_state(world: &mut #imports::World) -> Self::State {
fn init_state(world: &#imports::World) -> Self::State {
<#my_crate::All<&#trait_object> as #imports::WorldQuery>::init_state(world)
}

Expand Down Expand Up @@ -363,7 +363,7 @@ fn impl_trait_query(arg: TokenStream, item: TokenStream) -> Result<TokenStream2>
}

#[inline]
fn init_state(world: &mut #imports::World) -> Self::State {
fn init_state(world: &#imports::World) -> Self::State {
<#my_crate::All<&mut #trait_object> as #imports::WorldQuery>::init_state(world)
}

Expand Down
4 changes: 2 additions & 2 deletions bevy-trait-query/src/all/impls/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ unsafe impl<Trait: ?Sized + TraitQuery> WorldQuery for All<&Trait> {
}

#[inline]
fn init_state(world: &mut World) -> Self::State {
fn init_state(world: &World) -> Self::State {
TraitQueryState::init(world)
}

Expand Down Expand Up @@ -285,7 +285,7 @@ unsafe impl<Trait: ?Sized + TraitQuery> WorldQuery for All<&mut Trait> {
}

#[inline]
fn init_state(world: &mut World) -> Self::State {
fn init_state(world: &World) -> Self::State {
TraitQueryState::init(world)
}

Expand Down
12 changes: 7 additions & 5 deletions bevy-trait-query/src/internal/trait_registry.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::sync::atomic::{AtomicBool, Ordering};

use crate::TraitQuery;
use crate::dyn_constructor::DynCtor;
use bevy_ecs::component::{Component, ComponentId, StorageType};
Expand All @@ -14,7 +16,7 @@ pub(crate) struct TraitImplRegistry<Trait: ?Sized> {
pub(crate) sparse_components: Vec<ComponentId>,
pub(crate) sparse_meta: Vec<TraitImplMeta<Trait>>,

pub(crate) sealed: bool,
pub(crate) sealed: AtomicBool,
}

impl<T: ?Sized> Default for TraitImplRegistry<T> {
Expand All @@ -27,7 +29,7 @@ impl<T: ?Sized> Default for TraitImplRegistry<T> {
table_meta: vec![],
sparse_components: vec![],
sparse_meta: vec![],
sealed: false,
sealed: AtomicBool::new(false),
}
}
}
Expand All @@ -43,7 +45,7 @@ impl<Trait: ?Sized + TraitQuery> TraitImplRegistry<Trait> {
return;
}

if self.sealed {
if self.sealed.load(Ordering::Relaxed) {
// It is not possible to update the `FetchState` for a given system after the game has started,
// so for explicitness, let's panic instead of having a trait impl silently get forgotten.
panic!("Cannot register new trait impls after the game has started");
Expand All @@ -64,8 +66,8 @@ impl<Trait: ?Sized + TraitQuery> TraitImplRegistry<Trait> {
}
}

pub(crate) fn seal(&mut self) {
self.sealed = true;
pub(crate) fn seal(&self) {
self.sealed.store(true, Ordering::Relaxed);
}
}

Expand Down
Loading