Skip to content

Commit 68331f7

Browse files
committed
Use InvertibleComponentIdSet
1 parent f6ca611 commit 68331f7

2 files changed

Lines changed: 33 additions & 37 deletions

File tree

crates/bevy_dev_tools/src/schedule_data/serde.rs

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -123,23 +123,20 @@ pub struct AccessData {
123123
}
124124

125125
impl AccessData {
126-
fn try_new(value: &bevy_ecs::query::Access, trace: &mut ComponentTrace) -> Option<Self> {
127-
// TODO: `try_reads_and_writes` returns error if `read_and_writes_inverted=true`,
128-
// thus `AccessData` always has `read_and_writes_inverted=false`
129-
// Consider making `try_reads_and_writes()` return an enum of Normal or Except
130-
// Then can remove `read_and_writes_inverted()`.
131-
// Similarly for `try_writes()` and `writes_inverted` and `writes_inverted()`.
126+
fn new(value: &bevy_ecs::query::Access, trace: &mut ComponentTrace) -> Self {
127+
let read_and_writes = value.reads_and_writes();
128+
let writes = value.writes();
132129

133-
let read_and_writes = value.try_reads_and_writes().ok()?;
134-
let writes = value.try_writes().ok()?;
130+
let read_and_writes_inverted = read_and_writes.inverted();
131+
let writes_inverted = writes.inverted();
135132

136-
Some(Self {
133+
Self {
137134
read_and_writes: trace.get_indexes(read_and_writes.iter()),
138135
writes: trace.get_indexes(writes.iter()),
139-
read_and_writes_inverted: value.read_and_writes_inverted(),
140-
writes_inverted: value.writes_inverted(),
136+
read_and_writes_inverted,
137+
writes_inverted,
141138
archetypal: trace.get_indexes(value.archetypal().iter()),
142-
})
139+
}
143140
}
144141
}
145142

@@ -173,13 +170,10 @@ pub struct FilteredAccessData {
173170
}
174171

175172
impl FilteredAccessData {
176-
fn try_new(
177-
value: &bevy_ecs::query::FilteredAccess,
178-
trace: &mut ComponentTrace,
179-
) -> Option<Self> {
180-
let access = AccessData::try_new(value.access(), trace)?;
173+
fn new(value: &bevy_ecs::query::FilteredAccess, trace: &mut ComponentTrace) -> Self {
174+
let access = AccessData::new(value.access(), trace);
181175

182-
Some(Self {
176+
Self {
183177
access,
184178
required: trace.get_indexes(value.required().iter()),
185179
filter_sets: value
@@ -190,7 +184,7 @@ impl FilteredAccessData {
190184
without: trace.get_indexes(f.without().iter()),
191185
})
192186
.collect(),
193-
})
187+
}
194188
}
195189
}
196190

@@ -334,14 +328,10 @@ impl ScheduleData {
334328
== core::any::TypeId::of::<ApplyDeferred>(),
335329
exclusive: flags.contains(SystemStateFlags::EXCLUSIVE),
336330
deferred: flags.contains(SystemStateFlags::DEFERRED),
337-
combined_access: AccessData::try_new(combined_access, &mut component_trace)
338-
.unwrap_or_default(),
331+
combined_access: AccessData::new(combined_access, &mut component_trace),
339332
filtered_accesses: filtered_accesses
340333
.iter()
341-
.map(|fa| {
342-
FilteredAccessData::try_new(fa, &mut component_trace)
343-
.unwrap_or_default()
344-
})
334+
.map(|fa| FilteredAccessData::new(fa, &mut component_trace))
345335
.collect(),
346336
}
347337
})

crates/bevy_ecs/src/query/access.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -395,18 +395,6 @@ impl Access {
395395
AccessConflicts::Individual(conflicts)
396396
}
397397

398-
/// Is `true` if this component can read all components *except* those
399-
/// present in `Self::read_and_writes`.
400-
pub fn read_and_writes_inverted(&self) -> bool {
401-
self.read_and_writes_inverted
402-
}
403-
404-
/// Is `true` if this component can write to all components *except* those
405-
/// present in `Self::writes`.
406-
pub fn writes_inverted(&self) -> bool {
407-
self.writes_inverted
408-
}
409-
410398
/// Returns the indices of the components that this has an archetypal access to.
411399
///
412400
/// These are components whose values are not accessed (and thus will never cause conflicts),
@@ -505,6 +493,24 @@ pub enum InvertibleComponentIdSet<'a> {
505493
Excluded(&'a ComponentIdSet),
506494
}
507495

496+
impl InvertibleComponentIdSet<'_> {
497+
/// Returns true if this is Included, otherwise false
498+
pub fn inverted(&self) -> bool {
499+
match self {
500+
InvertibleComponentIdSet::Included(_) => true,
501+
InvertibleComponentIdSet::Excluded(_) => false,
502+
}
503+
}
504+
505+
/// Iterate the underlying component ids
506+
pub fn iter(&self) -> ComponentIdIter<Ones<'_>> {
507+
match self {
508+
InvertibleComponentIdSet::Included(b) => b.iter(),
509+
InvertibleComponentIdSet::Excluded(b) => b.iter(),
510+
}
511+
}
512+
}
513+
508514
/// Performs an in-place union of `other` into `self`, where either set may be inverted.
509515
///
510516
/// Each set corresponds to a `FixedBitSet` if `inverted` is `false`,

0 commit comments

Comments
 (0)