Skip to content

Faster FilteredEntity(Ref|Mut) and Entity(Ref|Mut)Except by borrowing Access #20111

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
15 changes: 3 additions & 12 deletions crates/bevy_animation/src/animation_curves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,7 @@ impl<A: Animatable> AnimationCurveEvaluator for AnimatableCurveEvaluator<A> {
self.evaluator.push_blend_register(weight, graph_node)
}

fn commit<'a>(
&mut self,
mut entity: AnimationEntityMut<'a>,
) -> Result<(), AnimationEvaluationError> {
fn commit(&mut self, mut entity: AnimationEntityMut) -> Result<(), AnimationEvaluationError> {
let property = self.property.get_mut(&mut entity)?;
*property = self
.evaluator
Expand Down Expand Up @@ -596,10 +593,7 @@ impl AnimationCurveEvaluator for WeightsCurveEvaluator {
Ok(())
}

fn commit<'a>(
&mut self,
mut entity: AnimationEntityMut<'a>,
) -> Result<(), AnimationEvaluationError> {
fn commit(&mut self, mut entity: AnimationEntityMut) -> Result<(), AnimationEvaluationError> {
if self.stack_morph_target_weights.is_empty() {
return Ok(());
}
Expand Down Expand Up @@ -905,10 +899,7 @@ pub trait AnimationCurveEvaluator: Downcast + Send + Sync + 'static {
///
/// The property on the component must be overwritten with the value from
/// the stack, not blended with it.
fn commit<'a>(
&mut self,
entity: AnimationEntityMut<'a>,
) -> Result<(), AnimationEvaluationError>;
fn commit(&mut self, entity: AnimationEntityMut) -> Result<(), AnimationEvaluationError>;
}

impl_downcast!(AnimationCurveEvaluator);
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_animation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,8 +1021,8 @@ pub fn advance_animations(
}

/// A type alias for [`EntityMutExcept`] as used in animation.
pub type AnimationEntityMut<'w> =
EntityMutExcept<'w, (AnimationTarget, AnimationPlayer, AnimationGraphHandle)>;
pub type AnimationEntityMut<'w, 's> =
EntityMutExcept<'w, 's, (AnimationTarget, AnimationPlayer, AnimationGraphHandle)>;

/// A system that modifies animation targets (e.g. bones in a skinned mesh)
/// according to the currently-playing animations.
Expand Down
26 changes: 26 additions & 0 deletions crates/bevy_ecs/src/query/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,32 @@ impl<T: SparseSetIndex> Access<T> {
}
}

/// Creates an [`Access`] with read access to all components.
/// This is equivalent to calling `read_all()` on `Access::new()`,
/// but is available in a `const` context.
pub(crate) const fn new_read_all() -> Self {
let mut access = Self::new();
access.reads_all_resources = true;
// Note that we cannot use `read_all_components()`
// because `FixedBitSet::clear()` is not `const`.
access.component_read_and_writes_inverted = true;
access
}

/// Creates an [`Access`] with read access to all components.
/// This is equivalent to calling `read_all()` on `Access::new()`,
/// but is available in a `const` context.
pub(crate) const fn new_write_all() -> Self {
let mut access = Self::new();
access.reads_all_resources = true;
access.writes_all_resources = true;
// Note that we cannot use `write_all_components()`
// because `FixedBitSet::clear()` is not `const`.
access.component_read_and_writes_inverted = true;
access.component_writes_inverted = true;
access
}

fn add_component_sparse_set_index_read(&mut self, index: usize) {
if !self.component_read_and_writes_inverted {
self.component_read_and_writes.grow_and_insert(index);
Expand Down
Loading
Loading