@@ -2,8 +2,8 @@ use crate::component::ComponentId;
2
2
use crate :: schedule:: { AmbiguityDetection , SystemContainer , SystemStage } ;
3
3
use crate :: world:: World ;
4
4
5
- use bevy_utils:: HashSet ;
6
5
use fixedbitset:: FixedBitSet ;
6
+ use std:: hash:: Hash ;
7
7
8
8
#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
9
9
/// Systems that access the same Component or Resource within the same stage
@@ -58,10 +58,10 @@ pub enum ExecutionOrderAmbiguities {
58
58
///
59
59
/// Created by applying [`find_ambiguities`] to a [`SystemContainer`].
60
60
/// These can be reported by configuring the [`ReportExecutionOrderAmbiguities`] resource.
61
- #[ derive( Debug , Clone , Eq , Hash ) ]
61
+ #[ derive( Debug , Clone , Eq ) ]
62
62
pub struct SystemOrderAmbiguity {
63
63
// The names of the conflicting systems
64
- pub system_names : ( String , String ) ,
64
+ pub system_names : [ String ; 2 ] ,
65
65
/// The components (and resources) that these systems have incompatible access to
66
66
pub conflicts : Vec < String > ,
67
67
/// The segment of the [`SystemStage`] that the conflicting systems were stored in
@@ -70,20 +70,37 @@ pub struct SystemOrderAmbiguity {
70
70
71
71
impl PartialEq for SystemOrderAmbiguity {
72
72
fn eq ( & self , other : & Self ) -> bool {
73
- // The order of the systems doesn't matter
74
- let names_aligned = ( self . system_names . 0 == other. system_names . 0 )
75
- & ( self . system_names . 1 == other. system_names . 1 ) ;
76
- let names_inverted = ( self . system_names . 0 == other. system_names . 1 )
77
- & ( self . system_names . 0 == other. system_names . 1 ) ;
78
- let names_match = names_aligned | names_inverted;
73
+ let mut self_names = self . system_names . clone ( ) ;
74
+ self_names. sort ( ) ;
79
75
80
- // The order of the reported conflicts doesn't matter
81
- let conflicts_match =
82
- HashSet :: from_iter ( self . conflicts . iter ( ) ) == HashSet :: from_iter ( other. conflicts . iter ( ) ) ;
76
+ let mut other_names = self . system_names . clone ( ) ;
77
+ other_names. sort ( ) ;
78
+
79
+ let mut self_conflicts = self . conflicts . clone ( ) ;
80
+ self_conflicts. sort ( ) ;
81
+
82
+ let mut other_conflicts = self . conflicts . clone ( ) ;
83
+ other_conflicts. sort ( ) ;
83
84
84
- let segments_match = self . segment == other. segment ;
85
+ ( self_names == other_names)
86
+ && ( self_conflicts == other_conflicts)
87
+ && ( self . segment == other. segment )
88
+ }
89
+ }
85
90
86
- names_match & conflicts_match & segments_match
91
+ // This impl is needed to allow us to test whether a returned set of ambiguities
92
+ // matches the expected value
93
+ impl Hash for SystemOrderAmbiguity {
94
+ fn hash < H : std:: hash:: Hasher > ( & self , state : & mut H ) {
95
+ // The order of the systems doesn't matter
96
+ let mut system_names = self . system_names . clone ( ) ;
97
+ system_names. sort ( ) ;
98
+ system_names. hash ( state) ;
99
+ // The order of the reported conflicts doesn't matter
100
+ let mut conflicts = self . conflicts . clone ( ) ;
101
+ conflicts. sort ( ) ;
102
+ conflicts. hash ( state) ;
103
+ self . segment . hash ( state) ;
87
104
}
88
105
}
89
106
@@ -150,7 +167,7 @@ impl SystemOrderAmbiguity {
150
167
151
168
Self {
152
169
// Don't bother with Cows here
153
- system_names : ( system_a_name. into ( ) , system_b_name. into ( ) ) ,
170
+ system_names : [ system_a_name. into ( ) , system_b_name. into ( ) ] ,
154
171
conflicts,
155
172
segment,
156
173
}
@@ -318,8 +335,8 @@ impl SystemStage {
318
335
* system_b_index,
319
336
component_ids. to_vec ( ) ,
320
337
SystemStageSegment :: Parallel ,
321
- & self ,
322
- & world,
338
+ self ,
339
+ world,
323
340
)
324
341
} )
325
342
. collect ( ) ;
@@ -333,8 +350,8 @@ impl SystemStage {
333
350
* system_b_index,
334
351
component_ids. to_vec ( ) ,
335
352
SystemStageSegment :: ExclusiveAtStart ,
336
- & self ,
337
- & world,
353
+ self ,
354
+ world,
338
355
)
339
356
} )
340
357
. collect ( ) ;
@@ -351,8 +368,8 @@ impl SystemStage {
351
368
* system_b_index,
352
369
component_ids. to_vec ( ) ,
353
370
SystemStageSegment :: ExclusiveBeforeCommands ,
354
- & self ,
355
- & world,
371
+ self ,
372
+ world,
356
373
)
357
374
} )
358
375
. collect ( ) ;
@@ -366,8 +383,8 @@ impl SystemStage {
366
383
* system_b_index,
367
384
component_ids. to_vec ( ) ,
368
385
SystemStageSegment :: ExclusiveAtEnd ,
369
- & self ,
370
- & world,
386
+ self ,
387
+ world,
371
388
)
372
389
} )
373
390
. collect ( ) ;
@@ -415,8 +432,8 @@ impl SystemStage {
415
432
for ( i, ambiguity) in ambiguities. iter ( ) . enumerate ( ) {
416
433
let ambiguity_number = i + 1 ;
417
434
// The path name is often just noise, and this gets us consistency with `conflicts`'s formatting
418
- let system_a_name = format_type_name ( ambiguity. system_names . 0 . as_str ( ) ) ;
419
- let system_b_name = format_type_name ( ambiguity. system_names . 1 . as_str ( ) ) ;
435
+ let system_a_name = format_type_name ( ambiguity. system_names [ 0 ] . as_str ( ) ) ;
436
+ let system_b_name = format_type_name ( ambiguity. system_names [ 1 ] . as_str ( ) ) ;
420
437
let mut conflicts: Vec < String > = ambiguity
421
438
. conflicts
422
439
. iter ( )
@@ -431,13 +448,13 @@ impl SystemStage {
431
448
println ! ( "{ambiguity_number:?}. `{system_a_name}` conflicts with `{system_b_name}` on {conflicts:?}" ) ;
432
449
}
433
450
// Print an empty line to space out multiple stages nicely
434
- println ! ( "" ) ;
451
+ println ! ( ) ;
435
452
}
436
453
437
454
if report_level == ExecutionOrderAmbiguities :: Deny
438
455
|| report_level == ExecutionOrderAmbiguities :: Forbid
439
456
{
440
- panic ! ( "The ReportExecutionOrderAmbiguities resource is set to a level that forbids the app from running with unresolved system execution order ambiguities." )
457
+ panic ! ( "The ` ReportExecutionOrderAmbiguities` resource is set to a level that forbids the app from running with unresolved system execution order ambiguities." )
441
458
}
442
459
}
443
460
}
@@ -875,18 +892,18 @@ mod tests {
875
892
HashSet :: from_iter( ambiguities) ,
876
893
HashSet :: from_iter( vec![
877
894
SystemOrderAmbiguity {
878
- system_names: (
895
+ system_names: [
879
896
"bevy_ecs::schedule::ambiguity_detection::tests::system_a" . to_string( ) ,
880
897
"bevy_ecs::schedule::ambiguity_detection::tests::system_b" . to_string( )
881
- ) ,
898
+ ] ,
882
899
conflicts: vec![ "bevy_ecs::schedule::ambiguity_detection::tests::R" . to_string( ) ] ,
883
900
segment: bevy_ecs:: schedule:: SystemStageSegment :: Parallel ,
884
901
} ,
885
902
SystemOrderAmbiguity {
886
- system_names: (
903
+ system_names: [
887
904
"bevy_ecs::schedule::ambiguity_detection::tests::system_a" . to_string( ) ,
888
905
"bevy_ecs::schedule::ambiguity_detection::tests::system_d" . to_string( )
889
- ) ,
906
+ ] ,
890
907
conflicts: vec![ "bevy_ecs::schedule::ambiguity_detection::tests::R" . to_string( ) ] ,
891
908
segment: bevy_ecs:: schedule:: SystemStageSegment :: Parallel ,
892
909
} ,
0 commit comments