using log calls

This commit is contained in:
2022-07-14 18:32:32 +02:00
parent 66376eaeda
commit d6fbb58da8
8 changed files with 39 additions and 38 deletions

View File

@@ -3,11 +3,10 @@
#include "protocol/Protocol.h" #include "protocol/Protocol.h"
#include "game/BaseGame.h" #include "game/BaseGame.h"
#include "misc/Random.h" #include "misc/Random.h"
#include "misc/Compression.h"
#include "misc/Format.h"
#include <cmath> #include <cmath>
#include "misc/Compression.h"
#include <iostream>
namespace td { namespace td {
namespace game { namespace game {
@@ -63,11 +62,11 @@ bool World::LoadMap(const protocol::WorldDataPacket* worldData) {
bool World::LoadMapFromFile(const std::string& fileName) { bool World::LoadMapFromFile(const std::string& fileName) {
DataBuffer buffer; DataBuffer buffer;
if (!buffer.ReadFile(fileName)) { 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; 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 mapHeaderPacketBuffer = utils::Decompress(buffer);
DataBuffer mapDataPacketBuffer = 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 mapHeaderCompressed = utils::Compress(headerPacket.Serialize(false));
DataBuffer mapDataCompressed = utils::Compress(dataPacket.Serialize(false)); DataBuffer mapDataCompressed = utils::Compress(dataPacket.Serialize(false));
std::cout << "Header Packet Size : " << mapHeaderCompressed.GetSize() << std::endl; utils::LOG(utils::format("Header Packet Size : %u", mapHeaderCompressed.GetSize()));
std::cout << "World Data Packet Size : " << mapDataCompressed.GetSize() << std::endl; utils::LOG(utils::format("World Data Packet Size : %u", mapDataCompressed.GetSize()));
DataBuffer buffer = mapHeaderCompressed << mapDataCompressed; 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); return buffer.WriteFile(fileName);
} }

View File

@@ -1,6 +1,5 @@
#include "game/client/Client.h" #include "game/client/Client.h"
#include "misc/Format.h"
#include <iostream>
namespace td { namespace td {
namespace client { namespace client {
@@ -12,7 +11,7 @@ bool Client::Connect(const network::IPAddresses& addresses, std::uint16_t port)
return true; return true;
} }
} }
std::cout << "Failed to connect !\n"; utils::LOG("Failed to connect !");
return false; return false;
} }
@@ -39,7 +38,7 @@ void Client::Tick(std::uint64_t delta) {
return; return;
m_Connected = m_Connexion.UpdateSocket(); m_Connected = m_Connexion.UpdateSocket();
if (!m_Connected) { if (!m_Connected) {
std::cout << "Disconnected ! (Reason : " << m_Connexion.GetDisconnectReason() << ")\n"; utils::LOG(utils::format("Disconnected ! (Reason : %s)", m_Connexion.GetDisconnectReason().c_str()));
Reset(); Reset();
} else { } else {
m_Game->Tick(delta); m_Game->Tick(delta);

View File

@@ -3,8 +3,6 @@
#include "misc/Time.h" #include "misc/Time.h"
#include <iostream>
#ifdef NDEBUG #ifdef NDEBUG
#define MIN_PLAYER_WAITING 2 #define MIN_PLAYER_WAITING 2
#else #else
@@ -53,7 +51,7 @@ void Lobby::SendTimeRemaining() {
void Lobby::OnPlayerJoin(std::uint8_t playerID) { void Lobby::OnPlayerJoin(std::uint8_t playerID) {
if (m_GameStarted) if (m_GameStarted)
return; return;
std::cout << "(Server) Player Joined Lobby !\n"; utils::LOG("(Server) Player Joined Lobby !");
m_Players.push_back(playerID); m_Players.push_back(playerID);
if (m_Players.size() == MIN_PLAYER_WAITING) { // start timer if a second player join the match if (m_Players.size() == MIN_PLAYER_WAITING) { // start timer if a second player join the match
m_StartTimerTime = utils::GetTime(); m_StartTimerTime = utils::GetTime();
@@ -65,7 +63,7 @@ void Lobby::OnPlayerJoin(std::uint8_t playerID) {
void Lobby::OnPlayerLeave(std::uint8_t playerID) { void Lobby::OnPlayerLeave(std::uint8_t playerID) {
if (m_GameStarted) if (m_GameStarted)
return; 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); auto it = std::find(m_Players.begin(), m_Players.end(), playerID);
if (it == m_Players.end()) if (it == m_Players.end())

View File

@@ -1,7 +1,8 @@
#include "game/server/Server.h" #include "game/server/Server.h"
#include <iostream>
#include "protocol/PacketFactory.h" #include "protocol/PacketFactory.h"
#include "misc/Format.h"
namespace td { namespace td {
namespace server { namespace server {
@@ -44,14 +45,14 @@ void Server::StopThread() {
bool Server::Start(std::uint16_t port) { bool Server::Start(std::uint16_t port) {
if (!m_Listener.Listen(port, 10)) { 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; return false;
} }
if (!m_Listener.SetBlocking(false)) { if (!m_Listener.SetBlocking(false)) {
std::cout << "Failed to block server socket !\n"; utils::LOG("Failed to block server socket !");
return false; return false;
} }
std::cout << "Server started at port " << port << " !\n"; utils::LOG(utils::format("Server started at port %u !", port));
m_TickCounter.Reset(); m_TickCounter.Reset();
m_ServerRunning = true; m_ServerRunning = true;
StartThread(); StartThread();
@@ -65,7 +66,7 @@ void Server::Clean() {
m_Connections.clear(); m_Connections.clear();
GetPlayers().clear(); GetPlayers().clear();
std::cout << "Server successfully stopped !\n"; utils::LOG("Server successfully stopped !");
} }
void Server::Stop() { void Server::Stop() {

View File

@@ -6,8 +6,7 @@
#include "window/Display.h" #include "window/Display.h"
#include "game/client/ClientGame.h" #include "game/client/ClientGame.h"
#include "game/client/Client.h" #include "game/client/Client.h"
#include "misc/Format.h"
#include <iostream>
namespace td { namespace td {
namespace render { namespace render {
@@ -25,11 +24,11 @@ ImVec4 WorldRenderer::GetImGuiTeamColor(game::TeamColor color) {
} }
void WorldRenderer::LoadModels() { void WorldRenderer::LoadModels() {
std::cout << "World Created !\n"; utils::LOGD("World Created !");
m_WorldVao = std::make_unique<GL::VertexArray>(std::move(WorldLoader::LoadWorldModel(m_World))); m_WorldVao = std::make_unique<GL::VertexArray>(std::move(WorldLoader::LoadWorldModel(m_World)));
m_MobVao = std::make_unique<GL::VertexArray>(std::move(WorldLoader::LoadMobModel())); m_MobVao = std::make_unique<GL::VertexArray>(std::move(WorldLoader::LoadMobModel()));
m_SelectTileVao = std::make_unique<GL::VertexArray>(std::move(WorldLoader::LoadTileSelectModel())); m_SelectTileVao = std::make_unique<GL::VertexArray>(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) { WorldRenderer::WorldRenderer(game::World* world, client::ClientGame* client) : m_Client(client), m_Renderer(m_Client->GetRenderer()), m_World(world), m_Zoom(0.1) {

View File

@@ -6,10 +6,13 @@
*/ */
#include "render/shaders/ShaderProgram.h" #include "render/shaders/ShaderProgram.h"
#include "misc/Log.h"
#include "misc/Format.h"
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <vector>
#include <glm/gtc/type_ptr.hpp> #include <glm/gtc/type_ptr.hpp>
@@ -39,7 +42,7 @@ void ShaderProgram::Stop() const {
int ShaderProgram::GetUniformLocation(const std::string& uniformName) const { int ShaderProgram::GetUniformLocation(const std::string& uniformName) const {
const int location = glGetUniformLocation(m_ProgramID, uniformName.c_str()); const int location = glGetUniformLocation(m_ProgramID, uniformName.c_str());
if (location == -1) { 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; return location;
} }
@@ -118,15 +121,14 @@ unsigned int ShaderProgram::LoadShader(const std::string& source, GLenum type) {
GLint compilesuccessful; GLint compilesuccessful;
glGetShaderiv(shaderID, GL_COMPILE_STATUS, &compilesuccessful); glGetShaderiv(shaderID, GL_COMPILE_STATUS, &compilesuccessful);
if (compilesuccessful == false) { if (compilesuccessful == false) {
std::cout << "Could not compile shader !\n";
GLsizei size; GLsizei size;
glGetShaderiv(shaderID, GL_INFO_LOG_LENGTH, &size); glGetShaderiv(shaderID, GL_INFO_LOG_LENGTH, &size);
std::vector<char> shaderError(static_cast<std::size_t>(size)); std::vector<char> shaderError(static_cast<std::size_t>(size));
glGetShaderInfoLog(shaderID, size, &size, shaderError.data()); glGetShaderInfoLog(shaderID, size, &size, shaderError.data());
std::cout << shaderError.data() << std::endl;
#ifdef __ANDROID__ utils::LOG("Could not compile shader !");
__android_log_print(ANDROID_LOG_ERROR, "TRACKERS", "Could not compile shader !\n %s", error);
#endif utils::LOG(shaderError.data());
} }
return shaderID; return shaderID;
} }

View File

@@ -2,6 +2,8 @@
#include "misc/Platform.h" #include "misc/Platform.h"
#include "misc/DataBuffer.h" #include "misc/DataBuffer.h"
#include "misc/Log.h"
#include "misc/Format.h"
#include "network/HttpLib.h" #include "network/HttpLib.h"
@@ -24,15 +26,15 @@ bool Updater::CheckUpdate() {
// we only look at the first line // we only look at the first line
m_LastVersion = m_LastVersion.substr(0, m_LastVersion.find('\n')); m_LastVersion = m_LastVersion.substr(0, m_LastVersion.find('\n'));
std::cout << "Current version : [" << GetCurrentVersion() << "]\n"; utils::LOG(utils::format("Current version : [%s]", GetCurrentVersion().c_str()));
std::cout << "Last version : [" << m_LastVersion << "]\n"; utils::LOG(utils::format("Last version : [%s]", m_LastVersion.c_str()));
if (currentVersion != m_LastVersion) { if (currentVersion != m_LastVersion) {
return true; return true;
} }
return false; return false;
} else { } else {
std::cerr << "Error : " << res.error() << std::endl; utils::LOG(utils::format("Error : %u", res.error()));
return false; return false;
} }

View File

@@ -8,14 +8,16 @@
#include "window/Display.h" #include "window/Display.h"
#define GLFW_INCLUDE_NONE #define GLFW_INCLUDE_NONE
#include "render/gui/TowerGui.h" #include "render/gui/TowerGui.h"
#include <SDL2/SDL.h>
#include <SDL2/SDL_video.h>
#include <iostream> #include <iostream>
#include "game/GameManager.h" #include "game/GameManager.h"
#include "render/Renderer.h" #include "render/Renderer.h"
#include "render/WorldRenderer.h" #include "render/WorldRenderer.h"
#include "../render/gui/imgui/imgui_impl_sdl.h" #include "../render/gui/imgui/imgui_impl_sdl.h"
#include "misc/Log.h"
#include "misc/Format.h"
#include <SDL2/SDL.h>
#include <SDL2/SDL_video.h>
#include <SDL2/SDL_render.h> #include <SDL2/SDL_render.h>
namespace Display { namespace Display {
@@ -94,8 +96,7 @@ bool Create() {
mask_desc = "?"; mask_desc = "?";
} }
std::cout << "GL Context: " << major << "." << minor << " " << mask_desc 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));
<< ", Color : R" << r << "G" << g << "B" << b << "A" << a << ", Depth bits: " << depth << std::endl;
SDL_GL_MakeCurrent(window, glContext); SDL_GL_MakeCurrent(window, glContext);