feat: batched debug lines draws

This commit is contained in:
Florian Sylvain
2025-05-11 01:41:19 +02:00
parent f276d243ec
commit 9b65954776
4 changed files with 34 additions and 18 deletions
+8 -3
View File
@@ -11,7 +11,8 @@
Game::Game()
: m_inputManager(
std::bind(&Game::processKeyPressed, this, std::placeholders::_1),
std::bind(&Game::processMousePressed, this, std::placeholders::_1)) {
std::bind(&Game::processMousePressed, this, std::placeholders::_1)),
m_debugLines(sf::PrimitiveType::Lines) {
m_window.create(sf::VideoMode({Constants::WIDTH, Constants::HEIGHT}),
"SFML Playground");
m_window.setVerticalSyncEnabled(true);
@@ -58,16 +59,20 @@ void Game::update() {
void Game::render() {
m_window.clear(sf::Color::Black);
m_debugLines.clear();
for (const auto &object : m_objects) {
object->draw(m_window);
auto *ball = dynamic_cast<Ball *>(object.get());
if (!ball) continue;
DebugDraw::drawDirectionLine(m_window, ball);
DebugDraw::drawVelocityLine(m_window, ball);
DebugDraw::addDirectionLine(m_debugLines, ball, m_window);
DebugDraw::addVelocityLine(m_debugLines, ball);
}
DebugDraw::drawBatchedLines(m_window, m_debugLines);
m_window.display();
}