Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/systems/collision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,23 @@ std::vector<sp::ecs::Entity> CollisionSystem::queryArea(glm::vec2 lowerBound, gl
return callback.list;
}

std::vector<sp::ecs::Entity> TransformQuery::queryArea(glm::vec2 lowerBound, glm::vec2 upperBound)
{
std::vector<sp::ecs::Entity> result;

for (auto [entity, transform, physics] : sp::ecs::Query<Transform, sp::ecs::optional<Physics>>())
{
auto radius = physics ? physics->getSize().x : 0;

if (transform.getPosition().x + radius < lowerBound.x || transform.getPosition().x - radius > upperBound.x)
continue;
if (transform.getPosition().y + radius < lowerBound.y || transform.getPosition().y - radius > upperBound.y)
continue;

result.push_back(entity);
}

return result;
}

}
10 changes: 9 additions & 1 deletion src/systems/collision.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,17 @@ class CollisionSystem
static void update(float delta);
static void addHandler(CollisionHandler* handler) { handlers.push_back(handler); }

// query all physics-enabled entities in an area
static std::vector<sp::ecs::Entity> queryArea(glm::vec2 lowerBound, glm::vec2 upperBound);
private:
static std::vector<CollisionHandler*> handlers;
};

}
class TransformQuery
{
public:
// query all entities in an area
static std::vector<sp::ecs::Entity> queryArea(glm::vec2 lowerBound, glm::vec2 upperBound);
};

}
Loading