Skip to content

Commit 42a846e

Browse files
committed
SystemNodeId, SystemSetNodeId
1 parent cc6c4d6 commit 42a846e

File tree

4 files changed

+188
-106
lines changed

4 files changed

+188
-106
lines changed

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ pub use self::single_threaded::SingleThreadedExecutor;
88

99
use fixedbitset::FixedBitSet;
1010

11-
use crate::{
12-
schedule::{BoxedCondition, NodeId},
13-
system::BoxedSystem,
14-
world::World,
15-
};
11+
use crate::schedule::graph_utils::{SystemNodeId, SystemSetNodeId};
12+
use crate::{schedule::BoxedCondition, system::BoxedSystem, world::World};
1613

1714
/// Types that can run a [`SystemSchedule`] on a [`World`].
1815
pub(super) trait SystemExecutor: Send + Sync {
@@ -53,8 +50,8 @@ pub struct SystemSchedule {
5350
pub(super) systems: Vec<BoxedSystem>,
5451
pub(super) system_conditions: Vec<Vec<BoxedCondition>>,
5552
pub(super) set_conditions: Vec<Vec<BoxedCondition>>,
56-
pub(super) system_ids: Vec<NodeId>,
57-
pub(super) set_ids: Vec<NodeId>,
53+
pub(super) system_ids: Vec<SystemNodeId>,
54+
pub(super) set_ids: Vec<SystemSetNodeId>,
5855
pub(super) system_dependencies: Vec<usize>,
5956
pub(super) system_dependents: Vec<Vec<usize>>,
6057
pub(super) sets_with_conditions_of_systems: Vec<FixedBitSet>,

crates/bevy_ecs/src/schedule/graph_utils.rs

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,69 @@ use fixedbitset::FixedBitSet;
88

99
use crate::schedule::set::*;
1010

11+
/// Unique identifier for a system set stored in a [`ScheduleGraph`].
12+
///
13+
/// [`ScheduleGraph`]: super::ScheduleGraph
14+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
15+
pub struct SystemNodeId(
16+
/// Index in various arrays storing systems.
17+
usize,
18+
);
19+
20+
impl SystemNodeId {
21+
pub(crate) fn new(index: usize) -> Self {
22+
Self(index)
23+
}
24+
25+
pub(crate) fn index(&self) -> usize {
26+
self.0
27+
}
28+
}
29+
30+
/// Unique identifier for a system set stored in a [`ScheduleGraph`].
31+
///
32+
/// [`ScheduleGraph`]: super::ScheduleGraph
33+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
34+
pub struct SystemSetNodeId(
35+
/// Index in various arrays storing system sets.
36+
usize,
37+
);
38+
39+
impl SystemSetNodeId {
40+
pub(crate) fn new(index: usize) -> Self {
41+
Self(index)
42+
}
43+
44+
pub(crate) fn index(&self) -> usize {
45+
self.0
46+
}
47+
}
48+
1149
/// Unique identifier for a system or system set stored in a [`ScheduleGraph`].
1250
///
1351
/// [`ScheduleGraph`]: super::ScheduleGraph
1452
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
1553
pub enum NodeId {
1654
/// Identifier for a system.
17-
System(usize),
55+
System(SystemNodeId),
1856
/// Identifier for a system set.
19-
Set(usize),
57+
Set(SystemSetNodeId),
2058
}
2159

2260
impl NodeId {
23-
/// Returns the internal integer value.
24-
pub(crate) fn index(&self) -> usize {
61+
/// Unpack [`SystemNodeId`] variant.
62+
pub fn system(&self) -> Option<SystemNodeId> {
63+
match self {
64+
NodeId::System(node) => Some(*node),
65+
NodeId::Set(_) => None,
66+
}
67+
}
68+
69+
/// Unpack [`SystemSetNodeId`] variant.
70+
pub fn set(&self) -> Option<SystemSetNodeId> {
2571
match self {
26-
NodeId::System(index) | NodeId::Set(index) => *index,
72+
NodeId::System(_) => None,
73+
NodeId::Set(node) => Some(*node),
2774
}
2875
}
2976

crates/bevy_ecs/src/schedule/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ pub use self::set::*;
1818
pub use self::state::*;
1919

2020
pub use self::graph_utils::NodeId;
21+
pub use self::graph_utils::SystemNodeId;
22+
pub use self::graph_utils::SystemSetNodeId;
2123

2224
#[cfg(test)]
2325
mod tests {

0 commit comments

Comments
 (0)