MCPcopy Create free account
hub / github.com/alecthomas/entityx / collect

Method collect

examples/example.cc:194–215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

192 }
193
194 void collect(ex::EntityManager &entities) {
195 ex::ComponentHandle<Body> body;
196 ex::ComponentHandle<Collideable> collideable;
197 for (ex::Entity entity : entities.entities_with_components(body, collideable)) {
198 unsigned int
199 left = static_cast<int>(body->position.x - collideable->radius) / PARTITIONS,
200 top = static_cast<int>(body->position.y - collideable->radius) / PARTITIONS,
201 right = static_cast<int>(body->position.x + collideable->radius) / PARTITIONS,
202 bottom = static_cast<int>(body->position.y + collideable->radius) / PARTITIONS;
203 Candidate candidate {body->position, collideable->radius, entity};
204 unsigned int slots[4] = {
205 left + top * size.x,
206 right + top * size.x,
207 left + bottom * size.x,
208 right + bottom * size.x,
209 };
210 grid[slots[0]].push_back(candidate);
211 if (slots[0] != slots[1]) grid[slots[1]].push_back(candidate);
212 if (slots[1] != slots[2]) grid[slots[2]].push_back(candidate);
213 if (slots[2] != slots[3]) grid[slots[3]].push_back(candidate);
214 }
215 }
216
217 void collide(ex::EventManager &events) {
218 for (const std::vector<Candidate> &candidates : grid) {

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected