goud_engine/ecs/system/system_trait/system_meta.rs
1//! `SystemMeta` — metadata about a system (name, access patterns).
2
3use std::borrow::Cow;
4
5use crate::ecs::query::Access;
6
7/// Metadata about a system.
8///
9/// `SystemMeta` stores information about a system that is useful for:
10/// - Debugging and logging (name)
11/// - Conflict detection (component access)
12/// - Scheduling (dependencies, ordering)
13///
14/// # Example
15///
16/// ```
17/// use goud_engine::ecs::system::SystemMeta;
18///
19/// let meta = SystemMeta::new("MySystem");
20/// assert_eq!(meta.name(), "MySystem");
21/// ```
22#[derive(Debug, Clone)]
23pub struct SystemMeta {
24 /// Human-readable name of the system.
25 name: Cow<'static, str>,
26 /// Component and resource access patterns.
27 component_access: Access,
28}
29
30impl SystemMeta {
31 /// Creates new system metadata with the given name.
32 #[inline]
33 pub fn new(name: impl Into<Cow<'static, str>>) -> Self {
34 Self {
35 name: name.into(),
36 component_access: Access::new(),
37 }
38 }
39
40 /// Returns the system's name.
41 #[inline]
42 pub fn name(&self) -> &str {
43 &self.name
44 }
45
46 /// Sets the system's name.
47 #[inline]
48 pub fn set_name(&mut self, name: impl Into<Cow<'static, str>>) {
49 self.name = name.into();
50 }
51
52 /// Returns the system's component access pattern.
53 #[inline]
54 pub fn component_access(&self) -> &Access {
55 &self.component_access
56 }
57
58 /// Returns a mutable reference to the component access pattern.
59 #[inline]
60 pub fn component_access_mut(&mut self) -> &mut Access {
61 &mut self.component_access
62 }
63
64 /// Sets the component access pattern.
65 #[inline]
66 pub fn set_component_access(&mut self, access: Access) {
67 self.component_access = access;
68 }
69
70 /// Checks if this system's access conflicts with another.
71 ///
72 /// Two systems conflict if one writes to a component that the other
73 /// reads or writes.
74 #[inline]
75 pub fn conflicts_with(&self, other: &SystemMeta) -> bool {
76 self.component_access
77 .conflicts_with(&other.component_access)
78 }
79
80 /// Returns true if this system only reads data (no writes).
81 #[inline]
82 pub fn is_read_only(&self) -> bool {
83 self.component_access.is_read_only()
84 }
85}
86
87impl Default for SystemMeta {
88 fn default() -> Self {
89 Self::new("UnnamedSystem")
90 }
91}