From d3fbaa04183511dcc99a4d2bfd1364bd433ac035 Mon Sep 17 00:00:00 2001 From: Vectozavr <60608292+vectozavr@users.noreply.github.com> Date: Tue, 19 Jul 2022 16:35:14 +0700 Subject: [PATCH] refactoring --- CMakeLists.txt | 12 ++++++------ Shooter.h | 4 ++-- engine/Engine.cpp | 17 ++++++++++++++--- ShooterClient.cpp => network/ShooterClient.cpp | 6 +++--- ShooterClient.h => network/ShooterClient.h | 4 ++-- .../ShooterMsgType.cpp | 0 ShooterMsgType.h => network/ShooterMsgType.h | 0 ShooterServer.cpp => network/ShooterServer.cpp | 2 +- ShooterServer.h => network/ShooterServer.h | 4 ++-- 9 files changed, 30 insertions(+), 19 deletions(-) rename ShooterClient.cpp => network/ShooterClient.cpp (99%) rename ShooterClient.h => network/ShooterClient.h (97%) rename ShooterMsgType.cpp => network/ShooterMsgType.cpp (100%) rename ShooterMsgType.h => network/ShooterMsgType.h (100%) rename ShooterServer.cpp => network/ShooterServer.cpp (99%) rename ShooterServer.h => network/ShooterServer.h (93%) diff --git a/CMakeLists.txt b/CMakeLists.txt index a6b3626..3d994e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,10 +10,10 @@ add_executable(${CMAKE_PROJECT_NAME} Source.cpp Player.cpp Player.h - ShooterClient.cpp - ShooterClient.h - ShooterServer.cpp - ShooterServer.h + network/ShooterClient.cpp + network/ShooterClient.h + network/ShooterServer.cpp + network/ShooterServer.h weapon/Weapon.cpp weapon/Weapon.h weapon/Ak47.h @@ -26,8 +26,8 @@ add_executable(${CMAKE_PROJECT_NAME} Shooter.cpp Shooter.h ShooterConsts.h - ShooterMsgType.h - ShooterMsgType.cpp + network/ShooterMsgType.h + network/ShooterMsgType.cpp # 3d engine: engine/Consts.h engine/math/Vec4D.h diff --git a/Shooter.h b/Shooter.h index 25ec937..239fb09 100644 --- a/Shooter.h +++ b/Shooter.h @@ -11,8 +11,8 @@ #include "PlayerController.h" #include "engine/gui/Window.h" -#include "ShooterClient.h" -#include "ShooterServer.h" +#include "network/ShooterClient.h" +#include "network/ShooterServer.h" class Shooter final : public Engine { diff --git a/engine/Engine.cpp b/engine/Engine.cpp index 09ad22a..b0eaba5 100644 --- a/engine/Engine.cpp +++ b/engine/Engine.cpp @@ -169,10 +169,15 @@ void Engine::printDebugInfo() const { static_cast(255.0 * (1.0 - static_cast(width) / timerWidth)), 0, 100}); + std::string fps; + if(timer.elapsedSeconds() > 0) { + fps = std::to_string((int) (1.0 / timer.elapsedSeconds())); + } else { + fps = "inf"; + } screen->drawText( - timerName.substr(2, timerName.size()) + ":\t" + - std::to_string((int) (1.0 / timer.elapsedSeconds())) + " / s \t (" + + timerName.substr(2, timerName.size()) + ":\t" + fps + " / s \t (" + std::to_string((int) (100 * timer.elapsedSeconds() / totalTime)) + "%)", Vec2D{xPos + 10, yPos + height * i + 5}, 30, sf::Color(0, 0, 0, 150)); @@ -190,8 +195,14 @@ void Engine::printDebugInfo() const { static_cast(255.0 * (1.0 - static_cast(width) / timerWidth)), 0, 100}); + std::string fps; + if(totalTime - timeSum > 0) { + fps = std::to_string((int) (1.0 / (totalTime - timeSum))); + } else { + fps = "inf"; + } - screen->drawText("other:\t" + std::to_string((int) (1.0 / (totalTime - timeSum))) + " / s \t (" + + screen->drawText("other:\t" + fps + " / s \t (" + std::to_string((int) (100 * (totalTime - timeSum) / totalTime)) + "%)", Vec2D{xPos + 10, yPos + height * i + 5}, 30, sf::Color(0, 0, 0, 150)); diff --git a/ShooterClient.cpp b/network/ShooterClient.cpp similarity index 99% rename from ShooterClient.cpp rename to network/ShooterClient.cpp index 536830f..a4dc480 100644 --- a/ShooterClient.cpp +++ b/network/ShooterClient.cpp @@ -5,10 +5,10 @@ #include "ShooterClient.h" #include -#include "engine/utils/Log.h" -#include "engine/animation/Timeline.h" +#include "../engine/utils/Log.h" +#include "../engine/animation/Timeline.h" #include "ShooterMsgType.h" -#include "engine/animation/Animations.h" +#include "../engine/animation/Animations.h" void ShooterClient::updatePacket() { sf::Packet packet; diff --git a/ShooterClient.h b/network/ShooterClient.h similarity index 97% rename from ShooterClient.h rename to network/ShooterClient.h index 9d40cb1..04ae2d1 100644 --- a/ShooterClient.h +++ b/network/ShooterClient.h @@ -5,8 +5,8 @@ #ifndef SHOOTER_SHOOTERCLIENT_H #define SHOOTER_SHOOTERCLIENT_H -#include "engine/network/ClientUDP.h" -#include "Player.h" +#include "../engine/network/ClientUDP.h" +#include "../Player.h" class ShooterClient final : public ClientUDP { private: diff --git a/ShooterMsgType.cpp b/network/ShooterMsgType.cpp similarity index 100% rename from ShooterMsgType.cpp rename to network/ShooterMsgType.cpp diff --git a/ShooterMsgType.h b/network/ShooterMsgType.h similarity index 100% rename from ShooterMsgType.h rename to network/ShooterMsgType.h diff --git a/ShooterServer.cpp b/network/ShooterServer.cpp similarity index 99% rename from ShooterServer.cpp rename to network/ShooterServer.cpp index f72b56f..a3955ff 100644 --- a/ShooterServer.cpp +++ b/network/ShooterServer.cpp @@ -3,7 +3,7 @@ // #include "ShooterServer.h" -#include "engine/utils/Log.h" +#include "../engine/utils/Log.h" #include "ShooterMsgType.h" void ShooterServer::broadcast() { diff --git a/ShooterServer.h b/network/ShooterServer.h similarity index 93% rename from ShooterServer.h rename to network/ShooterServer.h index 99e51c4..1761992 100644 --- a/ShooterServer.h +++ b/network/ShooterServer.h @@ -5,8 +5,8 @@ #ifndef SHOOTER_SHOOTERSERVER_H #define SHOOTER_SHOOTERSERVER_H -#include "engine/network/ServerUDP.h" -#include "Player.h" +#include "../engine/network/ServerUDP.h" +#include "../Player.h" struct BonusInfo final { const Vec3D position{};