@@ -43,6 +43,7 @@ pub struct SystemMeta {
43
43
is_send : bool ,
44
44
has_deferred : bool ,
45
45
pub ( crate ) last_run : Tick ,
46
+ validity_warning : ValidityWarning ,
46
47
#[ cfg( feature = "trace" ) ]
47
48
pub ( crate ) system_span : Span ,
48
49
#[ cfg( feature = "trace" ) ]
@@ -59,6 +60,7 @@ impl SystemMeta {
59
60
is_send : true ,
60
61
has_deferred : false ,
61
62
last_run : Tick :: new ( 0 ) ,
63
+ validity_warning : ValidityWarning :: Once ,
62
64
#[ cfg( feature = "trace" ) ]
63
65
system_span : info_span ! ( "system" , name = name) ,
64
66
#[ cfg( feature = "trace" ) ]
@@ -75,6 +77,7 @@ impl SystemMeta {
75
77
/// Sets the name of of this system.
76
78
///
77
79
/// Useful to give closure systems more readable and unique names for debugging and tracing.
80
+ #[ inline]
78
81
pub fn set_name ( & mut self , new_name : impl Into < Cow < ' static , str > > ) {
79
82
let new_name: Cow < ' static , str > = new_name. into ( ) ;
80
83
#[ cfg( feature = "trace" ) ]
@@ -108,9 +111,50 @@ impl SystemMeta {
108
111
109
112
/// Marks the system as having deferred buffers like [`Commands`](`super::Commands`)
110
113
/// This lets the scheduler insert [`apply_deferred`](`crate::prelude::apply_deferred`) systems automatically.
114
+ #[ inline]
111
115
pub fn set_has_deferred ( & mut self ) {
112
116
self . has_deferred = true ;
113
117
}
118
+
119
+ /// Call after [`System::validate_param`] fails.
120
+ /// Updates the validity warning.
121
+ /// The return value tells whether a warning should be emitted or not.
122
+ #[ inline]
123
+ pub ( crate ) fn update_validity_warning ( & mut self ) -> bool {
124
+ self . validity_warning . update ( )
125
+ }
126
+
127
+ /// Configures the validity warning.
128
+ #[ inline]
129
+ pub fn set_validity_warning ( & mut self , validity_warning : ValidityWarning ) {
130
+ self . validity_warning = validity_warning;
131
+ }
132
+ }
133
+
134
+ /// State machine for emitting warnings when [system params are invalid](System::validate_param).
135
+ #[ derive( Clone , Copy ) ]
136
+ pub enum ValidityWarning {
137
+ /// No warning should ever be emitted.
138
+ Never ,
139
+ /// The warning will be emitted once and status will update to [`Self::Never`].
140
+ Once ,
141
+ /// The warning will be emitted every time.
142
+ Always ,
143
+ }
144
+
145
+ impl ValidityWarning {
146
+ /// Updates the validity warning.
147
+ /// The return value tells whether a warning should be emitted or not.
148
+ #[ inline]
149
+ pub fn update ( & mut self ) -> bool {
150
+ let ( next, should_warn) = match self {
151
+ Self :: Never => ( Self :: Never , false ) ,
152
+ Self :: Once => ( Self :: Never , true ) ,
153
+ Self :: Always => ( Self :: Always , true ) ,
154
+ } ;
155
+ * self = next;
156
+ should_warn
157
+ }
114
158
}
115
159
116
160
// TODO: Actually use this in FunctionSystem. We should probably only do this once Systems are constructed using a World reference
@@ -662,6 +706,11 @@ where
662
706
F :: Param :: validate_param ( param_state, & self . system_meta , world)
663
707
}
664
708
709
+ #[ inline]
710
+ fn update_validity_warning ( & mut self ) -> bool {
711
+ self . system_meta . update_validity_warning ( )
712
+ }
713
+
665
714
#[ inline]
666
715
fn initialize ( & mut self , world : & mut World ) {
667
716
if let Some ( id) = self . world_id {
0 commit comments