@@ -34,13 +34,13 @@ int main(int argc, char *argv[]) {
34
34
ecs_entity_t e1 = ecs_new_id (ecs );
35
35
ecs_set_pair (ecs , e1 , Requires , Gigawatts , {1.21 });
36
36
const Requires * r = ecs_get_pair (ecs , e1 , Requires , Gigawatts );
37
- printf ("requires: %f \n" , r -> amount );
37
+ printf ("requires: %.2f \n" , r -> amount );
38
38
39
39
// The component can be either the first or second part of a pair:
40
40
ecs_entity_t e2 = ecs_new_id (ecs );
41
41
ecs_set_pair_second (ecs , e2 , Gigawatts , Requires , {1.21 });
42
42
r = ecs_get_pair_second (ecs , e2 , Gigawatts , Requires );
43
- printf ("requires: %f \n" , r -> amount );
43
+ printf ("requires: %.2f \n" , r -> amount );
44
44
45
45
// Note that <Requires, Gigawatts> and <Gigawatts, Requires> are two
46
46
// different pairs, and can be added to an entity at the same time.
@@ -50,7 +50,7 @@ int main(int argc, char *argv[]) {
50
50
ecs_entity_t e3 = ecs_new_id (ecs );
51
51
ecs_set_pair (ecs , e3 , Expires , ecs_id (Position ), {0.5 });
52
52
const Expires * e = ecs_get_pair (ecs , e3 , Expires , ecs_id (Position ));
53
- printf ("expires: %f \n" , e -> timeout );
53
+ printf ("expires: %.1f \n" , e -> timeout );
54
54
55
55
// You can prevent a pair from assuming the type of a component by adding
56
56
// the Tag property to a relationship:
@@ -84,12 +84,29 @@ int main(int argc, char *argv[]) {
84
84
printf ("%s\n" , type_str );
85
85
ecs_os_free (type_str );
86
86
87
+ // When querying for a relationship, provide both parts of the pair:
88
+ ecs_query_t * q = ecs_query_init (ecs , & (ecs_query_desc_t ) {
89
+ .filter .terms = {
90
+ { .id = ecs_pair (ecs_id (Requires ), Gigawatts ) }
91
+ }
92
+ });
93
+
94
+ // When iterating, always use the pair type:
95
+ ecs_iter_t it = ecs_query_iter (ecs , q );
96
+ while (ecs_query_next (& it )) {
97
+ r = ecs_term (& it , Requires , 1 );
98
+ for (int i = 0 ; i < it .count ; i ++ ) {
99
+ printf ("requires %.2f gigawatts\n" , r [i ].amount );
100
+ }
101
+ }
102
+
87
103
// Output:
88
- // requires: 1.210000
89
- // requires: 1.210000
90
- // expires: 0.500000
104
+ // requires: 1.21
105
+ // requires: 1.21
106
+ // expires: 0.5
91
107
// Requires
92
108
// Requires
93
109
// Expires
94
110
// 0
111
+ // requires 1.21 gigawatts
95
112
}
0 commit comments