mirror of
https://github.com/Floriansylvain/SFMLplayground.git
synced 2026-08-19 11:43:24 +02:00
feat: total ball count display & ball spawning via Insert key
This commit is contained in:
@@ -21,7 +21,7 @@ DebugOverlay::DebugOverlay(const std::string &fontPath)
|
|||||||
|
|
||||||
void DebugOverlay::update(const int drawCalls, const float timeScale,
|
void DebugOverlay::update(const int drawCalls, const float timeScale,
|
||||||
const sf::RenderWindow &window,
|
const sf::RenderWindow &window,
|
||||||
const size_t threadCount,
|
const size_t threadCount, const size_t totalBalls,
|
||||||
const size_t ballsPerThread) {
|
const size_t ballsPerThread) {
|
||||||
const float frameTime = m_fpsClock.restart().asSeconds();
|
const float frameTime = m_fpsClock.restart().asSeconds();
|
||||||
|
|
||||||
@@ -54,7 +54,9 @@ void DebugOverlay::update(const int drawCalls, const float timeScale,
|
|||||||
oss << "Mouse: " << mousePos.x << ", " << mousePos.y << "\n";
|
oss << "Mouse: " << mousePos.x << ", " << mousePos.y << "\n";
|
||||||
oss << "Time scale: " << timeScale << "\n";
|
oss << "Time scale: " << timeScale << "\n";
|
||||||
oss << "\nThreads: " << threadCount;
|
oss << "\nThreads: " << threadCount;
|
||||||
oss << "\nBalls per thread: " << ballsPerThread;
|
oss << "\nBalls per thread: " << ballsPerThread << "\n";
|
||||||
|
|
||||||
|
oss << "\nTotal Balls: " << totalBalls;
|
||||||
|
|
||||||
m_text.setString(oss.str());
|
m_text.setString(oss.str());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class DebugOverlay {
|
|||||||
explicit DebugOverlay(const std::string &fontPath);
|
explicit DebugOverlay(const std::string &fontPath);
|
||||||
|
|
||||||
void update(int drawCalls, float timeScale, const sf::RenderWindow &window,
|
void update(int drawCalls, float timeScale, const sf::RenderWindow &window,
|
||||||
size_t threadCount, size_t ballsPerThread);
|
size_t threadCount, size_t totalBalls, size_t ballsPerThread);
|
||||||
|
|
||||||
void draw(sf::RenderWindow &window) const;
|
void draw(sf::RenderWindow &window) const;
|
||||||
|
|
||||||
|
|||||||
+7
-1
@@ -36,6 +36,7 @@ Game::Game()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Game::processKeyPressed(const sf::Event::KeyPressed &keyPressed) {
|
void Game::processKeyPressed(const sf::Event::KeyPressed &keyPressed) {
|
||||||
|
const auto mousePos = sf::Mouse::getPosition(m_window);
|
||||||
switch (keyPressed.code) {
|
switch (keyPressed.code) {
|
||||||
case sf::Keyboard::Key::Equal:
|
case sf::Keyboard::Key::Equal:
|
||||||
m_timeScale = std::min(10.0f, m_timeScale + 0.25f);
|
m_timeScale = std::min(10.0f, m_timeScale + 0.25f);
|
||||||
@@ -48,6 +49,11 @@ void Game::processKeyPressed(const sf::Event::KeyPressed &keyPressed) {
|
|||||||
break;
|
break;
|
||||||
case sf::Keyboard::Key::Delete:
|
case sf::Keyboard::Key::Delete:
|
||||||
if (!m_objects.empty()) m_objects.pop_back();
|
if (!m_objects.empty()) m_objects.pop_back();
|
||||||
|
break;
|
||||||
|
case sf::Keyboard::Key::Insert:
|
||||||
|
spawnBall(sf::Vector2f(static_cast<float>(mousePos.x),
|
||||||
|
static_cast<float>(mousePos.y)));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -224,7 +230,7 @@ void Game::render() {
|
|||||||
const size_t threadCount = m_threadPool.getThreadCount();
|
const size_t threadCount = m_threadPool.getThreadCount();
|
||||||
const size_t ballsPerThread = m_objects.size() / threadCount;
|
const size_t ballsPerThread = m_objects.size() / threadCount;
|
||||||
m_debugOverlay.update(m_drawCallCount + 2, m_timeScale, m_window,
|
m_debugOverlay.update(m_drawCallCount + 2, m_timeScale, m_window,
|
||||||
threadCount, ballsPerThread);
|
threadCount, m_objects.size(), ballsPerThread);
|
||||||
m_debugOverlay.draw(m_window);
|
m_debugOverlay.draw(m_window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user