Patch - Refactors logging and adds macro header - V14.5.29
This commit refactors the logging system by replacing direct calls to the Logger class with macros. This improves code readability and maintainability by providing a consistent and concise way to log messages throughout the engine. The 'macro.h' header file is added and included in multiple system classes to define these logging macros, centralizing logging functionality. Additionally, error handling is improved in imguiManager::IncrementBuildVersionInConfig by logging specific errors during file operations.
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
//////////////
|
//////////////
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <dinput.h>
|
#include <dinput.h>
|
||||||
|
#include "macro.h"
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Class name: input_class
|
// Class name: input_class
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
// INCLUDES //
|
// INCLUDES //
|
||||||
//////////////
|
//////////////
|
||||||
#include <directxmath.h>
|
#include <directxmath.h>
|
||||||
|
#include "macro.h"
|
||||||
using namespace DirectX;
|
using namespace DirectX;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
// INCLUDES //
|
// INCLUDES //
|
||||||
//////////////
|
//////////////
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include "macro.h"
|
||||||
|
|
||||||
#include <d3d11.h>
|
#include <d3d11.h>
|
||||||
#include <directxmath.h>
|
#include <directxmath.h>
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <d3d11.h>
|
#include <d3d11.h>
|
||||||
#include <directxmath.h>
|
#include <directxmath.h>
|
||||||
|
#include "macro.h"
|
||||||
using namespace DirectX;
|
using namespace DirectX;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "macro.h"
|
||||||
|
|
||||||
#include "ecs/entity.h"
|
#include "ecs/entity.h"
|
||||||
#include "ecs/ComponentFactory.h"
|
#include "ecs/ComponentFactory.h"
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <d3d11.h>
|
#include <d3d11.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include "macro.h"
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
//////////////
|
//////////////
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include "macro.h"
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include "system_class.h"
|
#include "system_class.h"
|
||||||
|
#include "macro.h"
|
||||||
|
|
||||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pScmdline, int iCmdshow)
|
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pScmdline, int iCmdshow)
|
||||||
{
|
{
|
||||||
@@ -23,7 +23,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pScmdline,
|
|||||||
result = System->initialize();
|
result = System->initialize();
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
Logger::Get().Log("System initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
LOG_INIT("System initialized");
|
||||||
System->send_path(path,WFolder);
|
System->send_path(path,WFolder);
|
||||||
System->run();
|
System->run();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ void Skybox::Initialize(d_3d_class* d3dClassRef)
|
|||||||
|
|
||||||
object* Skybox::ConstructSkybox(application_class* app)
|
object* Skybox::ConstructSkybox(application_class* app)
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Construct skybox", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
LOG_INFO("Construct skybox");
|
||||||
|
|
||||||
char modelFilename[128];
|
char modelFilename[128];
|
||||||
strcpy_s(modelFilename, "assets/Model/OBJ/skysphere.obj");
|
strcpy_s(modelFilename, "assets/Model/OBJ/skysphere.obj");
|
||||||
@@ -43,7 +43,7 @@ object* Skybox::ConstructSkybox(application_class* app)
|
|||||||
HRESULT result = DirectX::CreateWICTextureFromFile(m_d3dClassRef->get_device(), m_d3dClassRef->get_device_context(), textureFilename.c_str(), nullptr, &texture);
|
HRESULT result = DirectX::CreateWICTextureFromFile(m_d3dClassRef->get_device(), m_d3dClassRef->get_device_context(), textureFilename.c_str(), nullptr, &texture);
|
||||||
if (FAILED(result))
|
if (FAILED(result))
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to load texture: " + std::string(textureFilename.begin(), textureFilename.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to load texture: " + std::string(textureFilename.begin(), textureFilename.end()));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
SkyboxTextures.diffuse.push_back(texture);
|
SkyboxTextures.diffuse.push_back(texture);
|
||||||
@@ -55,7 +55,7 @@ object* Skybox::ConstructSkybox(application_class* app)
|
|||||||
HRESULT result = m_Skybox->Initialize(m_d3dClassRef->get_device(), m_d3dClassRef->get_device_context(), modelFilename, SkyboxTextures);
|
HRESULT result = m_Skybox->Initialize(m_d3dClassRef->get_device(), m_d3dClassRef->get_device_context(), modelFilename, SkyboxTextures);
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Could not initialize the skybox model object", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Could not initialize the skybox model object");
|
||||||
delete m_Skybox;
|
delete m_Skybox;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ bool imguiManager::IncrementBuildVersionInConfig(const std::string& filepath) {
|
|||||||
line = "VER=" + std::to_string(BUILD_VERSION_VER);
|
line = "VER=" + std::to_string(BUILD_VERSION_VER);
|
||||||
}
|
}
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
|
LOG_ERROR("Error converting VER to integer");
|
||||||
return false; // erreur conversion
|
return false; // erreur conversion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,7 +83,11 @@ bool imguiManager::IncrementBuildVersionInConfig(const std::string& filepath) {
|
|||||||
|
|
||||||
// Réécrire tout le fichier
|
// Réécrire tout le fichier
|
||||||
std::ofstream file_out(filepath, std::ios::trunc);
|
std::ofstream file_out(filepath, std::ios::trunc);
|
||||||
if (!file_out) return false;
|
if (!file_out)
|
||||||
|
{
|
||||||
|
LOG_ERROR("Error writing to file");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
for (const auto& l : lines) {
|
for (const auto& l : lines) {
|
||||||
file_out << l << "\n";
|
file_out << l << "\n";
|
||||||
@@ -93,7 +98,7 @@ bool imguiManager::IncrementBuildVersionInConfig(const std::string& filepath) {
|
|||||||
|
|
||||||
bool imguiManager::Initialize(HWND hwnd, ID3D11Device* device, ID3D11DeviceContext* deviceContext)
|
bool imguiManager::Initialize(HWND hwnd, ID3D11Device* device, ID3D11DeviceContext* deviceContext)
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Initializing imgui", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
LOG_INIT("Initializing imgui");
|
||||||
|
|
||||||
m_device = device;
|
m_device = device;
|
||||||
m_deviceContext = deviceContext;
|
m_deviceContext = deviceContext;
|
||||||
@@ -218,7 +223,7 @@ bool imguiManager::Initialize(HWND hwnd, ID3D11Device* device, ID3D11DeviceConte
|
|||||||
// initialize the scene manager
|
// initialize the scene manager
|
||||||
scene_manager_ = new scene_manager;
|
scene_manager_ = new scene_manager;
|
||||||
if (!scene_manager_->initialize(app_.get())) {
|
if (!scene_manager_->initialize(app_.get())) {
|
||||||
Logger::Get().Log("Failed to initialize scene manager", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to initialize scene manager");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,35 +257,35 @@ bool imguiManager::Initialize(HWND hwnd, ID3D11Device* device, ID3D11DeviceConte
|
|||||||
std::string configPath = "config.txt"; // ou chemin complet
|
std::string configPath = "config.txt"; // ou chemin complet
|
||||||
configPath = exeDir + BUILD_VERSION_TYPE + "\\" + configPath;
|
configPath = exeDir + BUILD_VERSION_TYPE + "\\" + configPath;
|
||||||
if (!IncrementBuildVersionInConfig(configPath)) {
|
if (!IncrementBuildVersionInConfig(configPath)) {
|
||||||
Logger::Get().Log("Failed to increment build version in config.txt", __FILE__, __LINE__, Logger::LogLevel::Warning);
|
LOG_WARNING("Failed to increment build version in config.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the build version text in the inverse build type folder
|
// update the build version text in the inverse build type folder
|
||||||
configPath = "config.txt";
|
configPath = "config.txt";
|
||||||
configPath = exeDir + BUILD_VERSION_INVERSE + "\\" + configPath;
|
configPath = exeDir + BUILD_VERSION_INVERSE + "\\" + configPath;
|
||||||
Logger::Get().Log("Inverse build type config path: " + configPath, __FILE__, __LINE__, Logger::LogLevel::Info);
|
LOG_INFO("Inverse build type config path: " + configPath);
|
||||||
if (!IncrementBuildVersionInConfig(configPath)) {
|
if (!IncrementBuildVersionInConfig(configPath)) {
|
||||||
Logger::Get().Log("Failed to increment build version in config.txt of inverse build type", __FILE__, __LINE__, Logger::LogLevel::Warning);
|
LOG_WARNING("Failed to increment build version in config.txt of inverse build type");
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the sky entity shared ptr from the application
|
// get the sky entity shared ptr from the application
|
||||||
sky_entity_shared_ptr_ = app_->get_sky_entity_shared_ptr();
|
sky_entity_shared_ptr_ = app_->get_sky_entity_shared_ptr();
|
||||||
if (!sky_entity_shared_ptr_) {
|
if (!sky_entity_shared_ptr_) {
|
||||||
Logger::Get().Log("Sky entity shared ptr is null", __FILE__, __LINE__, Logger::LogLevel::Warning);
|
LOG_WARNING("Sky entity shared ptr is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::Get().Log("imgui initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
LOG_INIT("imgui initialized");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void imguiManager::Shutdown()
|
void imguiManager::Shutdown()
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Shutting down imgui", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
|
LOG_SHUTDOWN("Shutting down imgui");
|
||||||
ImGui_ImplDX11_Shutdown();
|
ImGui_ImplDX11_Shutdown();
|
||||||
ImGui_ImplWin32_Shutdown();
|
ImGui_ImplWin32_Shutdown();
|
||||||
ImGui::DestroyContext();
|
ImGui::DestroyContext();
|
||||||
Logger::Get().Log("imgui shutdown", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
|
LOG_SHUTDOWN("imgui shutdown");
|
||||||
}
|
}
|
||||||
|
|
||||||
void imguiManager::Render()
|
void imguiManager::Render()
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ input_class::~input_class()
|
|||||||
|
|
||||||
bool input_class::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, int screenHeight)
|
bool input_class::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, int screenHeight)
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Initializing input class", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
LOG_INIT("Initializing input class");
|
||||||
|
|
||||||
HRESULT result;
|
HRESULT result;
|
||||||
int i;
|
int i;
|
||||||
@@ -44,7 +44,7 @@ bool input_class::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, in
|
|||||||
result = DirectInput8Create(hinstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&m_directInput, NULL);
|
result = DirectInput8Create(hinstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&m_directInput, NULL);
|
||||||
if (FAILED(result))
|
if (FAILED(result))
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to create direct input interface", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to create direct input interface");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ bool input_class::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, in
|
|||||||
result = m_directInput->CreateDevice(GUID_SysKeyboard, &m_keyboard, NULL);
|
result = m_directInput->CreateDevice(GUID_SysKeyboard, &m_keyboard, NULL);
|
||||||
if (FAILED(result))
|
if (FAILED(result))
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to create direct input interface for the keyboard", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to create direct input interface for the keyboard");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ bool input_class::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, in
|
|||||||
result = m_keyboard->SetDataFormat(&c_dfDIKeyboard);
|
result = m_keyboard->SetDataFormat(&c_dfDIKeyboard);
|
||||||
if (FAILED(result))
|
if (FAILED(result))
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to set data format for the keyboard", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to set data format for the keyboard");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ bool input_class::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, in
|
|||||||
result = m_keyboard->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
|
result = m_keyboard->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
|
||||||
if (FAILED(result))
|
if (FAILED(result))
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to set cooperative level of the keyboard", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to set cooperative level of the keyboard");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ bool input_class::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, in
|
|||||||
result = m_keyboard->Acquire();
|
result = m_keyboard->Acquire();
|
||||||
if (FAILED(result))
|
if (FAILED(result))
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to acquire the keyboard", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to acquire the keyboard");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ bool input_class::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, in
|
|||||||
result = m_directInput->CreateDevice(GUID_SysMouse, &m_mouse, NULL);
|
result = m_directInput->CreateDevice(GUID_SysMouse, &m_mouse, NULL);
|
||||||
if (FAILED(result))
|
if (FAILED(result))
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to create direct input interface for the mouse", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to create direct input interface for the mouse");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ bool input_class::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, in
|
|||||||
result = m_mouse->SetDataFormat(&c_dfDIMouse);
|
result = m_mouse->SetDataFormat(&c_dfDIMouse);
|
||||||
if (FAILED(result))
|
if (FAILED(result))
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to set data format for the mouse", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to set data format for the mouse");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@ bool input_class::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, in
|
|||||||
result = m_mouse->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
|
result = m_mouse->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
|
||||||
if (FAILED(result))
|
if (FAILED(result))
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to set cooperative level of the mouse", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to set cooperative level of the mouse");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,11 +108,11 @@ bool input_class::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, in
|
|||||||
result = m_mouse->Acquire();
|
result = m_mouse->Acquire();
|
||||||
if (FAILED(result))
|
if (FAILED(result))
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to acquire the mouse", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to acquire the mouse");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::Get().Log("Input class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
LOG_INIT("Input class initialized");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -121,7 +121,7 @@ bool input_class::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, in
|
|||||||
void input_class::KeyDown(unsigned int input)
|
void input_class::KeyDown(unsigned int input)
|
||||||
{
|
{
|
||||||
// If a key is pressed then save that state in the key array.
|
// If a key is pressed then save that state in the key array.
|
||||||
Logger::Get().Log("Key down: " + std::to_string(input), __FILE__, __LINE__, Logger::LogLevel::Input);
|
LOG("Key down: " + std::to_string(input), Logger::LogLevel::Input);
|
||||||
m_keys[input] = true;
|
m_keys[input] = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -143,7 +143,7 @@ bool input_class::IsKeyDown(unsigned int key) const
|
|||||||
|
|
||||||
void input_class::Shutdown()
|
void input_class::Shutdown()
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Shutting down input class", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
|
LOG_SHUTDOWN("Shutting down input class");
|
||||||
|
|
||||||
// Release the mouse.
|
// Release the mouse.
|
||||||
if (m_mouse)
|
if (m_mouse)
|
||||||
@@ -168,7 +168,7 @@ void input_class::Shutdown()
|
|||||||
m_directInput = 0;
|
m_directInput = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::Get().Log("Input class shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
|
LOG_SHUTDOWN("Input class shut down");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -177,12 +177,11 @@ bool input_class::Frame()
|
|||||||
{
|
{
|
||||||
bool result;
|
bool result;
|
||||||
|
|
||||||
|
|
||||||
// Read the current state of the keyboard.
|
// Read the current state of the keyboard.
|
||||||
result = ReadKeyboard();
|
result = ReadKeyboard();
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to read keyboard state", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to read keyboard state");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,7 +189,7 @@ bool input_class::Frame()
|
|||||||
result = ReadMouse();
|
result = ReadMouse();
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to read mouse state", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to read mouse state");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,7 +215,7 @@ bool input_class::ReadKeyboard()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to get keyboard device state", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to get keyboard device state");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -240,7 +239,7 @@ bool input_class::ReadMouse()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to get mouse device state", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to get mouse device state");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ bool model_class::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceCo
|
|||||||
// Load in the model data.
|
// Load in the model data.
|
||||||
result = LoadModel(modelFilename);
|
result = LoadModel(modelFilename);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
Logger::Get().Log("Failed to load model data", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to load model data");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ bool model_class::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceCo
|
|||||||
// Initialize the vertex and index buffers.
|
// Initialize the vertex and index buffers.
|
||||||
result = InitializeBuffers(device);
|
result = InitializeBuffers(device);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
Logger::Get().Log("Failed to initialize buffers", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to initialize buffers");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +139,7 @@ bool model_class::InitializeBuffers(ID3D11Device* device)
|
|||||||
result = device->CreateBuffer(&vertexBufferDesc, &vertexData, &m_vertexBuffer);
|
result = device->CreateBuffer(&vertexBufferDesc, &vertexData, &m_vertexBuffer);
|
||||||
if (FAILED(result))
|
if (FAILED(result))
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to create vertex buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to create vertex buffer");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +160,7 @@ bool model_class::InitializeBuffers(ID3D11Device* device)
|
|||||||
result = device->CreateBuffer(&indexBufferDesc, &indexData, &m_indexBuffer);
|
result = device->CreateBuffer(&indexBufferDesc, &indexData, &m_indexBuffer);
|
||||||
if (FAILED(result))
|
if (FAILED(result))
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to create index buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to create index buffer");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,7 +227,7 @@ bool model_class::LoadModel(char* filename)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Unsupported file format", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Unsupported file format");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -238,7 +238,7 @@ bool model_class::LoadObjModel(char* filename)
|
|||||||
std::ifstream fin(filename, std::ios::in | std::ios::binary);
|
std::ifstream fin(filename, std::ios::in | std::ios::binary);
|
||||||
if (!fin)
|
if (!fin)
|
||||||
{
|
{
|
||||||
Logger::Get().Log("<EFBFBD>chec d'ouverture du fichier mod<6F>le", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("<EFBFBD>chec d'ouverture du fichier mod<6F>le");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,7 +352,7 @@ bool model_class::LoadTxtModel(char* filename)
|
|||||||
// If it could not open the file then exit.
|
// If it could not open the file then exit.
|
||||||
if (fin.fail())
|
if (fin.fail())
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to open model file", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to open model file");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -535,7 +535,7 @@ bool model_class::PreloadTextures(ID3D11Device* device, ID3D11DeviceContext* dev
|
|||||||
hResult = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture);
|
hResult = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture);
|
||||||
if (FAILED(hResult))
|
if (FAILED(hResult))
|
||||||
{
|
{
|
||||||
Logger::Get().Log("<EFBFBD>chec du chargement de la texture diffuse: " + std::string(texturePath.begin(), texturePath.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("<EFBFBD>chec du chargement de la texture diffuse: " + std::string(texturePath.begin(), texturePath.end()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
textureContainer.diffuse.push_back(texture);
|
textureContainer.diffuse.push_back(texture);
|
||||||
@@ -548,7 +548,7 @@ bool model_class::PreloadTextures(ID3D11Device* device, ID3D11DeviceContext* dev
|
|||||||
hResult = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture);
|
hResult = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture);
|
||||||
if (FAILED(hResult))
|
if (FAILED(hResult))
|
||||||
{
|
{
|
||||||
Logger::Get().Log("<EFBFBD>chec du chargement de la texture normale: " + std::string(texturePath.begin(), texturePath.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("<EFBFBD>chec du chargement de la texture normale: " + std::string(texturePath.begin(), texturePath.end()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
textureContainer.normal.push_back(texture);
|
textureContainer.normal.push_back(texture);
|
||||||
@@ -561,7 +561,7 @@ bool model_class::PreloadTextures(ID3D11Device* device, ID3D11DeviceContext* dev
|
|||||||
hResult = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture);
|
hResult = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture);
|
||||||
if (FAILED(hResult))
|
if (FAILED(hResult))
|
||||||
{
|
{
|
||||||
Logger::Get().Log("<EFBFBD>chec du chargement de la texture sp<73>culaire: " + std::string(texturePath.begin(), texturePath.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("<EFBFBD>chec du chargement de la texture sp<73>culaire: " + std::string(texturePath.begin(), texturePath.end()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
textureContainer.specular.push_back(texture);
|
textureContainer.specular.push_back(texture);
|
||||||
@@ -574,7 +574,7 @@ bool model_class::PreloadTextures(ID3D11Device* device, ID3D11DeviceContext* dev
|
|||||||
hResult = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture);
|
hResult = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture);
|
||||||
if (FAILED(hResult))
|
if (FAILED(hResult))
|
||||||
{
|
{
|
||||||
Logger::Get().Log("<EFBFBD>chec du chargement de la texture alpha: " + std::string(texturePath.begin(), texturePath.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("<EFBFBD>chec du chargement de la texture alpha: " + std::string(texturePath.begin(), texturePath.end()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
textureContainer.alpha.push_back(texture);
|
textureContainer.alpha.push_back(texture);
|
||||||
@@ -584,7 +584,7 @@ bool model_class::PreloadTextures(ID3D11Device* device, ID3D11DeviceContext* dev
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool model_class::ChangeTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext, std::wstring filename, TextureType type, int index) {
|
bool model_class::ChangeTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext, std::wstring filename, TextureType type, int index) {
|
||||||
Logger::Get().Log("Changing texture", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
LOG_INIT("Changing texture");
|
||||||
|
|
||||||
HRESULT result;
|
HRESULT result;
|
||||||
ID3D11ShaderResourceView* newTexture = nullptr;
|
ID3D11ShaderResourceView* newTexture = nullptr;
|
||||||
@@ -592,7 +592,7 @@ bool model_class::ChangeTexture(ID3D11Device* device, ID3D11DeviceContext* devic
|
|||||||
// Charger la nouvelle texture
|
// Charger la nouvelle texture
|
||||||
result = DirectX::CreateWICTextureFromFile(device, deviceContext, filename.c_str(), nullptr, &newTexture);
|
result = DirectX::CreateWICTextureFromFile(device, deviceContext, filename.c_str(), nullptr, &newTexture);
|
||||||
if (FAILED(result)) {
|
if (FAILED(result)) {
|
||||||
Logger::Get().Log("Failed to load texture: " + std::string(filename.begin(), filename.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to load texture: " + std::string(filename.begin(), filename.end()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -640,12 +640,12 @@ bool model_class::ChangeTexture(ID3D11Device* device, ID3D11DeviceContext* devic
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::Get().Log("Texture changed successfully", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
LOG_INIT("Texture changed successfully");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool model_class::AddTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext, std::wstring filename, TextureType type) {
|
bool model_class::AddTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext, std::wstring filename, TextureType type) {
|
||||||
Logger::Get().Log("Adding texture", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
LOG_INIT("Adding texture");
|
||||||
|
|
||||||
HRESULT result;
|
HRESULT result;
|
||||||
ID3D11ShaderResourceView* newTexture = nullptr;
|
ID3D11ShaderResourceView* newTexture = nullptr;
|
||||||
@@ -653,7 +653,7 @@ bool model_class::AddTexture(ID3D11Device* device, ID3D11DeviceContext* deviceCo
|
|||||||
// Charger la nouvelle texture
|
// Charger la nouvelle texture
|
||||||
result = DirectX::CreateWICTextureFromFile(device, deviceContext, filename.c_str(), nullptr, &newTexture);
|
result = DirectX::CreateWICTextureFromFile(device, deviceContext, filename.c_str(), nullptr, &newTexture);
|
||||||
if (FAILED(result)) {
|
if (FAILED(result)) {
|
||||||
Logger::Get().Log("Failed to load texture: " + std::string(filename.begin(), filename.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to load texture: " + std::string(filename.begin(), filename.end()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -677,13 +677,13 @@ bool model_class::AddTexture(ID3D11Device* device, ID3D11DeviceContext* deviceCo
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::Get().Log("Texture added successfully", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
LOG_INIT("Texture added successfully");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool model_class::AddTexture(ID3D11ShaderResourceView* texture, TextureType type) {
|
bool model_class::AddTexture(ID3D11ShaderResourceView* texture, TextureType type) {
|
||||||
if (!texture) {
|
if (!texture) {
|
||||||
Logger::Get().Log("Cannot add null texture", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Cannot add null texture");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -421,10 +421,9 @@ bool object::LoadTexturesFromPath(std::vector<std::wstring>& texturePaths, Textu
|
|||||||
std::wstring ws(errMsg);
|
std::wstring ws(errMsg);
|
||||||
std::string str(ws.begin(), ws.end());
|
std::string str(ws.begin(), ws.end());
|
||||||
|
|
||||||
Logger::Get().Log("Failed to load texture: " + std::string(texturePath.begin(), texturePath.end()) +
|
LOG_ERROR("Failed to load texture: " + std::string(texturePath.begin(), texturePath.end()) +
|
||||||
"\nError: " + std::to_string(result) +
|
"\nError: " + std::to_string(result) +
|
||||||
"\nDescription: " + str,
|
"\nDescription: " + str);
|
||||||
__FILE__, __LINE__, Logger::LogLevel::Error);
|
|
||||||
return false; // Assurez-vous de retourner false ou de g<>rer l'erreur de mani<6E>re appropri<72>e
|
return false; // Assurez-vous de retourner false ou de g<>rer l'erreur de mani<6E>re appropri<72>e
|
||||||
}
|
}
|
||||||
texturesContainer.AssignTexture(texturesContainer, texture,texturePath , i);
|
texturesContainer.AssignTexture(texturesContainer, texture,texturePath , i);
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ render_texture_class::~render_texture_class()
|
|||||||
|
|
||||||
bool render_texture_class::Initialize(ID3D11Device * device, int textureWidth, int textureHeight, float screenDepth, float screenNear, int format)
|
bool render_texture_class::Initialize(ID3D11Device * device, int textureWidth, int textureHeight, float screenDepth, float screenNear, int format)
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Initializing render_texture_class", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
LOG_INIT("Initializing render_texture_class");
|
||||||
|
|
||||||
D3D11_TEXTURE2D_DESC textureDesc;
|
D3D11_TEXTURE2D_DESC textureDesc;
|
||||||
HRESULT result;
|
HRESULT result;
|
||||||
@@ -70,7 +70,7 @@ bool render_texture_class::Initialize(ID3D11Device * device, int textureWidth, i
|
|||||||
result = device->CreateTexture2D(&textureDesc, NULL, &m_renderTargetTexture);
|
result = device->CreateTexture2D(&textureDesc, NULL, &m_renderTargetTexture);
|
||||||
if (FAILED(result))
|
if (FAILED(result))
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to create render target texture", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to create render target texture");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ bool render_texture_class::Initialize(ID3D11Device * device, int textureWidth, i
|
|||||||
result = device->CreateRenderTargetView(m_renderTargetTexture, &renderTargetViewDesc, &m_renderTargetView);
|
result = device->CreateRenderTargetView(m_renderTargetTexture, &renderTargetViewDesc, &m_renderTargetView);
|
||||||
if (FAILED(result))
|
if (FAILED(result))
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to create render target view", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to create render target view");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ bool render_texture_class::Initialize(ID3D11Device * device, int textureWidth, i
|
|||||||
result = device->CreateShaderResourceView(m_renderTargetTexture, &shaderResourceViewDesc, &m_shaderResourceView);
|
result = device->CreateShaderResourceView(m_renderTargetTexture, &shaderResourceViewDesc, &m_shaderResourceView);
|
||||||
if (FAILED(result))
|
if (FAILED(result))
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to create shader resource view", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to create shader resource view");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +121,7 @@ bool render_texture_class::Initialize(ID3D11Device * device, int textureWidth, i
|
|||||||
result = device->CreateTexture2D(&depthBufferDesc, NULL, &m_depthStencilBuffer);
|
result = device->CreateTexture2D(&depthBufferDesc, NULL, &m_depthStencilBuffer);
|
||||||
if (FAILED(result))
|
if (FAILED(result))
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to create depth buffer texture", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to create depth buffer texture");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,7 +137,7 @@ bool render_texture_class::Initialize(ID3D11Device * device, int textureWidth, i
|
|||||||
result = device->CreateDepthStencilView(m_depthStencilBuffer, &depthStencilViewDesc, &m_depthStencilView);
|
result = device->CreateDepthStencilView(m_depthStencilBuffer, &depthStencilViewDesc, &m_depthStencilView);
|
||||||
if (FAILED(result))
|
if (FAILED(result))
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to create depth stencil view", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to create depth stencil view");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,14 +155,14 @@ bool render_texture_class::Initialize(ID3D11Device * device, int textureWidth, i
|
|||||||
// Create an orthographic projection matrix for 2D rendering.
|
// Create an orthographic projection matrix for 2D rendering.
|
||||||
m_orthoMatrix = XMMatrixOrthographicLH((float)textureWidth, (float)textureHeight, screenNear, screenDepth);
|
m_orthoMatrix = XMMatrixOrthographicLH((float)textureWidth, (float)textureHeight, screenNear, screenDepth);
|
||||||
|
|
||||||
Logger::Get().Log("render_texture_class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
LOG_INIT("render_texture_class initialized");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void render_texture_class::Shutdown()
|
void render_texture_class::Shutdown()
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Shutting down render_texture_class", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
|
LOG_SHUTDOWN("Shutting down render_texture_class");
|
||||||
|
|
||||||
if (m_depthStencilView)
|
if (m_depthStencilView)
|
||||||
{
|
{
|
||||||
@@ -194,7 +194,7 @@ void render_texture_class::Shutdown()
|
|||||||
m_renderTargetTexture = 0;
|
m_renderTargetTexture = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::Get().Log("render_texture_class shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
|
LOG_SHUTDOWN("render_texture_class shut down");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,20 +13,20 @@ scene_manager::~scene_manager()
|
|||||||
bool scene_manager::initialize(application_class* app)
|
bool scene_manager::initialize(application_class* app)
|
||||||
{
|
{
|
||||||
if (!app) {
|
if (!app) {
|
||||||
Logger::Get().Log("Application pointer is null", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Application pointer is null");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
app_ = app;
|
app_ = app;
|
||||||
|
|
||||||
if (app_ == nullptr) {
|
if (app_ == nullptr) {
|
||||||
Logger::Get().Log("Application pointer is null", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Application pointer is null");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
direct_3d_ = app_->get_direct_3d();
|
direct_3d_ = app_->get_direct_3d();
|
||||||
if (!direct_3d_) {
|
if (!direct_3d_) {
|
||||||
Logger::Get().Log("Direct3D pointer is null", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Direct3D pointer is null");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,8 +40,7 @@ bool scene_manager::shutdown()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool scene_manager::save_scene_as() {
|
bool scene_manager::save_scene_as() {
|
||||||
|
LOG_INFO("Saving scene as...");
|
||||||
Logger::Get().Log("Saving scene as...", __FILE__, __LINE__, Logger::LogLevel::Info);
|
|
||||||
|
|
||||||
OPENFILENAME ofn;
|
OPENFILENAME ofn;
|
||||||
wchar_t szFile[260] = { 0 };
|
wchar_t szFile[260] = { 0 };
|
||||||
@@ -68,8 +67,7 @@ bool scene_manager::save_scene_as() {
|
|||||||
|
|
||||||
// Sauvegarder la sc<73>ne avec le nouveau chemin
|
// Sauvegarder la sc<73>ne avec le nouveau chemin
|
||||||
save_scene();
|
save_scene();
|
||||||
|
LOG_INFO("Scene saved as: " + scene_path_);
|
||||||
Logger::Get().Log("Scene saved as: " + scene_path_, __FILE__, __LINE__, Logger::LogLevel::Info);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,16 +92,16 @@ bool scene_manager::load_scene() {
|
|||||||
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
|
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
|
||||||
ofn.lpstrDefExt = L"ker";
|
ofn.lpstrDefExt = L"ker";
|
||||||
if (GetOpenFileName(&ofn) != TRUE) {
|
if (GetOpenFileName(&ofn) != TRUE) {
|
||||||
Logger::Get().Log("Load scene canceled or failed", __FILE__, __LINE__, Logger::LogLevel::Warning);
|
LOG_WARNING("Load scene canceled or failed");
|
||||||
return false; // L'utilisateur a annul<75> la bo<62>te de dialogue
|
return false; // L'utilisateur a annul<75> la bo<62>te de dialogue
|
||||||
}
|
}
|
||||||
std::filesystem::path filepath = ofn.lpstrFile;
|
std::filesystem::path filepath = ofn.lpstrFile;
|
||||||
scene_path_ = convert_w_string_to_string(filepath.wstring());
|
scene_path_ = convert_w_string_to_string(filepath.wstring());
|
||||||
if (scene_path_.empty()) {
|
if (scene_path_.empty()) {
|
||||||
Logger::Get().Log("Invalid scene path", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Invalid scene path");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Logger::Get().Log("Loading scene from: " + scene_path_, __FILE__, __LINE__, Logger::LogLevel::Info);
|
LOG_INFO("Loading scene from: " + scene_path_);
|
||||||
|
|
||||||
|
|
||||||
w_folder_ = app_->get_w_folder();
|
w_folder_ = app_->get_w_folder();
|
||||||
@@ -115,7 +113,7 @@ bool scene_manager::load_scene() {
|
|||||||
|
|
||||||
std::ifstream inFile(scene_path_);
|
std::ifstream inFile(scene_path_);
|
||||||
if (!inFile.is_open()) {
|
if (!inFile.is_open()) {
|
||||||
Logger::Get().Log("<EFBFBD>chec de l'ouverture du fichier", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("<EFBFBD>chec de l'ouverture du fichier");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,18 +153,18 @@ bool scene_manager::load_scene() {
|
|||||||
auto modelPathComponent = currentEntity->GetComponent<ecs::ModelPathComponent>();
|
auto modelPathComponent = currentEntity->GetComponent<ecs::ModelPathComponent>();
|
||||||
|
|
||||||
if (!modelPathComponent) {
|
if (!modelPathComponent) {
|
||||||
Logger::Get().Log("ModelPathComponent missing for entity ID: " + std::to_string(currentEntity->GetID()), __FILE__, __LINE__, Logger::LogLevel::Warning);
|
LOG_WARNING("ModelPathComponent missing for entity ID: " + std::to_string(currentEntity->GetID()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!modelPathComponent || modelPathComponent->GetPath().empty()) {
|
if (!modelPathComponent || modelPathComponent->GetPath().empty()) {
|
||||||
Logger::Get().Log("No model path specified for entity ID: " + std::to_string(currentEntity->GetID()), __FILE__, __LINE__, Logger::LogLevel::Warning);
|
LOG_WARNING("No model path specified for entity ID: " + std::to_string(currentEntity->GetID()));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto renderComponent = currentEntity->GetComponent<ecs::RenderComponent>();
|
auto renderComponent = currentEntity->GetComponent<ecs::RenderComponent>();
|
||||||
|
|
||||||
if (!renderComponent)
|
if (!renderComponent)
|
||||||
{
|
{
|
||||||
Logger::Get().Log("RenderComponent missing for entity ID: " + std::to_string(currentEntity->GetID()), __FILE__, __LINE__, Logger::LogLevel::Warning);
|
LOG_WARNING("RenderComponent missing for entity ID: " + std::to_string(currentEntity->GetID()));
|
||||||
}
|
}
|
||||||
|
|
||||||
currentTextures = renderComponent->GetTextureContainerBuffer();
|
currentTextures = renderComponent->GetTextureContainerBuffer();
|
||||||
@@ -185,7 +183,7 @@ bool scene_manager::load_scene() {
|
|||||||
|
|
||||||
// Pr<50>charger les textures
|
// Pr<50>charger les textures
|
||||||
if (!model->PreloadTextures(direct_3d_->get_device(), direct_3d_->get_device_context(), currentTextures)) {
|
if (!model->PreloadTextures(direct_3d_->get_device(), direct_3d_->get_device_context(), currentTextures)) {
|
||||||
Logger::Get().Log("<EFBFBD>chec du pr<70>chargement des textures", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("<EFBFBD>chec du pr<70>chargement des textures");
|
||||||
}
|
}
|
||||||
|
|
||||||
char modelFilename[256];
|
char modelFilename[256];
|
||||||
@@ -193,7 +191,7 @@ bool scene_manager::load_scene() {
|
|||||||
wcstombs_s(&convertedChars, modelFilename, sizeof(modelFilename), modelPath.c_str(), _TRUNCATE);
|
wcstombs_s(&convertedChars, modelFilename, sizeof(modelFilename), modelPath.c_str(), _TRUNCATE);
|
||||||
|
|
||||||
if (!model->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), modelFilename, currentTextures)) {
|
if (!model->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), modelFilename, currentTextures)) {
|
||||||
Logger::Get().Log("<EFBFBD>chec d'initialisation du mod<6F>le", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("<EFBFBD>chec d'initialisation du mod<6F>le");
|
||||||
} else {
|
} else {
|
||||||
// Ajouter au cache
|
// Ajouter au cache
|
||||||
modelCache[modelKey] = model;
|
modelCache[modelKey] = model;
|
||||||
@@ -221,7 +219,7 @@ bool scene_manager::load_scene() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::Get().Log("Sc<EFBFBD>ne charg<72>e avec succ<63>s", __FILE__, __LINE__, Logger::LogLevel::Info);
|
LOG_INFO("Sc<EFBFBD>ne charg<72>e avec succ<63>s");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,10 +230,9 @@ bool scene_manager::save_scene() {
|
|||||||
if (scene_path_.empty() && !save_scene_as()) {
|
if (scene_path_.empty() && !save_scene_as()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ofstream outFile(scene_path_);
|
std::ofstream outFile(scene_path_);
|
||||||
if (!outFile.is_open()) {
|
if (!outFile.is_open()) {
|
||||||
Logger::Get().Log("<EFBFBD>chec de l'ouverture du fichier", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("<EFBFBD>chec de l'ouverture du fichier");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,7 +256,7 @@ bool scene_manager::save_scene() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
outFile.close();
|
outFile.close();
|
||||||
Logger::Get().Log("Sc<EFBFBD>ne sauvegard<72>e avec succ<63>s: " + scene_path_, __FILE__, __LINE__, Logger::LogLevel::Info);
|
LOG_INFO("Sc<EFBFBD>ne sauvegard<72>e avec succ<63>s: " + scene_path_);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,4 +295,3 @@ std::string scene_manager::convert_w_string_to_string(const std::wstring& wstr)
|
|||||||
WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &str[0], size_needed, NULL, NULL);
|
WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &str[0], size_needed, NULL, NULL);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ stats::~stats()
|
|||||||
bool stats::initialize(application_class* app)
|
bool stats::initialize(application_class* app)
|
||||||
{
|
{
|
||||||
if (!app) {
|
if (!app) {
|
||||||
Logger::Get().Log("Application pointer is null", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Application pointer is null");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,11 +25,11 @@ bool stats::initialize(application_class* app)
|
|||||||
fps_ = app_->get_fps();
|
fps_ = app_->get_fps();
|
||||||
|
|
||||||
if (!fps_) {
|
if (!fps_) {
|
||||||
Logger::Get().Log("FPS object is null", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("FPS object is null");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::Get().Log("Stats initialized successfully", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
LOG_INIT("Stats initialized successfully");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -44,7 +44,7 @@ void stats::update_geometric_stats()
|
|||||||
|
|
||||||
update_visible_count();
|
update_visible_count();
|
||||||
|
|
||||||
Logger::Get().Log("Statistics updated: " + std::to_string(*total_vertex_count_) + " vertices, " + std::to_string(*total_triangle_count_) + " triangles", __FILE__, __LINE__, Logger::LogLevel::Debug);
|
LOG_DEBUG("Statistics updated: " + std::to_string(*total_vertex_count_) + " vertices, " + std::to_string(*total_triangle_count_) + " triangles");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ bool system_class::initialize()
|
|||||||
int screenHeight, screenWidth = 0;
|
int screenHeight, screenWidth = 0;
|
||||||
bool result;
|
bool result;
|
||||||
|
|
||||||
Logger::Get().Log("Initializing system class", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
LOG_INIT("Initializing system class");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -40,7 +40,7 @@ bool system_class::initialize()
|
|||||||
result = input_->Initialize(hinstance_, hwnd_, screenWidth, screenHeight);
|
result = input_->Initialize(hinstance_, hwnd_, screenWidth, screenHeight);
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to initialize input class", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to initialize input class");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,25 +76,25 @@ bool system_class::initialize()
|
|||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
Logger::Get().Log(std::string("Exception caught during initialization: ") + e.what(), __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR(std::string("Exception caught during initialization: ") + e.what());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::Get().Log("System class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
LOG_INIT("System class initialized");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void system_class::shutdown()
|
void system_class::shutdown()
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Shutting down system class", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
|
LOG_SHUTDOWN("Shutting down system class");
|
||||||
|
|
||||||
std::lock_guard<std::mutex> guard(render_mutex_);
|
std::lock_guard<std::mutex> guard(render_mutex_);
|
||||||
|
|
||||||
// shutdown the window.
|
// shutdown the window.
|
||||||
shutdown_windows();
|
shutdown_windows();
|
||||||
|
|
||||||
Logger::Get().Log("System class shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
|
LOG_SHUTDOWN("System class shut down");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@ void system_class::run()
|
|||||||
MSG msg;
|
MSG msg;
|
||||||
bool done, result;
|
bool done, result;
|
||||||
|
|
||||||
Logger::Get().Log("Running the system", __FILE__, __LINE__);
|
LOG_INFO("Running the system", __FILE__, __LINE__);
|
||||||
|
|
||||||
// initialize the message structure.
|
// initialize the message structure.
|
||||||
ZeroMemory(&msg, sizeof(MSG));
|
ZeroMemory(&msg, sizeof(MSG));
|
||||||
@@ -130,7 +130,7 @@ void system_class::run()
|
|||||||
// If windows signals to end the application then exit out.
|
// If windows signals to end the application then exit out.
|
||||||
if (application_ != nullptr && application_->get_should_quit())
|
if (application_ != nullptr && application_->get_should_quit())
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Received quit signal from application", __FILE__, __LINE__);
|
LOG_INFO("Received quit signal from application", __FILE__, __LINE__);
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -141,7 +141,7 @@ void system_class::run()
|
|||||||
result = frame();
|
result = frame();
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to process frame", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to process frame");
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
fps_limiter_->set_target_fps(application_->get_target_fps());
|
fps_limiter_->set_target_fps(application_->get_target_fps());
|
||||||
@@ -165,7 +165,7 @@ bool system_class::frame()
|
|||||||
result = input_->Frame();
|
result = input_->Frame();
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to process input frame", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to process input frame");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@ bool system_class::frame()
|
|||||||
result = application_->frame(input_.get());
|
result = application_->frame(input_.get());
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to process application frame", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to process application frame");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,7 +195,7 @@ bool system_class::frame()
|
|||||||
result = imgui_manager_->ImGuiWidgetRenderer();
|
result = imgui_manager_->ImGuiWidgetRenderer();
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to render ImGui widgets", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to render ImGui widgets");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -291,7 +291,7 @@ LRESULT CALLBACK system_class::message_handler(HWND hwnd, UINT umsg, WPARAM wpar
|
|||||||
}
|
}
|
||||||
case WM_CLOSE:
|
case WM_CLOSE:
|
||||||
{
|
{
|
||||||
Logger::Get().Log("WM_CLOSE message received", __FILE__, __LINE__);
|
LOG_INFO("WM_CLOSE message received", __FILE__, __LINE__);
|
||||||
application_->set_should_quit(true);
|
application_->set_should_quit(true);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -312,7 +312,7 @@ void system_class::initialize_windows(int& screenWidth, int& screenHeight)
|
|||||||
DEVMODE dmScreenSettings;
|
DEVMODE dmScreenSettings;
|
||||||
int posX, posY;
|
int posX, posY;
|
||||||
|
|
||||||
Logger::Get().Log("Initializing windows", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
LOG_INIT("Initializing windows");
|
||||||
// Get an external pointer to this object.
|
// Get an external pointer to this object.
|
||||||
application_handle = this;
|
application_handle = this;
|
||||||
|
|
||||||
@@ -392,7 +392,7 @@ void system_class::initialize_windows(int& screenWidth, int& screenHeight)
|
|||||||
|
|
||||||
void system_class::shutdown_windows()
|
void system_class::shutdown_windows()
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Shutting down the windows", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
|
LOG_SHUTDOWN("Shutting down the windows");
|
||||||
// Show the mouse cursor.
|
// Show the mouse cursor.
|
||||||
ShowCursor(true);
|
ShowCursor(true);
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ texture_class::~texture_class()
|
|||||||
|
|
||||||
bool texture_class::Initialize(ID3D11Device * device, ID3D11DeviceContext * deviceContext, std::string filename)
|
bool texture_class::Initialize(ID3D11Device * device, ID3D11DeviceContext * deviceContext, std::string filename)
|
||||||
{
|
{
|
||||||
Logger::Get().Log(("Iinitializing texture: %s", filename), __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
LOG_INIT("Initializing texture: " + filename);
|
||||||
|
|
||||||
bool result;
|
bool result;
|
||||||
D3D11_TEXTURE2D_DESC textureDesc;
|
D3D11_TEXTURE2D_DESC textureDesc;
|
||||||
@@ -46,13 +46,13 @@ bool texture_class::Initialize(ID3D11Device * device, ID3D11DeviceContext * devi
|
|||||||
textureDesc.CPUAccessFlags = 0;
|
textureDesc.CPUAccessFlags = 0;
|
||||||
textureDesc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;
|
textureDesc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;
|
||||||
|
|
||||||
// Create the empty texture.
|
// Create the empty texture.
|
||||||
hResult = device->CreateTexture2D(&textureDesc, NULL, &m_texture);
|
hResult = device->CreateTexture2D(&textureDesc, NULL, &m_texture);
|
||||||
if (FAILED(hResult))
|
if (FAILED(hResult))
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to create texture", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to create texture");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the row pitch of the targa image data.
|
// Set the row pitch of the targa image data.
|
||||||
rowPitch = (m_width * 4) * sizeof(unsigned char);
|
rowPitch = (m_width * 4) * sizeof(unsigned char);
|
||||||
@@ -64,13 +64,13 @@ bool texture_class::Initialize(ID3D11Device * device, ID3D11DeviceContext * devi
|
|||||||
srvDesc.Texture2D.MostDetailedMip = 0;
|
srvDesc.Texture2D.MostDetailedMip = 0;
|
||||||
srvDesc.Texture2D.MipLevels = -1;
|
srvDesc.Texture2D.MipLevels = -1;
|
||||||
|
|
||||||
// Create the shader resource view for the texture.
|
// Create the shader resource view for the texture.
|
||||||
hResult = device->CreateShaderResourceView(m_texture, &srvDesc, &m_textureView);
|
hResult = device->CreateShaderResourceView(m_texture, &srvDesc, &m_textureView);
|
||||||
if (FAILED(hResult))
|
if (FAILED(hResult))
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to create shader resource view", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to create shader resource view");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate mipmaps for this texture.
|
// Generate mipmaps for this texture.
|
||||||
deviceContext->GenerateMips(m_textureView);
|
deviceContext->GenerateMips(m_textureView);
|
||||||
@@ -79,21 +79,20 @@ bool texture_class::Initialize(ID3D11Device * device, ID3D11DeviceContext * devi
|
|||||||
delete[] m_targaData;
|
delete[] m_targaData;
|
||||||
m_targaData = 0;
|
m_targaData = 0;
|
||||||
|
|
||||||
Logger::Get().Log("Texture initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
LOG_INIT("Texture initialized");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void texture_class::Shutdown()
|
void texture_class::Shutdown()
|
||||||
{
|
{
|
||||||
|
LOG_SHUTDOWN("Shutting down texture");
|
||||||
Logger::Get().Log("Shutting down texture", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
|
// Release the texture view resource.
|
||||||
// Release the texture view resource.
|
if (m_textureView)
|
||||||
if (m_textureView)
|
{
|
||||||
{
|
m_textureView->Release();
|
||||||
m_textureView->Release();
|
m_textureView = 0;
|
||||||
m_textureView = 0;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Release the texture.
|
// Release the texture.
|
||||||
if (m_texture)
|
if (m_texture)
|
||||||
@@ -109,7 +108,7 @@ void texture_class::Shutdown()
|
|||||||
m_targaData = 0;
|
m_targaData = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::Get().Log("Texture shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
|
LOG_SHUTDOWN("Texture shut down");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -121,42 +120,41 @@ ID3D11ShaderResourceView* texture_class::GetTexture()
|
|||||||
|
|
||||||
bool texture_class::LoadTarga(std::string filename)
|
bool texture_class::LoadTarga(std::string filename)
|
||||||
{
|
{
|
||||||
|
LOG_INFO("Loading targa file: " + filename);
|
||||||
Logger::Get().Log(("Loading targa file: %s", filename), __FILE__, __LINE__);
|
int error, bpp, imageSize, index, i, j, k;
|
||||||
int error, bpp, imageSize, index, i, j, k;
|
FILE* filePtr;
|
||||||
FILE* filePtr;
|
unsigned int count;
|
||||||
unsigned int count;
|
TargaHeader targaFileHeader;
|
||||||
TargaHeader targaFileHeader;
|
unsigned char* targaImage;
|
||||||
unsigned char* targaImage;
|
|
||||||
|
|
||||||
|
|
||||||
// Open the targa file for reading in binary.
|
// Open the targa file for reading in binary.
|
||||||
error = fopen_s(&filePtr, filename.c_str(), "rb");
|
error = fopen_s(&filePtr, filename.c_str(), "rb");
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to open targa file. Working directory: " + std::filesystem::current_path().string(), __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to open targa file. Working directory: " + std::filesystem::current_path().string());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read in the file header.
|
// Read in the file header.
|
||||||
count = (unsigned int)fread(&targaFileHeader, sizeof(TargaHeader), 1, filePtr);
|
count = (unsigned int)fread(&targaFileHeader, sizeof(TargaHeader), 1, filePtr);
|
||||||
if (count != 1)
|
if (count != 1)
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to read targa file header", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to read targa file header");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the important information from the header.
|
// Get the important information from the header.
|
||||||
m_height = (int)targaFileHeader.height;
|
m_height = (int)targaFileHeader.height;
|
||||||
m_width = (int)targaFileHeader.width;
|
m_width = (int)targaFileHeader.width;
|
||||||
bpp = (int)targaFileHeader.bpp;
|
bpp = (int)targaFileHeader.bpp;
|
||||||
|
|
||||||
// Check that it is 32 bit and not 24 bit.
|
// Check that it is 32 bit and not 24 bit.
|
||||||
if (bpp != 32 && bpp != 24)
|
if (bpp != 32 && bpp != 24)
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Targa file is not 32 or 24 bit", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Targa file is not 32 or 24 bit");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the size of the 32 bit image data.
|
// Calculate the size of the 32 bit image data.
|
||||||
imageSize = m_width * m_height * (bpp / 8);
|
imageSize = m_width * m_height * (bpp / 8);
|
||||||
@@ -164,21 +162,21 @@ bool texture_class::LoadTarga(std::string filename)
|
|||||||
// Allocate memory for the targa image data.
|
// Allocate memory for the targa image data.
|
||||||
targaImage = new unsigned char[imageSize];
|
targaImage = new unsigned char[imageSize];
|
||||||
|
|
||||||
// Read in the targa image data.
|
// Read in the targa image data.
|
||||||
count = (unsigned int)fread(targaImage, 1, imageSize, filePtr);
|
count = (unsigned int)fread(targaImage, 1, imageSize, filePtr);
|
||||||
if (count != imageSize)
|
if (count != imageSize)
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to read targa image data", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to read targa image data");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the file.
|
// Close the file.
|
||||||
error = fclose(filePtr);
|
error = fclose(filePtr);
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Failed to close targa file", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Failed to close targa file");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate memory for the targa destination data.
|
// Allocate memory for the targa destination data.
|
||||||
m_targaData = new unsigned char[imageSize];
|
m_targaData = new unsigned char[imageSize];
|
||||||
@@ -189,44 +187,44 @@ bool texture_class::LoadTarga(std::string filename)
|
|||||||
// Initialize the index into the targa image data.
|
// Initialize the index into the targa image data.
|
||||||
k = (m_width * m_height * (bpp / 8)) - (m_width * (bpp / 8));
|
k = (m_width * m_height * (bpp / 8)) - (m_width * (bpp / 8));
|
||||||
|
|
||||||
// Now copy the targa image data into the targa destination array in the correct order since the targa format is stored upside down and also is not in RGBA order.
|
// Now copy the targa image data into the targa destination array in the correct order since the targa format is stored upside down and also is not in RGBA order.
|
||||||
for (j = 0; j < m_height; j++)
|
for (j = 0; j < m_height; j++)
|
||||||
{
|
{
|
||||||
for (i = 0; i < m_width; i++)
|
for (i = 0; i < m_width; i++)
|
||||||
{
|
{
|
||||||
if (index + 3 < imageSize) // Ajout de la v<>rification ici
|
if (index + 3 < imageSize) // Ajout de la v<>rification ici
|
||||||
{
|
{
|
||||||
m_targaData[index + 0] = targaImage[k + 2]; // Red.
|
m_targaData[index + 0] = targaImage[k + 2]; // Red.
|
||||||
m_targaData[index + 1] = targaImage[k + 1]; // Green.
|
m_targaData[index + 1] = targaImage[k + 1]; // Green.
|
||||||
m_targaData[index + 2] = targaImage[k + 0]; // Blue
|
m_targaData[index + 2] = targaImage[k + 0]; // Blue
|
||||||
if (bpp == 32)
|
if (bpp == 32)
|
||||||
{
|
{
|
||||||
m_targaData[index + 3] = targaImage[k + 3]; // Alpha
|
m_targaData[index + 3] = targaImage[k + 3]; // Alpha
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Index out of bounds", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("Index out of bounds");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Increment the indexes into the targa data.
|
// Increment the indexes into the targa data.
|
||||||
k += (bpp / 8);
|
k += (bpp / 8);
|
||||||
index += (bpp / 8);
|
index += (bpp / 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the targa image data index back to the preceding row at the beginning of the column since its reading it in upside down.
|
// Set the targa image data index back to the preceding row at the beginning of the column since its reading it in upside down.
|
||||||
k -= (m_width * (bpp / 8) * 2);
|
k -= (m_width * (bpp / 8) * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Release the targa image data now that it was copied into the destination array.
|
// Release the targa image data now that it was copied into the destination array.
|
||||||
delete[] targaImage;
|
delete[] targaImage;
|
||||||
targaImage = 0;
|
targaImage = 0;
|
||||||
|
|
||||||
Logger::Get().Log(("targa file %s loaded", filename), __FILE__, __LINE__);
|
LOG_INFO("targa file " + filename + " loaded");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ timer_class::~timer_class()
|
|||||||
|
|
||||||
bool timer_class::Initialize()
|
bool timer_class::Initialize()
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Initilazing timer class", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
LOG_INIT("Initilazing timer class");
|
||||||
|
|
||||||
INT64 frequency;
|
INT64 frequency;
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ bool timer_class::Initialize()
|
|||||||
QueryPerformanceFrequency((LARGE_INTEGER*)&frequency);
|
QueryPerformanceFrequency((LARGE_INTEGER*)&frequency);
|
||||||
if (frequency == 0)
|
if (frequency == 0)
|
||||||
{
|
{
|
||||||
Logger::Get().Log("QueryPerformanceFrequency failed", __FILE__, __LINE__, Logger::LogLevel::Error);
|
LOG_ERROR("QueryPerformanceFrequency failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ bool timer_class::Initialize()
|
|||||||
// Get the initial start time.
|
// Get the initial start time.
|
||||||
QueryPerformanceCounter((LARGE_INTEGER*)&m_startTime);
|
QueryPerformanceCounter((LARGE_INTEGER*)&m_startTime);
|
||||||
|
|
||||||
Logger::Get().Log("Timer class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
LOG_INIT("Timer class initialized");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user