Skip to content

Commit af5dd8a

Browse files
committed
Use InvertibleComponentIdSet
1 parent f6ca611 commit af5dd8a

2 files changed

Lines changed: 34 additions & 33 deletions

File tree

crates/bevy_dev_tools/src/schedule_data/serde.rs

Lines changed: 16 additions & 21 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,13 @@ pub struct FilteredAccessData {
173170
}
174171

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

182-
Some(Self {
179+
Self {
183180
access,
184181
required: trace.get_indexes(value.required().iter()),
185182
filter_sets: value
@@ -190,7 +187,7 @@ impl FilteredAccessData {
190187
without: trace.get_indexes(f.without().iter()),
191188
})
192189
.collect(),
193-
})
190+
}
194191
}
195192
}
196193

@@ -334,13 +331,11 @@ impl ScheduleData {
334331
== core::any::TypeId::of::<ApplyDeferred>(),
335332
exclusive: flags.contains(SystemStateFlags::EXCLUSIVE),
336333
deferred: flags.contains(SystemStateFlags::DEFERRED),
337-
combined_access: AccessData::try_new(combined_access, &mut component_trace)
338-
.unwrap_or_default(),
334+
combined_access: AccessData::new(combined_access, &mut component_trace),
339335
filtered_accesses: filtered_accesses
340336
.iter()
341337
.map(|fa| {
342-
FilteredAccessData::try_new(fa, &mut component_trace)
343-
.unwrap_or_default()
338+
FilteredAccessData::new(fa, &mut component_trace)
344339
})
345340
.collect(),
346341
}

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)