mirror of
https://github.com/Floriansylvain/SFMLplayground.git
synced 2026-08-19 11:43:24 +02:00
feat: debug toggle button (F3)
This commit is contained in:
+15
-12
@@ -18,7 +18,6 @@ Game::Game()
|
|||||||
m_window.create(sf::VideoMode({Constants::WIDTH, Constants::HEIGHT}),
|
m_window.create(sf::VideoMode({Constants::WIDTH, Constants::HEIGHT}),
|
||||||
"SFML Playground");
|
"SFML Playground");
|
||||||
m_window.setVerticalSyncEnabled(true);
|
m_window.setVerticalSyncEnabled(true);
|
||||||
m_timeScale = 1.0f;
|
|
||||||
m_objects.clear();
|
m_objects.clear();
|
||||||
|
|
||||||
auto balls = BallFactory::generateBalls();
|
auto balls = BallFactory::generateBalls();
|
||||||
@@ -35,6 +34,10 @@ void Game::processKeyPressed(const sf::Event::KeyPressed &kP) {
|
|||||||
m_timeScale -= 0.25f;
|
m_timeScale -= 0.25f;
|
||||||
if (m_timeScale < 0.25f) m_timeScale = 0.25f;
|
if (m_timeScale < 0.25f) m_timeScale = 0.25f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (kP.code == sf::Keyboard::Key::F3) {
|
||||||
|
m_toggleDebug = !m_toggleDebug;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::processMousePressed(const sf::Event::MouseButtonPressed &mP) {
|
void Game::processMousePressed(const sf::Event::MouseButtonPressed &mP) {
|
||||||
@@ -67,20 +70,20 @@ void Game::render() {
|
|||||||
|
|
||||||
for (const auto &object : m_objects) {
|
for (const auto &object : m_objects) {
|
||||||
object->draw(m_window);
|
object->draw(m_window);
|
||||||
m_drawCallCount++;
|
++m_drawCallCount;
|
||||||
|
|
||||||
auto *ball = dynamic_cast<Ball *>(object.get());
|
if (!m_toggleDebug) continue;
|
||||||
if (!ball) continue;
|
if (auto *ball = dynamic_cast<Ball *>(object.get())) {
|
||||||
|
DebugDraw::addDirectionLine(m_debugLines, ball, m_window);
|
||||||
DebugDraw::addDirectionLine(m_debugLines, ball, m_window);
|
DebugDraw::addVelocityLine(m_debugLines, ball);
|
||||||
DebugDraw::addVelocityLine(m_debugLines, ball);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugDraw::drawBatchedLines(m_window, m_debugLines);
|
if (m_toggleDebug) {
|
||||||
m_drawCallCount++;
|
DebugDraw::drawBatchedLines(m_window, m_debugLines);
|
||||||
|
m_debugOverlay.update(m_drawCallCount + 2, m_timeScale, m_window);
|
||||||
m_debugOverlay.update(m_drawCallCount, m_timeScale, m_window);
|
m_debugOverlay.draw(m_window);
|
||||||
m_debugOverlay.draw(m_window);
|
}
|
||||||
|
|
||||||
m_window.display();
|
m_window.display();
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -19,7 +19,7 @@ class PhysicalObject;
|
|||||||
|
|
||||||
class Game {
|
class Game {
|
||||||
private:
|
private:
|
||||||
float m_timeScale;
|
float m_timeScale = 1.0f;
|
||||||
sf::RenderWindow m_window;
|
sf::RenderWindow m_window;
|
||||||
std::vector<std::unique_ptr<PhysicalObject>> m_objects;
|
std::vector<std::unique_ptr<PhysicalObject>> m_objects;
|
||||||
sf::Clock m_clock;
|
sf::Clock m_clock;
|
||||||
@@ -27,6 +27,8 @@ class Game {
|
|||||||
sf::VertexArray m_debugLines;
|
sf::VertexArray m_debugLines;
|
||||||
int m_drawCallCount = 0;
|
int m_drawCallCount = 0;
|
||||||
DebugOverlay m_debugOverlay;
|
DebugOverlay m_debugOverlay;
|
||||||
|
bool m_toggleDebug = false;
|
||||||
|
|
||||||
void processKeyPressed(const sf::Event::KeyPressed& keyPressed);
|
void processKeyPressed(const sf::Event::KeyPressed& keyPressed);
|
||||||
void processMousePressed(const sf::Event::MouseButtonPressed& mousePressed);
|
void processMousePressed(const sf::Event::MouseButtonPressed& mousePressed);
|
||||||
void handleMouseClick(const sf::Vector2i& mousePos);
|
void handleMouseClick(const sf::Vector2i& mousePos);
|
||||||
|
|||||||
Reference in New Issue
Block a user