From 61341d1b0509e1a14b9c6c568b3e68867e692401 Mon Sep 17 00:00:00 2001 From: Vectozavr <60608292+vectozavr@users.noreply.github.com> Date: Sat, 30 Oct 2021 16:39:44 +0700 Subject: [PATCH] Huge refactoring v3 --- Shooter.cpp | 1 - engine/Consts.h | 3 ++- engine/Engine.cpp | 22 ++++++++++++++++++---- engine/Engine.h | 2 +- engine/Screen.cpp | 15 --------------- engine/Screen.h | 2 -- 6 files changed, 21 insertions(+), 24 deletions(-) diff --git a/Shooter.cpp b/Shooter.cpp index f708529..fb4a311 100644 --- a/Shooter.cpp +++ b/Shooter.cpp @@ -70,7 +70,6 @@ void Shooter::InitNetwork() { void Shooter::start() { // This code executed once in the beginning: - setDebugText(false); setUpdateWorld(false); screen->setMouseCursorVisible(true); diff --git a/engine/Consts.h b/engine/Consts.h index b46af7c..ccaeb98 100644 --- a/engine/Consts.h +++ b/engine/Consts.h @@ -14,7 +14,8 @@ namespace Consts { const std::string PROJECT_NAME = "engine"; const bool USE_LOG_FILE = true; const bool USE_OPEN_GL = true; - const bool SHOW_COORDINATES = true; + const bool SHOW_DEBUG_INFO = false; + const bool SHOW_FPS_COUNTER = true; const double PI = 3.14159265358979323846264338327950288; const double EPS = 0.000001; diff --git a/engine/Engine.cpp b/engine/Engine.cpp index d8a20c5..667310c 100644 --- a/engine/Engine.cpp +++ b/engine/Engine.cpp @@ -69,6 +69,10 @@ void Engine::create(int screenWidth, int screenHeight, const std::string &name, _triPerSec = camera->buffSize() * Time::fps(); } + if (Consts::SHOW_FPS_COUNTER) { + screen->drawText(std::to_string(Time::fps()) + " fps", Vec2D(screen->width() - 100, 10), 25, sf::Color(100,100,100)); + } + printDebugText(); gui(); } @@ -91,8 +95,9 @@ void Engine::exit() { } void Engine::printDebugText() const { + if (_debugText) { - std::string str = _name + "\n\n X: " + + std::string text = _name + "\n\n X: " + std::to_string((camera->position().x())) + "\n Y: " + std::to_string((camera->position().y())) + "\n Z: " + std::to_string((camera->position().z())) + "\n\n" + @@ -100,10 +105,19 @@ void Engine::printDebugText() const { std::to_string(screen->height()) + "\t" + std::to_string(Time::fps()) + " fps"; if(_useOpenGL) { - str += "\n Using OpenGL acceleration"; + text += "\n Using OpenGL acceleration"; } else { - str += "\n" + std::to_string((int) _triPerSec) + " tris/s"; + text += "\n" + std::to_string((int) _triPerSec) + " tris/s"; } - screen->debugText(str); + + sf::Text t; + + t.setFont(*ResourceManager::loadFont(Consts::THIN_FONT)); + t.setString(text); + t.setCharacterSize(30); + t.setFillColor(sf::Color::Black); + t.setPosition(screen->width() - 400, 10); + + screen->drawText(t); } } diff --git a/engine/Engine.h b/engine/Engine.h index 1b2f3a2..46363c1 100644 --- a/engine/Engine.h +++ b/engine/Engine.h @@ -19,7 +19,7 @@ private: double _triPerSec = 0; bool _updateWorld = true; - bool _debugText = Consts::SHOW_COORDINATES; + bool _debugText = Consts::SHOW_DEBUG_INFO; bool _useOpenGL = Consts::USE_OPEN_GL; void printDebugText() const; diff --git a/engine/Screen.cpp b/engine/Screen.cpp index b330583..596046a 100644 --- a/engine/Screen.cpp +++ b/engine/Screen.cpp @@ -72,21 +72,6 @@ void Screen::close() { _window->close(); } - -void Screen::debugText(const std::string& text) { - sf::Text t; - - t.setFont(*ResourceManager::loadFont(Consts::THIN_FONT)); - t.setString(text); - t.setCharacterSize(30); - t.setFillColor(sf::Color::Black); - t.setPosition(10, 50); - - _window->pushGLStates(); - _window->draw(t); - _window->popGLStates(); -} - void Screen::setMouseCursorVisible(bool visible) { _window->setMouseCursorVisible(visible); } diff --git a/engine/Screen.h b/engine/Screen.h index e3dd38c..b5ab6ed 100644 --- a/engine/Screen.h +++ b/engine/Screen.h @@ -48,8 +48,6 @@ public: void close(); - void debugText(const std::string& text); - void setMouseCursorVisible(bool visible); // OpenGL functions