Skip to content

Commit 9cebc66

Browse files
authored
Make 8 methods public and updated input parameter generics for SystemState::build_system_with_input (#17034)
# Objective - Made certain methods public for advanced use cases. Methods that returns mutable references are marked as unsafe due to the possibility of violating internal lifetime constraint assumptions. - Fixes an issue introduced by #15184
1 parent 5f42c9a commit 9cebc66

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

crates/bevy_ecs/src/query/access.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1272,28 +1272,28 @@ impl<T: SparseSetIndex> FilteredAccessSet<T> {
12721272
}
12731273

12741274
/// Adds a read access to a resource to the set.
1275-
pub(crate) fn add_unfiltered_resource_read(&mut self, index: T) {
1275+
pub fn add_unfiltered_resource_read(&mut self, index: T) {
12761276
let mut filter = FilteredAccess::default();
12771277
filter.add_resource_read(index);
12781278
self.add(filter);
12791279
}
12801280

12811281
/// Adds a write access to a resource to the set.
1282-
pub(crate) fn add_unfiltered_resource_write(&mut self, index: T) {
1282+
pub fn add_unfiltered_resource_write(&mut self, index: T) {
12831283
let mut filter = FilteredAccess::default();
12841284
filter.add_resource_write(index);
12851285
self.add(filter);
12861286
}
12871287

12881288
/// Adds read access to all resources to the set.
1289-
pub(crate) fn add_unfiltered_read_all_resources(&mut self) {
1289+
pub fn add_unfiltered_read_all_resources(&mut self) {
12901290
let mut filter = FilteredAccess::default();
12911291
filter.access.read_all_resources();
12921292
self.add(filter);
12931293
}
12941294

12951295
/// Adds write access to all resources to the set.
1296-
pub(crate) fn add_unfiltered_write_all_resources(&mut self) {
1296+
pub fn add_unfiltered_write_all_resources(&mut self) {
12971297
let mut filter = FilteredAccess::default();
12981298
filter.access.write_all_resources();
12991299
self.add(filter);

crates/bevy_ecs/src/schedule/graph/graph_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ where
125125
/// For a directed graph, the edge is directed from `a` to `b`.
126126
///
127127
/// Inserts nodes `a` and/or `b` if they aren't already part of the graph.
128-
pub(crate) fn add_edge(&mut self, a: NodeId, b: NodeId) {
128+
pub fn add_edge(&mut self, a: NodeId, b: NodeId) {
129129
if self.edges.insert(Self::edge_key(a, b)) {
130130
// insert in the adjacency list if it's a new edge
131131
self.nodes

crates/bevy_ecs/src/system/function_system.rs

+28-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use variadics_please::all_tuples;
1818
#[cfg(feature = "trace")]
1919
use tracing::{info_span, Span};
2020

21-
use super::{In, IntoSystem, ReadOnlySystem, SystemParamBuilder};
21+
use super::{IntoSystem, ReadOnlySystem, SystemParamBuilder};
2222

2323
/// The metadata of a [`System`].
2424
#[derive(Clone)]
@@ -396,7 +396,7 @@ macro_rules! impl_build_system {
396396
Input: SystemInput,
397397
Out: 'static,
398398
Marker,
399-
F: FnMut(In<Input>, $(SystemParamItem<$param>),*) -> Out
399+
F: FnMut(Input, $(SystemParamItem<$param>),*) -> Out
400400
+ SystemParamFunction<Marker, Param = ($($param,)*), In = Input, Out = Out>,
401401
>(
402402
self,
@@ -474,6 +474,12 @@ impl<Param: SystemParam> SystemState<Param> {
474474
&self.meta
475475
}
476476

477+
/// Gets the metadata for this instance.
478+
#[inline]
479+
pub fn meta_mut(&mut self) -> &mut SystemMeta {
480+
&mut self.meta
481+
}
482+
477483
/// Retrieve the [`SystemParam`] values. This can only be called when all parameters are read-only.
478484
#[inline]
479485
pub fn get<'w, 's>(&'s mut self, world: &'w World) -> SystemParamItem<'w, 's, Param>
@@ -644,6 +650,25 @@ impl<Param: SystemParam> SystemState<Param> {
644650
self.meta.last_run = change_tick;
645651
param
646652
}
653+
654+
/// Returns a reference to the current system param states.
655+
pub fn param_state(&self) -> &Param::State {
656+
&self.param_state
657+
}
658+
659+
/// Returns a mutable reference to the current system param states.
660+
/// Marked as unsafe because modifying the system states may result in violation to certain
661+
/// assumptions made by the [`SystemParam`]. Use with care.
662+
///
663+
/// # Safety
664+
/// Modifying the system param states may have unintended consequences.
665+
/// The param state is generally considered to be owned by the [`SystemParam`]. Modifications
666+
/// should respect any invariants as required by the [`SystemParam`].
667+
/// For example, modifying the system state of [`ResMut`](crate::system::ResMut) without also
668+
/// updating [`SystemMeta::component_access_set`] will obviously create issues.
669+
pub unsafe fn param_state_mut(&mut self) -> &mut Param::State {
670+
&mut self.param_state
671+
}
647672
}
648673

649674
impl<Param: SystemParam> FromWorld for SystemState<Param> {
@@ -656,7 +681,7 @@ impl<Param: SystemParam> FromWorld for SystemState<Param> {
656681
///
657682
/// You get this by calling [`IntoSystem::into_system`] on a function that only accepts
658683
/// [`SystemParam`]s. The output of the system becomes the functions return type, while the input
659-
/// becomes the functions [`In`] tagged parameter or `()` if no such parameter exists.
684+
/// becomes the functions first parameter or `()` if no such parameter exists.
660685
///
661686
/// [`FunctionSystem`] must be `.initialized` before they can be run.
662687
///

0 commit comments

Comments
 (0)