add entities.get_all(...), .get_all_in_box(...), .get_all_in_radius(...)
This commit is contained in:
@@ -503,3 +503,20 @@ std::vector<Entity> Entities::getAllInside(AABB aabb) {
|
||||
}
|
||||
return collected;
|
||||
}
|
||||
|
||||
std::vector<Entity> Entities::getAllInRadius(glm::vec3 center, float radius) {
|
||||
std::vector<Entity> collected;
|
||||
auto view = registry.view<Transform>();
|
||||
for (auto [entity, transform] : view.each()) {
|
||||
if (glm::distance2(transform.pos, center) <= radius*radius) {
|
||||
const auto& found = uids.find(entity);
|
||||
if (found == uids.end()) {
|
||||
continue;
|
||||
}
|
||||
if (auto wrapper = get(found->second)) {
|
||||
collected.push_back(*wrapper);
|
||||
}
|
||||
}
|
||||
}
|
||||
return collected;
|
||||
}
|
||||
|
||||
@@ -210,6 +210,7 @@ public:
|
||||
void onSave(const Entity& entity);
|
||||
bool hasBlockingInside(AABB aabb);
|
||||
std::vector<Entity> getAllInside(AABB aabb);
|
||||
std::vector<Entity> getAllInRadius(glm::vec3 center, float radius);
|
||||
void despawn(entityid_t id);
|
||||
dynamic::Value serialize(const Entity& entity);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user