@@ -304,9 +304,9 @@ const bool hasWheel = w.has(car, wheel);
304
304
305
305
// Check if entities hidden behind the iterator have Velocity (via iterator).
306
306
ecs::Query q = w.query().any<Position, Velocity>();
307
- q.each([&](ecs::Iter iter ) {
308
- const bool hasPosition = iter .has<Position>();
309
- const bool hasVelocity = iter .has<Velocity>();
307
+ q.each([&](ecs::Iter& it ) {
308
+ const bool hasPosition = it .has<Position>();
309
+ const bool hasVelocity = it .has<Velocity>();
310
310
...
311
311
});
312
312
```
@@ -319,9 +319,9 @@ auto v = w.add<Velocity>().entity;
319
319
320
320
// Check if entities hidden behind the iterator have Velocity (via iterator).
321
321
ecs::Query q = w.query().any(p).any(v);
322
- q.each([&](ecs::Iter iter ) {
323
- const bool hasPosition = iter .has(p);
324
- const bool hasVelocity = iter .has(v);
322
+ q.each([&](ecs::Iter& it ) {
323
+ const bool hasPosition = it .has(p);
324
+ const bool hasVelocity = it .has(v);
325
325
...
326
326
});
327
327
```
@@ -622,33 +622,33 @@ There are three types of iterators:
622
622
ecs::Query q = w.query();
623
623
q.all<Position&, Velocity>();
624
624
625
- q.each([](ecs::IterAll iter ) {
626
- auto p = iter .view_mut<Position >(); // Read-write access to Position
627
- auto v = iter .view<Velocity >(); // Read-only access to Velocity
625
+ q.each([](ecs::IterAll& it ) {
626
+ auto p = it .view_mut<Position >(); // Read-write access to Position
627
+ auto v = it .view<Velocity >(); // Read-only access to Velocity
628
628
629
629
// Iterate over all enabled entities and update their x-axis position
630
- GAIA_EACH (iter ) {
631
- if (!iter .enabled(i))
630
+ GAIA_EACH (it ) {
631
+ if (!it .enabled(i))
632
632
return;
633
633
p[ i] .x += 1.f;
634
634
}
635
635
636
636
// Iterate over all entities and update their position based on their velocity
637
- GAIA_EACH (iter ) {
637
+ GAIA_EACH (it ) {
638
638
p[ i] .x += v[ i] .x * dt;
639
639
p[ i] .y += v[ i] .y * dt;
640
640
p[ i] .z += v[ i] .z * dt;
641
641
}
642
642
});
643
643
```
644
644
645
- *** GAIA_EACH(iter )*** is simply a shortcut for
645
+ *** GAIA_EACH(it )*** is simply a shortcut for
646
646
```
647
- for (uint32_t i=0; i<iter .size(); ++i)
647
+ for (uint32_t i=0; i<it .size(); ++i)
648
648
```
649
649
A similar macro exists where you can specify the variable name. It is called *** GAIA_EACH_ (iter,k)***
650
650
```
651
- for (uint32_t k=0; k<iter .size(); ++k)
651
+ for (uint32_t k=0; k<it .size(); ++k)
652
652
```
653
653
654
654
### Constraints
@@ -685,21 +685,21 @@ q.arr(entities, ecs::Query::Constraint::AcceptAll);
685
685
// Fills the array with only e1 because e1 is disabled.
686
686
q.arr(entities, ecs::Query::Constraint::DisabledOnly);
687
687
688
- q.each([ ] (ecs::Iter iter ) {
689
- auto p = iter .view_mut<Position >(); // Read-Write access to Position
688
+ q.each([ ] (ecs::Iter& it ) {
689
+ auto p = it .view_mut<Position >(); // Read-Write access to Position
690
690
// Iterates over enabled entities
691
- GAIA_EACH (iter ) p[ i] = {}; // reset the position of each enabled entity
691
+ GAIA_EACH (it ) p[ i] = {}; // reset the position of each enabled entity
692
692
});
693
- q.each([](ecs::IterDisabled iter ) {
694
- auto p = iter .view_mut<Position >(); // Read-Write access to Position
693
+ q.each([](ecs::IterDisabled& it ) {
694
+ auto p = it .view_mut<Position >(); // Read-Write access to Position
695
695
// Iterates over disabled entities
696
- GAIA_EACH (iter ) p[ i] = {}; // reset the position of each disabled entity
696
+ GAIA_EACH (it ) p[ i] = {}; // reset the position of each disabled entity
697
697
});
698
- q.each([](ecs::IterAll iter ) {
699
- auto p = iter .view_mut<Position >(); // Read-Write access to Position
698
+ q.each([](ecs::IterAll& it ) {
699
+ auto p = it .view_mut<Position >(); // Read-Write access to Position
700
700
// Iterates over all entities
701
- GAIA_EACH (iter ) {
702
- if (iter .enabled(i)) {
701
+ GAIA_EACH (it ) {
702
+ if (it .enabled(i)) {
703
703
p[ i] = {}; // reset the position of each enabled entity
704
704
}
705
705
}
@@ -716,7 +716,7 @@ struct Disabled {};
716
716
e.add<Disabled >(); // disable entity
717
717
718
718
ecs::Query q = w.query().all<Position, Disabled>;
719
- q.each([ &] (ecs::Iter iter ){
719
+ q.each([ &] (ecs::Iter& it ){
720
720
// Processes all disabled entities
721
721
});
722
722
@@ -1118,25 +1118,25 @@ struct VelocitySoA {
1118
1118
...
1119
1119
1120
1120
ecs::Query q = w.query().all<PositionSoA&, VelocitySoA>;
1121
- q.each([ ] (ecs::Iter iter ) {
1121
+ q.each([ ] (ecs::Iter& it ) {
1122
1122
// Position
1123
- auto vp = iter .view_mut<PositionSoA >(); // read-write access to PositionSoA
1123
+ auto vp = it .view_mut<PositionSoA >(); // read-write access to PositionSoA
1124
1124
auto px = vp.set<0>(); // continuous block of "x" from PositionSoA
1125
1125
auto py = vp.set<1>(); // continuous block of "y" from PositionSoA
1126
1126
auto pz = vp.set<2>(); // continuous block of "z" from PositionSoA
1127
1127
1128
1128
// Velocity
1129
- auto vv = iter .view<VelocitySoA >(); // read-only access to VelocitySoA
1129
+ auto vv = it .view<VelocitySoA >(); // read-only access to VelocitySoA
1130
1130
auto vx = vv.get<0>(); // continuous block of "x" from VelocitySoA
1131
1131
auto vy = vv.get<1>(); // continuous block of "y" from VelocitySoA
1132
1132
auto vz = vv.get<2>(); // continuous block of "z" from VelocitySoA
1133
1133
1134
1134
// Handle x coordinates
1135
- GAIA_EACH(iter ) px[ i] += vx[ i] * dt;
1135
+ GAIA_EACH(it ) px[ i] += vx[ i] * dt;
1136
1136
// Handle y coordinates
1137
- GAIA_EACH(iter ) py[ i] += vy[ i] * dt;
1137
+ GAIA_EACH(it ) py[ i] += vy[ i] * dt;
1138
1138
// Handle z coordinates
1139
- GAIA_EACH(iter ) pz[ i] += vz[ i] * dt;
1139
+ GAIA_EACH(it ) pz[ i] += vz[ i] * dt;
1140
1140
1141
1141
/*
1142
1142
You can even use SIMD intrinsics now without a worry.
@@ -1146,14 +1146,14 @@ q.each([](ecs::Iter iter) {
1146
1146
The code bellow uses x86 SIMD intrinsics.
1147
1147
uint32_t i = 0;
1148
1148
// Process SSE-sized blocks first
1149
- for (; i < iter .size(); i+=4) {
1149
+ for (; i < it .size(); i+=4) {
1150
1150
const auto pVec = _ mm_load_ps(px.data() + i);
1151
1151
const auto vVec = _ mm_load_ps(vx.data() + i);
1152
1152
const auto respVec = _ mm_fmadd_ps(vVec, dtVec, pVec);
1153
1153
_ mm_store_ps(px.data() + i, respVec);
1154
1154
}
1155
1155
// Process the rest of the elements
1156
- for (; i < iter .size(); ++i) {
1156
+ for (; i < it .size(); ++i) {
1157
1157
...
1158
1158
}
1159
1159
* /
0 commit comments