From d6fbb58da83bac0ed019873c394842cd1e636681 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Thu, 14 Jul 2022 18:32:32 +0200 Subject: [PATCH] using log calls --- src/game/World.cpp | 15 +++++++-------- src/game/client/Client.cpp | 7 +++---- src/game/server/Lobby.cpp | 6 ++---- src/game/server/Server.cpp | 11 ++++++----- src/render/WorldRenderer.cpp | 7 +++---- src/render/shaders/ShaderProgram.cpp | 14 ++++++++------ src/updater/Updater.cpp | 8 +++++--- src/window/Display.cpp | 9 +++++---- 8 files changed, 39 insertions(+), 38 deletions(-) diff --git a/src/game/World.cpp b/src/game/World.cpp index 2b0d943..47b48dc 100644 --- a/src/game/World.cpp +++ b/src/game/World.cpp @@ -3,11 +3,10 @@ #include "protocol/Protocol.h" #include "game/BaseGame.h" #include "misc/Random.h" +#include "misc/Compression.h" +#include "misc/Format.h" #include -#include "misc/Compression.h" - -#include namespace td { namespace game { @@ -63,11 +62,11 @@ bool World::LoadMap(const protocol::WorldDataPacket* worldData) { bool World::LoadMapFromFile(const std::string& fileName) { DataBuffer buffer; if (!buffer.ReadFile(fileName)) { - std::cerr << "Failed to load map from file " << fileName << " !\n"; + utils::LOG(utils::format("[ERROR] : Failed to load map from file %s", fileName.c_str())); return false; } - std::cout << "Read file : " << fileName << " (File size : " << buffer.GetSize() << ")" << std::endl; + utils::LOG(utils::format("Read file : %s (File size : %u)", fileName.c_str(), buffer.GetSize())); DataBuffer mapHeaderPacketBuffer = utils::Decompress(buffer); DataBuffer mapDataPacketBuffer = utils::Decompress(buffer); @@ -91,11 +90,11 @@ bool World::SaveMap(const std::string& fileName) const { DataBuffer mapHeaderCompressed = utils::Compress(headerPacket.Serialize(false)); DataBuffer mapDataCompressed = utils::Compress(dataPacket.Serialize(false)); - std::cout << "Header Packet Size : " << mapHeaderCompressed.GetSize() << std::endl; - std::cout << "World Data Packet Size : " << mapDataCompressed.GetSize() << std::endl; + utils::LOG(utils::format("Header Packet Size : %u", mapHeaderCompressed.GetSize())); + utils::LOG(utils::format("World Data Packet Size : %u", mapDataCompressed.GetSize())); DataBuffer buffer = mapHeaderCompressed << mapDataCompressed; - std::cout << "Total Size : " << buffer.GetSize() << std::endl; + utils::LOG(utils::format("Total Size : %u", buffer.GetSize())); return buffer.WriteFile(fileName); } diff --git a/src/game/client/Client.cpp b/src/game/client/Client.cpp index fa6ad28..de265c2 100644 --- a/src/game/client/Client.cpp +++ b/src/game/client/Client.cpp @@ -1,6 +1,5 @@ #include "game/client/Client.h" - -#include +#include "misc/Format.h" namespace td { namespace client { @@ -12,7 +11,7 @@ bool Client::Connect(const network::IPAddresses& addresses, std::uint16_t port) return true; } } - std::cout << "Failed to connect !\n"; + utils::LOG("Failed to connect !"); return false; } @@ -39,7 +38,7 @@ void Client::Tick(std::uint64_t delta) { return; m_Connected = m_Connexion.UpdateSocket(); if (!m_Connected) { - std::cout << "Disconnected ! (Reason : " << m_Connexion.GetDisconnectReason() << ")\n"; + utils::LOG(utils::format("Disconnected ! (Reason : %s)", m_Connexion.GetDisconnectReason().c_str())); Reset(); } else { m_Game->Tick(delta); diff --git a/src/game/server/Lobby.cpp b/src/game/server/Lobby.cpp index 9c54020..e11a5ac 100644 --- a/src/game/server/Lobby.cpp +++ b/src/game/server/Lobby.cpp @@ -3,8 +3,6 @@ #include "misc/Time.h" -#include - #ifdef NDEBUG #define MIN_PLAYER_WAITING 2 #else @@ -53,7 +51,7 @@ void Lobby::SendTimeRemaining() { void Lobby::OnPlayerJoin(std::uint8_t playerID) { if (m_GameStarted) return; - std::cout << "(Server) Player Joined Lobby !\n"; + utils::LOG("(Server) Player Joined Lobby !"); m_Players.push_back(playerID); if (m_Players.size() == MIN_PLAYER_WAITING) { // start timer if a second player join the match m_StartTimerTime = utils::GetTime(); @@ -65,7 +63,7 @@ void Lobby::OnPlayerJoin(std::uint8_t playerID) { void Lobby::OnPlayerLeave(std::uint8_t playerID) { if (m_GameStarted) return; - std::cout << "(Server) Player Leaved Lobby !\n"; + utils::LOG("(Server) Player Leaved Lobby !"); auto it = std::find(m_Players.begin(), m_Players.end(), playerID); if (it == m_Players.end()) diff --git a/src/game/server/Server.cpp b/src/game/server/Server.cpp index 9eb6214..bacbbc4 100644 --- a/src/game/server/Server.cpp +++ b/src/game/server/Server.cpp @@ -1,7 +1,8 @@ #include "game/server/Server.h" -#include #include "protocol/PacketFactory.h" +#include "misc/Format.h" + namespace td { namespace server { @@ -44,14 +45,14 @@ void Server::StopThread() { bool Server::Start(std::uint16_t port) { if (!m_Listener.Listen(port, 10)) { - std::cout << "Failed to bind port " << port << " !\n"; + utils::LOG(utils::format("Failed to bind port %u !", port)); return false; } if (!m_Listener.SetBlocking(false)) { - std::cout << "Failed to block server socket !\n"; + utils::LOG("Failed to block server socket !"); return false; } - std::cout << "Server started at port " << port << " !\n"; + utils::LOG(utils::format("Server started at port %u !", port)); m_TickCounter.Reset(); m_ServerRunning = true; StartThread(); @@ -65,7 +66,7 @@ void Server::Clean() { m_Connections.clear(); GetPlayers().clear(); - std::cout << "Server successfully stopped !\n"; + utils::LOG("Server successfully stopped !"); } void Server::Stop() { diff --git a/src/render/WorldRenderer.cpp b/src/render/WorldRenderer.cpp index 8c40387..1c0ea4e 100644 --- a/src/render/WorldRenderer.cpp +++ b/src/render/WorldRenderer.cpp @@ -6,8 +6,7 @@ #include "window/Display.h" #include "game/client/ClientGame.h" #include "game/client/Client.h" - -#include +#include "misc/Format.h" namespace td { namespace render { @@ -25,11 +24,11 @@ ImVec4 WorldRenderer::GetImGuiTeamColor(game::TeamColor color) { } void WorldRenderer::LoadModels() { - std::cout << "World Created !\n"; + utils::LOGD("World Created !"); m_WorldVao = std::make_unique(std::move(WorldLoader::LoadWorldModel(m_World))); m_MobVao = std::make_unique(std::move(WorldLoader::LoadMobModel())); m_SelectTileVao = std::make_unique(std::move(WorldLoader::LoadTileSelectModel())); - std::cout << "Vertex Count : " << m_WorldVao->GetVertexCount() << std::endl; + utils::LOGD(utils::format("Vertex Count : %u", m_WorldVao->GetVertexCount())); } WorldRenderer::WorldRenderer(game::World* world, client::ClientGame* client) : m_Client(client), m_Renderer(m_Client->GetRenderer()), m_World(world), m_Zoom(0.1) { diff --git a/src/render/shaders/ShaderProgram.cpp b/src/render/shaders/ShaderProgram.cpp index c99fcc3..d41afee 100755 --- a/src/render/shaders/ShaderProgram.cpp +++ b/src/render/shaders/ShaderProgram.cpp @@ -6,10 +6,13 @@ */ #include "render/shaders/ShaderProgram.h" +#include "misc/Log.h" +#include "misc/Format.h" #include #include #include +#include #include @@ -39,7 +42,7 @@ void ShaderProgram::Stop() const { int ShaderProgram::GetUniformLocation(const std::string& uniformName) const { const int location = glGetUniformLocation(m_ProgramID, uniformName.c_str()); if (location == -1) { - std::cout << "Warning ! Uniform variable " << uniformName << " not found !\n"; + utils::LOGD(utils::format("Warning ! Uniform variable %s not found !", uniformName.c_str())); } return location; } @@ -118,15 +121,14 @@ unsigned int ShaderProgram::LoadShader(const std::string& source, GLenum type) { GLint compilesuccessful; glGetShaderiv(shaderID, GL_COMPILE_STATUS, &compilesuccessful); if (compilesuccessful == false) { - std::cout << "Could not compile shader !\n"; GLsizei size; glGetShaderiv(shaderID, GL_INFO_LOG_LENGTH, &size); std::vector shaderError(static_cast(size)); glGetShaderInfoLog(shaderID, size, &size, shaderError.data()); - std::cout << shaderError.data() << std::endl; -#ifdef __ANDROID__ - __android_log_print(ANDROID_LOG_ERROR, "TRACKERS", "Could not compile shader !\n %s", error); -#endif + + utils::LOG("Could not compile shader !"); + + utils::LOG(shaderError.data()); } return shaderID; } diff --git a/src/updater/Updater.cpp b/src/updater/Updater.cpp index 00d8879..f0d5b04 100644 --- a/src/updater/Updater.cpp +++ b/src/updater/Updater.cpp @@ -2,6 +2,8 @@ #include "misc/Platform.h" #include "misc/DataBuffer.h" +#include "misc/Log.h" +#include "misc/Format.h" #include "network/HttpLib.h" @@ -24,15 +26,15 @@ bool Updater::CheckUpdate() { // we only look at the first line m_LastVersion = m_LastVersion.substr(0, m_LastVersion.find('\n')); - std::cout << "Current version : [" << GetCurrentVersion() << "]\n"; - std::cout << "Last version : [" << m_LastVersion << "]\n"; + utils::LOG(utils::format("Current version : [%s]", GetCurrentVersion().c_str())); + utils::LOG(utils::format("Last version : [%s]", m_LastVersion.c_str())); if (currentVersion != m_LastVersion) { return true; } return false; } else { - std::cerr << "Error : " << res.error() << std::endl; + utils::LOG(utils::format("Error : %u", res.error())); return false; } diff --git a/src/window/Display.cpp b/src/window/Display.cpp index dec62f5..0d38247 100644 --- a/src/window/Display.cpp +++ b/src/window/Display.cpp @@ -8,14 +8,16 @@ #include "window/Display.h" #define GLFW_INCLUDE_NONE #include "render/gui/TowerGui.h" -#include -#include #include #include "game/GameManager.h" #include "render/Renderer.h" #include "render/WorldRenderer.h" #include "../render/gui/imgui/imgui_impl_sdl.h" +#include "misc/Log.h" +#include "misc/Format.h" +#include +#include #include namespace Display { @@ -94,8 +96,7 @@ bool Create() { mask_desc = "?"; } - std::cout << "GL Context: " << major << "." << minor << " " << mask_desc - << ", Color : R" << r << "G" << g << "B" << b << "A" << a << ", Depth bits: " << depth << std::endl; + td::utils::LOG(td::utils::format("GL Context : %i.%i %s, Color : R:%i G:%i B:%i A:%i, Depth bits : %i", major, minor, mask_desc, r, g, b, a, depth)); SDL_GL_MakeCurrent(window, glContext);