Skip to content

Commit

Permalink
change is_system_type() -> bool to system_type() -> Option<TypeId> (
Browse files Browse the repository at this point in the history
#7715)

# Objective

- it would be nice to be able to associate a `NodeId` of a system type set to the `NodeId` of the actual system (used in bevy_mod_debugdump)

## Solution

- make `system_type` return the type id of the system
  - that way you can check if a `dyn SystemSet` is the system type set of a `dyn System`
- I don't know if this information is already present somewhere else in the scheduler or if there is a better way to expose it
  • Loading branch information
jakobhellermann committed Feb 16, 2023
1 parent 6a63940 commit b1646e9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
4 changes: 0 additions & 4 deletions crates/bevy_ecs/macros/src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ pub fn derive_set(input: syn::DeriveInput, trait_path: &syn::Path) -> TokenStrea

(quote! {
impl #impl_generics #trait_path for #ident #ty_generics #where_clause {
fn is_system_type(&self) -> bool {
false
}

fn is_base(&self) -> bool {
#is_base
}
Expand Down
18 changes: 9 additions & 9 deletions crates/bevy_ecs/src/schedule/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl SystemSetConfig {
// system type sets are automatically populated
// to avoid unintentionally broad changes, they cannot be configured
assert!(
!set.is_system_type(),
set.system_type().is_none(),
"configuring system type sets is not allowed"
);

Expand Down Expand Up @@ -200,7 +200,7 @@ impl IntoSystemSetConfig for SystemSetConfig {
#[track_caller]
fn in_set(mut self, set: impl SystemSet) -> Self {
assert!(
!set.is_system_type(),
set.system_type().is_none(),
"adding arbitrary systems to a system type set is not allowed"
);
assert!(
Expand All @@ -218,7 +218,7 @@ impl IntoSystemSetConfig for SystemSetConfig {
#[track_caller]
fn in_base_set(mut self, set: impl SystemSet) -> Self {
assert!(
!set.is_system_type(),
set.system_type().is_none(),
"System type sets cannot be base sets."
);
assert!(
Expand Down Expand Up @@ -394,7 +394,7 @@ impl IntoSystemConfig<()> for SystemConfig {
#[track_caller]
fn in_set(mut self, set: impl SystemSet) -> Self {
assert!(
!set.is_system_type(),
set.system_type().is_none(),
"adding arbitrary systems to a system type set is not allowed"
);
assert!(
Expand All @@ -408,7 +408,7 @@ impl IntoSystemConfig<()> for SystemConfig {
#[track_caller]
fn in_base_set(mut self, set: impl SystemSet) -> Self {
assert!(
!set.is_system_type(),
set.system_type().is_none(),
"System type sets cannot be base sets."
);
assert!(
Expand Down Expand Up @@ -548,7 +548,7 @@ impl IntoSystemConfigs<()> for SystemConfigs {
#[track_caller]
fn in_set(mut self, set: impl SystemSet) -> Self {
assert!(
!set.is_system_type(),
set.system_type().is_none(),
"adding arbitrary systems to a system type set is not allowed"
);
assert!(
Expand All @@ -565,7 +565,7 @@ impl IntoSystemConfigs<()> for SystemConfigs {
#[track_caller]
fn in_base_set(mut self, set: impl SystemSet) -> Self {
assert!(
!set.is_system_type(),
set.system_type().is_none(),
"System type sets cannot be base sets."
);
assert!(
Expand Down Expand Up @@ -692,7 +692,7 @@ impl IntoSystemSetConfigs for SystemSetConfigs {
#[track_caller]
fn in_set(mut self, set: impl SystemSet) -> Self {
assert!(
!set.is_system_type(),
set.system_type().is_none(),
"adding arbitrary systems to a system type set is not allowed"
);
assert!(
Expand All @@ -713,7 +713,7 @@ impl IntoSystemSetConfigs for SystemSetConfigs {
#[track_caller]
fn in_base_set(mut self, set: impl SystemSet) -> Self {
assert!(
!set.is_system_type(),
set.system_type().is_none(),
"System type sets cannot be base sets."
);
assert!(
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/schedule/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ impl SystemSetNode {
}

pub fn is_system_type(&self) -> bool {
self.inner.is_system_type()
self.inner.system_type().is_some()
}
}

Expand Down
11 changes: 6 additions & 5 deletions crates/bevy_ecs/src/schedule/set.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::any::TypeId;
use std::fmt::Debug;
use std::hash::{Hash, Hasher};
use std::marker::PhantomData;
Expand All @@ -17,9 +18,9 @@ pub type BoxedScheduleLabel = Box<dyn ScheduleLabel>;

/// Types that identify logical groups of systems.
pub trait SystemSet: DynHash + Debug + Send + Sync + 'static {
/// Returns `true` if this system set is a [`SystemTypeSet`].
fn is_system_type(&self) -> bool {
false
/// Returns `Some` if this system set is a [`SystemTypeSet`].
fn system_type(&self) -> Option<TypeId> {
None
}

/// Returns `true` if this set is a "base system set". Systems
Expand Down Expand Up @@ -102,8 +103,8 @@ impl<T> PartialEq for SystemTypeSet<T> {
impl<T> Eq for SystemTypeSet<T> {}

impl<T> SystemSet for SystemTypeSet<T> {
fn is_system_type(&self) -> bool {
true
fn system_type(&self) -> Option<TypeId> {
Some(TypeId::of::<T>())
}

fn dyn_clone(&self) -> Box<dyn SystemSet> {
Expand Down

0 comments on commit b1646e9

Please sign in to comment.