Skip to content
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

[Merged by Bors] - SystemParam for the name of the system you are currently in #5731

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 46 additions & 0 deletions crates/bevy_ecs/src/system/system_param.rs
Expand Up @@ -16,6 +16,7 @@ pub use bevy_ecs_macros::SystemParam;
use bevy_ecs_macros::{all_tuples, impl_param_set};
use bevy_ptr::UnsafeCellDeref;
use std::{
borrow::Cow,
fmt::Debug,
marker::PhantomData,
ops::{Deref, DerefMut},
Expand Down Expand Up @@ -1304,6 +1305,51 @@ impl<'w, 's> SystemParamFetch<'w, 's> for SystemChangeTickState {
}
}

#[derive(Debug)]
pub struct SystemName {
Aceeri marked this conversation as resolved.
Show resolved Hide resolved
Aceeri marked this conversation as resolved.
Show resolved Hide resolved
Aceeri marked this conversation as resolved.
Show resolved Hide resolved
name: Cow<'static, str>,
}

impl SystemName {
pub fn name(&self) -> &Cow<'static, str> {
Aceeri marked this conversation as resolved.
Show resolved Hide resolved
&self.name
}
}

impl<'a> SystemParam for SystemName {
type Fetch = SystemNameState;
}

// SAFETY: Only reads World entities
Aceeri marked this conversation as resolved.
Show resolved Hide resolved
unsafe impl ReadOnlySystemParamFetch for SystemNameState {}

/// The [`SystemParamState`] of [`Entities`].
Aceeri marked this conversation as resolved.
Show resolved Hide resolved
#[doc(hidden)]
pub struct SystemNameState;

// SAFETY: no component value access
unsafe impl SystemParamState for SystemNameState {
fn init(_world: &mut World, _system_meta: &mut SystemMeta) -> Self {
Aceeri marked this conversation as resolved.
Show resolved Hide resolved
Self
}
}

impl<'w, 's> SystemParamFetch<'w, 's> for SystemNameState {
type Item = SystemName;

#[inline]
unsafe fn get_param(
_state: &'s mut Self,
system_meta: &SystemMeta,
_world: &'w World,
_change_tick: u32,
) -> Self::Item {
SystemName {
name: system_meta.name.clone(),
Aceeri marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

macro_rules! impl_system_param_tuple {
($($param: ident),*) => {
impl<$($param: SystemParam),*> SystemParam for ($($param,)*) {
Expand Down