Skip to content

Commit b20c7af

Browse files
committed
add non-access methods for resources existence
1 parent 92eaf1a commit b20c7af

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

crates/bevy_ecs/src/schedule/executor/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ mod tests {
202202
#[test]
203203
fn invalid_system_param_skips() {
204204
for executor in EXECUTORS {
205-
invalid_system_param_skips_core(executor)
205+
invalid_system_param_skips_core(executor);
206206
}
207207
}
208208

@@ -235,7 +235,7 @@ mod tests {
235235
#[test]
236236
fn invalid_condition_param_skips_system() {
237237
for executor in EXECUTORS {
238-
invalid_condition_param_skips_system_core(executor)
238+
invalid_condition_param_skips_system_core(executor);
239239
}
240240
}
241241

crates/bevy_ecs/src/system/system_param.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ unsafe impl<'a, T: Resource> SystemParam for Res<'a, T> {
600600
_system_meta: &SystemMeta,
601601
world: &World,
602602
) -> bool {
603-
world.get_resource_by_id(component_id).is_some()
603+
world.contains_resource_by_id(component_id)
604604
}
605605

606606
#[inline]
@@ -711,7 +711,7 @@ unsafe impl<'a, T: Resource> SystemParam for ResMut<'a, T> {
711711
_system_meta: &SystemMeta,
712712
world: &World,
713713
) -> bool {
714-
world.get_resource_by_id(component_id).is_some()
714+
world.contains_resource_by_id(component_id)
715715
}
716716

717717
#[inline]
@@ -1279,7 +1279,7 @@ unsafe impl<'a, T: 'static> SystemParam for NonSend<'a, T> {
12791279
_system_meta: &SystemMeta,
12801280
world: &World,
12811281
) -> bool {
1282-
world.get_non_send_by_id(component_id).is_some()
1282+
world.contains_non_send_by_id(component_id)
12831283
}
12841284

12851285
#[inline]
@@ -1387,7 +1387,7 @@ unsafe impl<'a, T: 'static> SystemParam for NonSendMut<'a, T> {
13871387
_system_meta: &SystemMeta,
13881388
world: &World,
13891389
) -> bool {
1390-
world.get_non_send_by_id(component_id).is_some()
1390+
world.contains_non_send_by_id(component_id)
13911391
}
13921392

13931393
#[inline]

crates/bevy_ecs/src/world/mod.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,16 @@ impl World {
14791479
.unwrap_or(false)
14801480
}
14811481

1482+
/// Returns `true` if a resource with provided `component_id` exists. Otherwise returns `false`.
1483+
#[inline]
1484+
pub fn contains_resource_by_id(&self, component_id: ComponentId) -> bool {
1485+
self.storages
1486+
.resources
1487+
.get(component_id)
1488+
.map(ResourceData::is_present)
1489+
.unwrap_or(false)
1490+
}
1491+
14821492
/// Returns `true` if a resource of type `R` exists. Otherwise returns `false`.
14831493
#[inline]
14841494
pub fn contains_non_send<R: 'static>(&self) -> bool {
@@ -1489,6 +1499,16 @@ impl World {
14891499
.unwrap_or(false)
14901500
}
14911501

1502+
/// Returns `true` if a resource with provided `component_id` exists. Otherwise returns `false`.
1503+
#[inline]
1504+
pub fn contains_non_send_by_id(&self, component_id: ComponentId) -> bool {
1505+
self.storages
1506+
.non_send_resources
1507+
.get(component_id)
1508+
.map(ResourceData::is_present)
1509+
.unwrap_or(false)
1510+
}
1511+
14921512
/// Returns `true` if a resource of type `R` exists and was added since the world's
14931513
/// [`last_change_tick`](World::last_change_tick()). Otherwise, this returns `false`.
14941514
///

0 commit comments

Comments
 (0)