| 207 | } |
| 208 | |
| 209 | void EntityMap::forAllEntities(EntityCallback const& callback, function<bool(EntityPtr const&, EntityPtr const&)> sortOrder) const { |
| 210 | // Even if there is no sort order, we still copy pointers to a temporary |
| 211 | // list, so that it is safe to call addEntity from the callback. |
| 212 | List<EntityPtr const*> allEntities; |
| 213 | allEntities.reserve(m_spatialMap.size()); |
| 214 | for (auto const& entry : m_spatialMap.entries()) |
| 215 | allEntities.append(&entry.second.value); |
| 216 | |
| 217 | if (sortOrder) { |
| 218 | allEntities.sort([&sortOrder](EntityPtr const* a, EntityPtr const* b) { |
| 219 | return sortOrder(*a, *b); |
| 220 | }); |
| 221 | } |
| 222 | |
| 223 | for (auto ptr : allEntities) |
| 224 | callback(*ptr); |
| 225 | } |
| 226 | |
| 227 | EntityPtr EntityMap::findEntity(RectF const& boundBox, EntityFilter const& filter) const { |
| 228 | EntityPtr res; |