File tree 3 files changed +86
-0
lines changed
3 files changed +86
-0
lines changed Original file line number Diff line number Diff line change
1
+ using Flecs . NET . Core ;
2
+ using Xunit ;
3
+
4
+ namespace Flecs . NET . Tests . Cpp
5
+ {
6
+ public class QueryBuilderTests
7
+ {
8
+ public QueryBuilderTests ( )
9
+ {
10
+ FlecsInternal . Reset ( ) ;
11
+ }
12
+
13
+ [ Fact ]
14
+ public void CascadeDesc ( )
15
+ {
16
+ using World world = World . Create ( ) ;
17
+
18
+ Entity tag = world . Entity ( ) ;
19
+ Entity foo = world . Entity ( ) ;
20
+ Entity bar = world . Entity ( ) ;
21
+
22
+ Entity e0 = world . Entity ( ) . Add ( tag ) ;
23
+ Entity e1 = world . Entity ( ) . IsA ( e0 ) ;
24
+ Entity e2 = world . Entity ( ) . IsA ( e1 ) ;
25
+ Entity e3 = world . Entity ( ) . IsA ( e2 ) ;
26
+
27
+ Query q = world . Query (
28
+ filter : world . FilterBuilder ( ) . With ( tag ) . Cascade ( ) . Descend ( )
29
+ ) ;
30
+
31
+ e1 . Add ( bar ) ;
32
+ e2 . Add ( foo ) ;
33
+
34
+ bool e1Found = false ;
35
+ bool e2Found = false ;
36
+ bool e3Found = false ;
37
+
38
+ int count = 0 ;
39
+ q . Each ( ( Entity e ) =>
40
+ {
41
+ count ++ ;
42
+
43
+ if ( e == e1 ) {
44
+ Assert . False ( e1Found ) ;
45
+ Assert . True ( e2Found ) ;
46
+ Assert . True ( e3Found ) ;
47
+ e1Found = true ;
48
+ }
49
+
50
+ if ( e == e2 ) {
51
+ Assert . False ( e1Found ) ;
52
+ Assert . False ( e2Found ) ;
53
+ Assert . True ( e3Found ) ;
54
+ e2Found = true ;
55
+ }
56
+
57
+ if ( e == e3 ) {
58
+ Assert . False ( e1Found ) ;
59
+ Assert . False ( e2Found ) ;
60
+ Assert . False ( e3Found ) ;
61
+ e3Found = true ;
62
+ }
63
+ } ) ;
64
+
65
+ Assert . True ( e1Found ) ;
66
+ Assert . True ( e2Found ) ;
67
+ Assert . True ( e3Found ) ;
68
+ Assert . Equal ( 3 , count ) ;
69
+ }
70
+ }
71
+ }
Original file line number Diff line number Diff line change @@ -310,6 +310,11 @@ public static partial class Ecs
310
310
/// </summary>
311
311
public const uint Cascade = EcsCascade ;
312
312
313
+ /// <summary>
314
+ /// Equivalent to <see cref="EcsDesc"/>
315
+ /// </summary>
316
+ public const uint Desc = EcsDesc ;
317
+
313
318
/// <summary>
314
319
/// Equivalent to <see cref="EcsParent"/>
315
320
/// </summary>
Original file line number Diff line number Diff line change @@ -160,6 +160,16 @@ public ref FilterBuilder Cascade<T>()
160
160
return ref Cascade ( Type < T > . Id ( World ) ) ;
161
161
}
162
162
163
+ /// <summary>
164
+ /// Use with cascade to iterate results in descending (bottom -> top) order
165
+ /// </summary>
166
+ /// <returns></returns>
167
+ public ref FilterBuilder Descend ( ) {
168
+ AssertTermId ( ) ;
169
+ CurrentTermId . flags |= EcsDesc ;
170
+ return ref this ;
171
+ }
172
+
163
173
/// <summary>
164
174
/// The parent flag is short for Up(EcsChildOf).
165
175
/// </summary>
You can’t perform that action at this time.
0 commit comments