diff --git a/KhaoticDemo/main.cpp b/KhaoticDemo/main.cpp index e69de29..b6ed93c 100644 --- a/KhaoticDemo/main.cpp +++ b/KhaoticDemo/main.cpp @@ -0,0 +1,4 @@ +int main() +{ + return 0; +} \ No newline at end of file diff --git a/enginecustom/Logger.h b/enginecustom/Logger.h new file mode 100644 index 0000000..a5f6bf6 --- /dev/null +++ b/enginecustom/Logger.h @@ -0,0 +1,82 @@ +#pragma once +#include +#include +#include +#include +#include +#include + +class Logger +{ +public: + + enum class LogLevel + { + Info, + Warning, + Error + }; + + Logger() + { + char* appdata = nullptr; + size_t len; + _dupenv_s(&appdata, &len, "APPDATA"); + if (appdata == 0 ||appdata == nullptr) + { + m_appdataPath = "log.log"; + } + else + { + m_appdataPath = appdata; + } + free(appdata); + std::string directoryPath = m_appdataPath + "\\Khaotic Engine"; + CreateDirectoryA(directoryPath.c_str(), NULL); + + m_logFilePath = directoryPath + "\\" + m_logFileName; + } + + void Log(const std::string& message, const std::string& fileName, int lineNumber, LogLevel level = LogLevel::Info) + { + auto now = std::chrono::system_clock::now(); + auto in_time_t = std::chrono::system_clock::to_time_t(now); + + std::tm buf; + localtime_s(&buf, &in_time_t); + + std::string levelStr; + switch (level) + { + case LogLevel::Error: + levelStr = "ERROR"; + break; + case LogLevel::Warning: + levelStr = "WARNING"; + break; + case LogLevel::Info: + levelStr = "INFO"; + break; + } + + std::stringstream ss; + ss << "[" << std::put_time(&buf, "%Y-%m-%d") << "] " + << "[" << std::put_time(&buf, "%X") << "] " + << "[" << levelStr << "] " + << "[" << fileName << ":" << lineNumber << "] " + << message; + + std::ofstream file(m_logFilePath, std::ios::app); + if (file.is_open()) + { + file << ss.str() << std::endl; + file.close(); + } + } + +private: + std::string m_filename; + std::string m_appdataPath; + std::string m_logFileName = "enginecustom.log"; + std::string m_logFilePath; +}; diff --git a/enginecustom/Main.cpp b/enginecustom/Main.cpp index 1ea2604..3eab9ff 100644 --- a/enginecustom/Main.cpp +++ b/enginecustom/Main.cpp @@ -5,6 +5,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pScmdline, { SystemClass* System; bool result; + Logger logger; // Create the system object. @@ -14,6 +15,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pScmdline, result = System->Initialize(); if (result) { + logger.Log("System initialized", __FILE__, __LINE__); System->Run(); } diff --git a/enginecustom/Systemclass.cpp b/enginecustom/Systemclass.cpp index 7abe5e4..1975ca3 100644 --- a/enginecustom/Systemclass.cpp +++ b/enginecustom/Systemclass.cpp @@ -4,18 +4,18 @@ #include extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); -SystemClass::SystemClass() +SystemClass::SystemClass() : logger() { m_Input = 0; m_Application = 0; m_imguiManager = 0; + } SystemClass::SystemClass(const SystemClass& other) { } - SystemClass::~SystemClass() { } @@ -25,48 +25,63 @@ bool SystemClass::Initialize() int screenWidth, screenHeight; bool result; + logger.Log("Initializing system class", __FILE__, __LINE__); - // Initialize the width and height of the screen to zero before sending the variables into the function. - screenWidth = 0; - screenHeight = 0; - - m_initialWindowWidth = 0; - m_initialWindowHeight = 0; - m_isDirect3DInitialized = false; - - // Initialize the windows api. - InitializeWindows(screenWidth, screenHeight); - - // Create and initialize the input object. This object will be used to handle reading the keyboard input from the user. - m_Input = new InputClass; - - result = m_Input->Initialize(m_hinstance, m_hwnd, screenWidth, screenHeight); - if (!result) + try { + // Initialize the width and height of the screen to zero before sending the variables into the function. + screenWidth = 0; + screenHeight = 0; + + m_initialWindowWidth = 0; + m_initialWindowHeight = 0; + m_isDirect3DInitialized = false; + + // Initialize the windows api. + InitializeWindows(screenWidth, screenHeight); + + // Create and initialize the input object. This object will be used to handle reading the keyboard input from the user. + m_Input = new InputClass; + + result = m_Input->Initialize(m_hinstance, m_hwnd, screenWidth, screenHeight); + if (!result) + { + logger.Log("Failed to initialize input class", __FILE__, __LINE__, Logger::LogLevel::Error); + return false; + } + + // Create and initialize the application class object. This object will handle rendering all the graphics for this application. + m_Application = new ApplicationClass; + + result = m_Application->Initialize(screenWidth, screenHeight, m_hwnd); + if (!result) + { + return false; + } + + m_isDirect3DInitialized = true; + + // If we received a WM_SIZE message before Direct3D was initialized, resize the swap chain now + if (m_initialWindowWidth > 0 && m_initialWindowHeight > 0) + { + m_Application->GetDirect3D()->ResizeSwapChain(m_initialWindowWidth, m_initialWindowHeight); + } + + // Initialize imgui + m_imguiManager = new imguiManager; + result = m_imguiManager->Initialize(m_hwnd, m_Application->GetDirect3D()->GetDevice(), m_Application->GetDirect3D()->GetDeviceContext()); + if (!result) + { + return false; + } + } + catch (const std::exception& e) + { + logger.Log(std::string("Exception caught during initialization: ") + e.what(), __FILE__, __LINE__, Logger::LogLevel::Error); return false; } - // Create and initialize the application class object. This object will handle rendering all the graphics for this application. - m_Application = new ApplicationClass; - - result = m_Application->Initialize(screenWidth, screenHeight, m_hwnd); - if (!result) - { - return false; - } - - m_isDirect3DInitialized = true; - - // If we received a WM_SIZE message before Direct3D was initialized, resize the swap chain now - if (m_initialWindowWidth > 0 && m_initialWindowHeight > 0) - { - m_Application->GetDirect3D()->ResizeSwapChain(m_initialWindowWidth, m_initialWindowHeight); - } - - // Initialize imgui - m_imguiManager = new imguiManager; - m_imguiManager->Initialize(m_hwnd, m_Application->GetDirect3D()->GetDevice(), m_Application->GetDirect3D()->GetDeviceContext()); - + logger.Log("System class initialized", __FILE__, __LINE__); return true; } @@ -107,6 +122,8 @@ void SystemClass::Run() MSG msg; bool done, result; + logger.Log("Running the system", __FILE__, __LINE__); + // Initialize the message structure. ZeroMemory(&msg, sizeof(MSG)); @@ -124,6 +141,7 @@ void SystemClass::Run() // If windows signals to end the application then exit out. if (msg.message == WM_QUIT) { + logger.Log("WM_QUIT message received", __FILE__, __LINE__); done = true; } else @@ -132,6 +150,7 @@ void SystemClass::Run() result = Frame(); if (!result) { + logger.Log("Failed to process frame", __FILE__, __LINE__, Logger::LogLevel::Error); done = true; } } @@ -149,6 +168,7 @@ bool SystemClass::Frame() result = m_Input->Frame(); if (!result) { + logger.Log("Failed to process input frame", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -156,6 +176,7 @@ bool SystemClass::Frame() result = m_Application->Frame(m_Input); if (!result) { + logger.Log("Failed to process application frame", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -263,7 +284,7 @@ void SystemClass::InitializeWindows(int& screenWidth, int& screenHeight) DEVMODE dmScreenSettings; int posX, posY; - + logger.Log("Initializing windows", __FILE__, __LINE__); // Get an external pointer to this object. ApplicationHandle = this; @@ -343,6 +364,8 @@ void SystemClass::InitializeWindows(int& screenWidth, int& screenHeight) void SystemClass::ShutdownWindows() { + + logger.Log("Shutting down the windows", __FILE__, __LINE__); // Show the mouse cursor. ShowCursor(true); diff --git a/enginecustom/applicationclass.cpp b/enginecustom/applicationclass.cpp index cb466a9..5b4c74e 100644 --- a/enginecustom/applicationclass.cpp +++ b/enginecustom/applicationclass.cpp @@ -38,296 +38,292 @@ ApplicationClass::~ApplicationClass() bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd) { - char mouseString1[32], mouseString2[32], mouseString3[32]; - char modelFilename[128], textureFilename1[128], textureFilename2[128], textureFilename3[128], textureFilename4[128], textureFilename5[128], textureFilename6[128], renderString[32]; - char bitmapFilename[128]; - char spriteFilename[128]; - char fpsString[32]; - bool result; - m_screenWidth = screenWidth; - m_screenHeight = screenHeight; + logger.Log("Initializing application class", __FILE__, __LINE__); - // Create the Direct3D object. - m_Direct3D = new D3DClass; - if (!m_Direct3D) + try { + char mouseString1[32], mouseString2[32], mouseString3[32]; + char modelFilename[128], textureFilename1[128], textureFilename2[128], textureFilename3[128], textureFilename4[128], textureFilename5[128], textureFilename6[128], renderString[32]; + char bitmapFilename[128]; + char spriteFilename[128]; + char fpsString[32]; + bool result; + + m_screenWidth = screenWidth; + m_screenHeight = screenHeight; + + // Create the Direct3D object. + m_Direct3D = new D3DClass; + if (!m_Direct3D) + { + logger.Log("Could not create the Direct3D object", __FILE__, __LINE__, Logger::LogLevel::Error); + return false; + } + + result = m_Direct3D->Initialize(screenWidth, screenHeight, VSYNC_ENABLED, hwnd, FULL_SCREEN, SCREEN_DEPTH, SCREEN_NEAR); + if (!result) + { + logger.Log("Could not initialize Direct3D", __FILE__, __LINE__, Logger::LogLevel::Error); + return false; + } + + // Create the camera object. + m_Camera = new CameraClass; + if (!m_Camera) + { + logger.Log("Could not create the camera object", __FILE__, __LINE__, Logger::LogLevel::Error); + return false; + } + + // Set the initial position of the camera. + m_Camera->SetPosition(0.0f, 0.0f, -12.0f); + m_Camera->SetRotation(0.0f, 0.0f, 0.0f); + m_Camera->Render(); + m_Camera->GetViewMatrix(m_baseViewMatrix); + + // Create and initialize the font shader object. + m_FontShader = new FontShaderClass; + + result = m_FontShader->Initialize(m_Direct3D->GetDevice(), hwnd); + if (!result) + { + logger.Log("Could not initialize the font shader object", __FILE__, __LINE__, Logger::LogLevel::Error); + return false; + } + + // Create and initialize the font object. + m_Font = new FontClass; + + result = m_Font->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), 0); + if (!result) + { + logger.Log("Could not initialize the font object", __FILE__, __LINE__, Logger::LogLevel::Error); + return false; + } + + // Create and initialize the texture shader object. + m_TextureShader = new TextureShaderClass; + + result = m_TextureShader->Initialize(m_Direct3D->GetDevice(), hwnd); + if (!result) + { + logger.Log("Could not initialize the texture shader object", __FILE__, __LINE__, Logger::LogLevel::Error); + return false; + } + + + // Create and initialize the render to texture object. + m_RenderTexture = new RenderTextureClass; + + result = m_RenderTexture->Initialize(m_Direct3D->GetDevice(), 256, 256, SCREEN_DEPTH, SCREEN_NEAR, 1); + if (!result) + { + logger.Log("Could not initialize the render texture object", __FILE__, __LINE__, Logger::LogLevel::Error); + return false; + } + + // Create and initialize the display plane object. + m_DisplayPlane = new DisplayPlaneClass; + + result = m_DisplayPlane->Initialize(m_Direct3D->GetDevice(), 1.0f, 1.0f); + if (!result) + { + logger.Log("Could not initialize the display plane object", __FILE__, __LINE__, Logger::LogLevel::Error); + return false; + } + + + // Set the sprite info file we will be using. + strcpy_s(spriteFilename, "sprite_data_01.txt"); + + // Create and initialize the sprite object. + m_Sprite = new SpriteClass; + + result = m_Sprite->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), screenWidth, screenHeight, spriteFilename, 50, 50); + if (!result) + { + logger.Log("Could not initialize the sprite object", __FILE__, __LINE__, Logger::LogLevel::Error); + return false; + } + + // Set the initial mouse strings. + strcpy_s(mouseString1, "Mouse X: 0"); + strcpy_s(mouseString2, "Mouse Y: 0"); + strcpy_s(mouseString3, "Mouse Button: No"); + + // Create and initialize the text objects for the mouse strings. + m_MouseStrings = new TextClass[3]; + + for (int i = 0; i < 3; i++) + { + int y = 10 + (i * 25); + result = m_MouseStrings[i].Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), screenWidth, screenHeight, 32, m_Font, mouseString1, 10, y, 1.0f, 1.0f, 1.0f); + if (!result) + { + logger.Log("Could not initialize the mouse strings", __FILE__, __LINE__, Logger::LogLevel::Error); + return false; + } + } + + // Set the file name of the bitmap file. + strcpy_s(bitmapFilename, "stone01.tga"); + + // Create and initialize the bitmap object. + m_Bitmap = new BitmapClass; + + result = m_Bitmap->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), screenWidth, screenHeight, bitmapFilename, 50, 50); + if (!result) + { + logger.Log("Could not initialize the bitmap object", __FILE__, __LINE__, Logger::LogLevel::Error); + return false; + } + + // Set the file name of the model. + strcpy_s(modelFilename, "cube.txt"); + + // Set the file name of the textures. + strcpy_s(textureFilename1, "stone01.tga"); + strcpy_s(textureFilename2, "normal01.tga"); + strcpy_s(textureFilename3, "spec02.tga"); + strcpy_s(textureFilename4, "alpha01.tga"); + strcpy_s(textureFilename5, "light01.tga"); + strcpy_s(textureFilename6, "moss01.tga"); + + // Create and initialize the model object. + m_Model = new ModelClass; + + result = m_Model->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textureFilename1, textureFilename2, textureFilename3, textureFilename4, + textureFilename5, textureFilename6); + if (!result) + { + logger.Log("Could not initialize the model object", __FILE__, __LINE__, Logger::LogLevel::Error); + return false; + } + + // Create and initialize the light shader object. + m_LightShader = new LightShaderClass; + + result = m_LightShader->Initialize(m_Direct3D->GetDevice(), hwnd); + if (!result) + { + logger.Log("Could not initialize the light shader object", __FILE__, __LINE__, Logger::LogLevel::Error); + return false; + } + + // Create and initialize the light object. + m_Light = new LightClass; + + m_Light->SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f); + m_Light->SetDirection(0.0f, 0.0f, -1.0f); + m_Light->SetSpecularColor(1.0f, 1.0f, 1.0f, 1.0f); + m_Light->SetSpecularPower(16.0f); + + // Set the number of lights we will use. + m_numLights = 4; + + // Create and initialize the light objects array. + m_Lights.resize(m_numLights); + + m_Lights[0] = new LightClass; + m_Lights[0]->SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f); // White + m_Lights[0]->SetDirection(0.0f, 0.0f, -1.0f); + m_Lights[0]->SetSpecularColor(1.0f, 1.0f, 1.0f, 1.0f); + m_Lights[0]->SetSpecularPower(16.0f); + m_Lights[0]->SetPosition(10.0f, 7.0f, -5.0f); + + // Manually set the color and position of each light. + m_Lights[1] = new LightClass; + m_Lights[1]->SetDiffuseColor(1.0f, 0.0f, 0.0f, 1.0f); // Red + m_Lights[1]->SetDirection(0.0f, 0.0f, 1.0f); + m_Lights[1]->SetSpecularColor(1.0f, 0.0f, 0.0f, 1.0f); + m_Lights[1]->SetSpecularPower(16.0f); + m_Lights[1]->SetPosition(10.0f, 7.0f, -5.0f); + + m_Lights[2] = new LightClass; + m_Lights[2]->SetDiffuseColor(0.0f, 1.0f, 0.0f, 1.0f); // Green + m_Lights[2]->SetDirection(0.0f, 0.0f, 1.0f); + m_Lights[2]->SetSpecularColor(0.0f, 1.0f, 0.0f, 1.0f); + m_Lights[2]->SetSpecularPower(16.0f); + m_Lights[2]->SetPosition(10.0f, 7.0f, -5.0f); + + m_Lights[3] = new LightClass; + m_Lights[3]->SetDiffuseColor(0.0f, 0.0f, 1.0f, 1.0f); // Blue + m_Lights[3]->SetDirection(0.0f, 0.0f, 1.0f); + m_Lights[3]->SetSpecularColor(0.0f, 0.0f, 1.0f, 1.0f); + m_Lights[3]->SetSpecularPower(16.0f); + m_Lights[3]->SetPosition(10.0f, 7.0f, -5.0f); + + + // Create and initialize the normal map shader object. + m_ShaderManager = new ShaderManagerClass; + + result = m_ShaderManager->Initialize(m_Direct3D->GetDevice(), hwnd); + if (!result) + { + logger.Log("Could not initialize the shader manager object", __FILE__, __LINE__, Logger::LogLevel::Error); + return false; + } + + // Set the initial render count string. + strcpy_s(renderString, "Render Count: 0"); + + // Create and initialize the text object for the render count string. + m_RenderCountString = new TextClass; + + result = m_RenderCountString->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), screenWidth, screenHeight, 32, m_Font, renderString, 10, 10, 1.0f, 1.0f, 1.0f); + if (!result) + { + logger.Log("Could not initialize the render count string", __FILE__, __LINE__, Logger::LogLevel::Error); + return false; + } + + // Create and initialize the model list object. + m_ModelList = new ModelListClass; + m_ModelList->Initialize(25); + + // Create and initialize the timer object. + m_Timer = new TimerClass; + + result = m_Timer->Initialize(); + if (!result) + { + logger.Log("Could not initialize the timer object", __FILE__, __LINE__, Logger::LogLevel::Error); + return false; + } + + // Create the position class object. + m_Position = new PositionClass; + + // Create the frustum class object. + m_Frustum = new FrustumClass; + + // Create and initialize the fps object. + m_Fps = new FpsClass(); + + m_Fps->Initialize(); + + // Set the initial fps and fps string. + m_previousFps = -1; + strcpy_s(fpsString, "Fps: 0"); + + // Create and initialize the text object for the fps string. + m_FpsString = new TextClass; + + result = m_FpsString->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), screenWidth, screenHeight, 32, m_Font, fpsString, 10, 10, 0.0f, 1.0f, 0.0f); + if (!result) + { + logger.Log("Could not initialize the fps string", __FILE__, __LINE__, Logger::LogLevel::Error); + return false; + } + } + catch (const std::exception& e) + { + logger.Log(std::string("Exception caught during initialization: ") + e.what(), __FILE__, __LINE__, Logger::LogLevel::Error); return false; } - result = m_Direct3D->Initialize(screenWidth, screenHeight, VSYNC_ENABLED, hwnd, FULL_SCREEN, SCREEN_DEPTH, SCREEN_NEAR); - if (!result) - { - MessageBox(hwnd, L"Could not initialize Direct3D.", L"Error", MB_OK); - return false; - } - - // Create the camera object. - m_Camera = new CameraClass; - if (!m_Camera) - { - return false; - } - - // Set the initial position of the camera. - m_Camera->SetPosition(0.0f, 0.0f, -12.0f); - m_Camera->SetRotation(0.0f, 0.0f, 0.0f); - m_Camera->Render(); - m_Camera->GetViewMatrix(m_baseViewMatrix); - - // Create and initialize the font shader object. - m_FontShader = new FontShaderClass; - - result = m_FontShader->Initialize(m_Direct3D->GetDevice(), hwnd); - if (!result) - { - MessageBox(hwnd, L"Could not initialize the font shader object.", L"Error", MB_OK); - return false; - } - - // Create and initialize the font object. - m_Font = new FontClass; - - result = m_Font->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), 0); - if (!result) - { - return false; - } - - // Create and initialize the texture shader object. - m_TextureShader = new TextureShaderClass; - - result = m_TextureShader->Initialize(m_Direct3D->GetDevice(), hwnd); - if (!result) - { - MessageBox(hwnd, L"Could not initialize the texture shader object.", L"Error", MB_OK); - return false; - } - - - // Create and initialize the render to texture object. - m_RenderTexture = new RenderTextureClass; - - result = m_RenderTexture->Initialize(m_Direct3D->GetDevice(), 256, 256, SCREEN_DEPTH, SCREEN_NEAR, 1); - if (!result) - { - return false; - } - - // Create and initialize the display plane object. - m_DisplayPlane = new DisplayPlaneClass; - - result = m_DisplayPlane->Initialize(m_Direct3D->GetDevice(), 1.0f, 1.0f); - if (!result) - { - return false; - } - - - // Set the sprite info file we will be using. - strcpy_s(spriteFilename, "sprite_data_01.txt"); - - // Create and initialize the sprite object. - m_Sprite = new SpriteClass; - - result = m_Sprite->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), screenWidth, screenHeight, spriteFilename, 50, 50); - if (!result) - { - return false; - } - - // Set the initial mouse strings. - strcpy_s(mouseString1, "Mouse X: 0"); - strcpy_s(mouseString2, "Mouse Y: 0"); - strcpy_s(mouseString3, "Mouse Button: No"); - - // Create and initialize the text objects for the mouse strings. - m_MouseStrings = new TextClass[3]; - - result = m_MouseStrings[0].Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), screenWidth, screenHeight, 32, m_Font, mouseString1, 10, 10, 1.0f, 1.0f, 1.0f); - if (!result) - { - return false; - } - - result = m_MouseStrings[1].Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), screenWidth, screenHeight, 32, m_Font, mouseString1, 10, 35, 1.0f, 1.0f, 1.0f); - if (!result) - { - return false; - } - - result = m_MouseStrings[2].Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), screenWidth, screenHeight, 32, m_Font, mouseString1, 10, 60, 1.0f, 1.0f, 1.0f); - if (!result) - { - return false; - } - - // Set the file name of the bitmap file. - strcpy_s(bitmapFilename, "stone01.tga"); - - // Create and initialize the bitmap object. - m_Bitmap = new BitmapClass; - - result = m_Bitmap->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), screenWidth, screenHeight, bitmapFilename, 50, 50); - if (!result) - { - return false; - } - - // Set the file name of the model. - strcpy_s(modelFilename, "cube.txt"); - - // Set the file name of the textures. - strcpy_s(textureFilename1, "stone01.tga"); - strcpy_s(textureFilename2, "normal01.tga"); - strcpy_s(textureFilename3, "spec02.tga"); - strcpy_s(textureFilename4, "alpha01.tga"); - strcpy_s(textureFilename5, "light01.tga"); - strcpy_s(textureFilename6, "moss01.tga"); - - // Create and initialize the model object. - m_Model = new ModelClass; - - result = m_Model->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textureFilename1, textureFilename2, textureFilename3, textureFilename4, - textureFilename5, textureFilename6); - if (!result) - { - MessageBox(hwnd, L"Could not initialize the model object.", L"Error", MB_OK); - return false; - } - - // Create and initialize the light shader object. - m_LightShader = new LightShaderClass; - - result = m_LightShader->Initialize(m_Direct3D->GetDevice(), hwnd); - if (!result) - { - MessageBox(hwnd, L"Could not initialize the light shader object.", L"Error", MB_OK); - return false; - } - - // Create and initialize the light object. - m_Light = new LightClass; - - m_Light->SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f); - m_Light->SetDirection(0.0f, 0.0f, -1.0f); - m_Light->SetSpecularColor(1.0f, 1.0f, 1.0f, 1.0f); - m_Light->SetSpecularPower(16.0f); - - // Set the number of lights we will use. - m_numLights = 4; - - // Create and initialize the light objects array. - m_Lights.resize(m_numLights); - - m_Lights[0] = new LightClass; - m_Lights[0]->SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f); // White - m_Lights[0]->SetDirection(0.0f, 0.0f, -1.0f); - m_Lights[0]->SetSpecularColor(1.0f, 1.0f, 1.0f, 1.0f); - m_Lights[0]->SetSpecularPower(16.0f); - m_Lights[0]->SetPosition(10.0f, 7.0f, -5.0f); - - // Manually set the color and position of each light. - m_Lights[1] = new LightClass; - m_Lights[1]->SetDiffuseColor(1.0f, 0.0f, 0.0f, 1.0f); // Red - m_Lights[1]->SetDirection(0.0f, 0.0f, 1.0f); - m_Lights[1]->SetSpecularColor(1.0f, 0.0f, 0.0f, 1.0f); - m_Lights[1]->SetSpecularPower(16.0f); - m_Lights[1]->SetPosition(10.0f, 7.0f, -5.0f); - - m_Lights[2] = new LightClass; - m_Lights[2]->SetDiffuseColor(0.0f, 1.0f, 0.0f, 1.0f); // Green - m_Lights[2]->SetDirection(0.0f, 0.0f, 1.0f); - m_Lights[2]->SetSpecularColor(0.0f, 1.0f, 0.0f, 1.0f); - m_Lights[2]->SetSpecularPower(16.0f); - m_Lights[2]->SetPosition(10.0f, 7.0f, -5.0f); - - m_Lights[3] = new LightClass; - m_Lights[3]->SetDiffuseColor(0.0f, 0.0f, 1.0f, 1.0f); // Blue - m_Lights[3]->SetDirection(0.0f, 0.0f, 1.0f); - m_Lights[3]->SetSpecularColor(0.0f, 0.0f, 1.0f, 1.0f); - m_Lights[3]->SetSpecularPower(16.0f); - m_Lights[3]->SetPosition(10.0f, 7.0f, -5.0f); - - - // Create and initialize the normal map shader object. - m_ShaderManager = new ShaderManagerClass; - - result = m_ShaderManager->Initialize(m_Direct3D->GetDevice(), hwnd); - if (!result) - { - return false; - } - - - - // Create and initialize the font shader object. - m_FontShader = new FontShaderClass; - - result = m_FontShader->Initialize(m_Direct3D->GetDevice(), hwnd); - if (!result) - { - MessageBox(hwnd, L"Could not initialize the font shader object.", L"Error", MB_OK); - return false; - } - - // Create and initialize the font object. - m_Font = new FontClass; - - result = m_Font->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), 0); - if (!result) - { - return false; - } - - // Set the initial render count string. - strcpy_s(renderString, "Render Count: 0"); - - // Create and initialize the text object for the render count string. - m_RenderCountString = new TextClass; - - result = m_RenderCountString->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), screenWidth, screenHeight, 32, m_Font, renderString, 10, 10, 1.0f, 1.0f, 1.0f); - if (!result) - { - return false; - } - - // Create and initialize the model list object. - m_ModelList = new ModelListClass; - m_ModelList->Initialize(25); - - // Create and initialize the timer object. - m_Timer = new TimerClass; - - result = m_Timer->Initialize(); - if (!result) - { - return false; - } - - // Create the position class object. - m_Position = new PositionClass; - - // Create the frustum class object. - m_Frustum = new FrustumClass; - - // Create and initialize the fps object. - m_Fps = new FpsClass(); - - m_Fps->Initialize(); - - // Set the initial fps and fps string. - m_previousFps = -1; - strcpy_s(fpsString, "Fps: 0"); - - // Create and initialize the text object for the fps string. - m_FpsString = new TextClass; - - result = m_FpsString->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), screenWidth, screenHeight, 32, m_Font, fpsString, 10, 10, 0.0f, 1.0f, 0.0f); - if (!result) - { - return false; - } + logger.Log("Application class initialized", __FILE__, __LINE__); return true; } @@ -551,6 +547,7 @@ bool ApplicationClass::Frame(InputClass* Input) result = Render(rotation, x, y, z, textureTranslation); if (!result) { + logger.Log("Could not render the graphics scene", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -558,6 +555,7 @@ bool ApplicationClass::Frame(InputClass* Input) result = UpdateFps(); if (!result) { + logger.Log("Could not update the frames per second", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -580,6 +578,7 @@ bool ApplicationClass::Frame(InputClass* Input) result = RenderSceneToTexture(rotation); if (!result) { + logger.Log("Could not render the scene to the render texture", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -587,6 +586,7 @@ bool ApplicationClass::Frame(InputClass* Input) result = UpdateMouseStrings(mouseX, mouseY, leftMouseDown); if (!result) { + logger.Log("Could not update the mouse strings", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -723,6 +723,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t diffuseColor, lightPosition); if (!result) { + logger.Log("Could not render the cube model using the light shader", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } } @@ -747,6 +748,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t if (!result) { + logger.Log("Could not render the object model using the light shader", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } } @@ -764,10 +766,11 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t chunk->Render(m_Direct3D->GetDeviceContext()); - result = m_LightShader->Render(m_Direct3D->GetDeviceContext(), chunk->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, chunk->GetTexture(1), + result = m_LightShader->Render(m_Direct3D->GetDeviceContext(), chunk->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, chunk->GetTexture(5), diffuseColor, lightPosition); if (!result) { + logger.Log("Could not render the terrain model using the light shader", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } } @@ -781,6 +784,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t result = m_TextureShader->Render(m_Direct3D->GetDeviceContext(), m_DisplayPlane->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_RenderTexture->GetShaderResourceView()); if (!result) { + logger.Log("Could not render the display plane using the texture shader", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -793,6 +797,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t result = m_TextureShader->Render(m_Direct3D->GetDeviceContext(), m_DisplayPlane->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_RenderTexture->GetShaderResourceView()); if (!result) { + logger.Log("Could not render the display plane using the texture shader", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -805,6 +810,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t result = m_TextureShader->Render(m_Direct3D->GetDeviceContext(), m_DisplayPlane->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_RenderTexture->GetShaderResourceView()); if (!result) { + logger.Log("Could not render the display plane using the texture shader", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -842,6 +848,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t m_Model->GetTexture(0), diffuseColor, lightPosition); if (!result) { + logger.Log("Could not render the model using the light shader", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -854,6 +861,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t result = UpdateRenderCountString(renderCount); if (!result) { + logger.Log("Could not update the render count string", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -871,6 +879,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t m_Font->GetTexture(), m_RenderCountString->GetPixelColor()); if (!result) { + logger.Log("Could not render the render count text string using the font shader", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -881,6 +890,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t m_Font->GetTexture(), m_FpsString->GetPixelColor()); if (!result) { + logger.Log("Could not render the fps text string using the font shader", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -893,6 +903,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t m_Font->GetTexture(), m_MouseStrings[i].GetPixelColor()); if (!result) { + logger.Log("Could not render the mouse text strings using the font shader", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } } @@ -908,6 +919,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t result = m_TextureShader->Render(m_Direct3D->GetDeviceContext(), m_Sprite->GetIndexCount(), worldMatrix, viewMatrix, orthoMatrix, m_Sprite->GetTexture()); if (!result) { + logger.Log("Could not render the sprite using the texture shader", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -961,6 +973,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t m_Model->GetTexture(0), m_Model->GetTexture(5), m_Model->GetTexture(3)); if (!result) { + logger.Log("Could not render the model using the alpha map shader", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -976,6 +989,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t m_Model->GetTexture(0)); if (!result) { + logger.Log("Could not render the model using the texture shader", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -991,6 +1005,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t m_Model->GetTexture(0), m_Model->GetTexture(1), m_Lights[0]->GetDirection(), m_Lights[0]->GetDiffuseColor()); if (!result) { + logger.Log("Could not render the model using the normal map shader", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -1007,6 +1022,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t m_Model->GetTexture(0), m_Model->GetTexture(5)); if (!result) { + logger.Log("Could not render the model using the multitexture shader", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -1023,6 +1039,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t m_Model->GetTexture(0), textureTranslation); if (!result) { + logger.Log("Could not render the model using the translate shader", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -1039,6 +1056,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t m_Camera->GetPosition(), m_Lights[0]->GetSpecularColor(), m_Lights[0]->GetSpecularPower()); if (!result) { + logger.Log("Could not render the model using the specular map shader", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -1053,6 +1071,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t result = m_ShaderManager->RenderTransparentShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(0), blendAmount); if (!result) { + logger.Log("Could not render the model using the transparent shader", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -1104,6 +1123,9 @@ int ApplicationClass::GetScreenHeight() const void ApplicationClass::GenerateTerrain() { + + logger.Log("Generating terrain", __FILE__, __LINE__); + char modelFilename[128]; char textureFilename1[128]; char textureFilename2[128]; @@ -1151,6 +1173,9 @@ void ApplicationClass::GenerateTerrain() void ApplicationClass::AddKobject(WCHAR* filepath) { + + logger.Log("Adding object", __FILE__, __LINE__); + char modelFilename[128]; char textureFilename1[128]; char textureFilename2[128]; @@ -1185,6 +1210,9 @@ void ApplicationClass::AddKobject(WCHAR* filepath) void ApplicationClass::AddCube() { + + logger.Log("Adding cube", __FILE__, __LINE__); + char modelFilename[128]; char textureFilename1[128]; char textureFilename2[128]; @@ -1215,6 +1243,8 @@ void ApplicationClass::AddCube() void ApplicationClass::DeleteKobject(int index) { + logger.Log("Deleting object", __FILE__, __LINE__); + if (index < m_object.size()) { m_object[index]->Shutdown(); @@ -1225,6 +1255,8 @@ void ApplicationClass::DeleteKobject(int index) void ApplicationClass::DeleteTerrain() { + logger.Log("Deleting terrain", __FILE__, __LINE__); + for (auto cube : m_terrainChunk) { cube->Shutdown(); @@ -1250,6 +1282,7 @@ bool ApplicationClass::UpdateMouseStrings(int mouseX, int mouseY, bool mouseDown result = m_MouseStrings[0].UpdateText(m_Direct3D->GetDeviceContext(), m_Font, finalString, 10, 50, 1.0f, 1.0f, 1.0f); if (!result) { + logger.Log("Could not update the mouse X string", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -1264,6 +1297,7 @@ bool ApplicationClass::UpdateMouseStrings(int mouseX, int mouseY, bool mouseDown result = m_MouseStrings[1].UpdateText(m_Direct3D->GetDeviceContext(), m_Font, finalString, 10, 75, 1.0f, 1.0f, 1.0f); if (!result) { + logger.Log("Could not update the mouse Y string", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -1282,6 +1316,7 @@ bool ApplicationClass::UpdateMouseStrings(int mouseX, int mouseY, bool mouseDown if (!result) { + logger.Log("Could not update the mouse button string", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -1352,6 +1387,7 @@ bool ApplicationClass::UpdateFps() result = m_FpsString->UpdateText(m_Direct3D->GetDeviceContext(), m_Font, finalString, 10, 10, red, green, blue); if (!result) { + logger.Log("Could not update the fps string", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -1375,6 +1411,7 @@ bool ApplicationClass::UpdateRenderCountString(int renderCount) result = m_RenderCountString->UpdateText(m_Direct3D->GetDeviceContext(), m_Font, finalString, 10, 30, 1.0f, 1.0f, 1.0f); if (!result) { + logger.Log("Could not update the render count string", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -1419,6 +1456,8 @@ void ApplicationClass::SetLightPosition(int index, XMVECTOR position) void ApplicationClass::DeleteLight(int index) { + logger.Log("Deleting light", __FILE__, __LINE__); + if (index < 0 || index >= m_Lights.size()) { // Index out of bounds diff --git a/enginecustom/applicationclass.h b/enginecustom/applicationclass.h index 3aaad14..3493076 100644 --- a/enginecustom/applicationclass.h +++ b/enginecustom/applicationclass.h @@ -5,6 +5,8 @@ /////////////////////// // MY CLASS INCLUDES // /////////////////////// +#include "Logger.h" + #include "d3dclass.h" #include "cameraclass.h" #include "object.h" @@ -160,6 +162,12 @@ private : FpsClass* m_Fps; TextClass* m_FpsString; int m_previousFps; + + // ------------------------------------------------- // + // ------------------- LOGGER ---------------------- // + // ------------------------------------------------- // + + Logger logger; }; #endif \ No newline at end of file diff --git a/enginecustom/enginecustom.vcxproj b/enginecustom/enginecustom.vcxproj index 40cd905..7eb8b74 100644 --- a/enginecustom/enginecustom.vcxproj +++ b/enginecustom/enginecustom.vcxproj @@ -87,6 +87,7 @@ + @@ -108,79 +109,120 @@ - - - - - - - - - - - - + + Document + + + Document + + + Document + + + Document + + + Document + + + Document + + + Document + + + Document + + + Document + + + Document + + + Document + + + Document + - - - + Document - - + + Document - - - - - + + + Document + + + Document + + + Document + + + Document + + + Document + + + Document + - + Pixel Pixel Pixel Pixel Document - - + + Vertex Vertex Vertex Vertex Document - + - - + + - + - - - + + + - - + + + + + + - - - - + + + + + - + Designer Document - - + + Designer Document - + diff --git a/enginecustom/enginecustom.vcxproj.filters b/enginecustom/enginecustom.vcxproj.filters index 1d7464f..46ace05 100644 --- a/enginecustom/enginecustom.vcxproj.filters +++ b/enginecustom/enginecustom.vcxproj.filters @@ -290,11 +290,17 @@ Fichiers d%27en-tête + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + - - fonts - assets @@ -304,9 +310,6 @@ assets - - assets - assets @@ -325,24 +328,15 @@ Assets + + + shader - - shader - - - Fonts - - - Fonts - - - shader - shader @@ -386,23 +380,13 @@ + + - - Fonts - - - Assets - - - Assets - Assets - - Assets - assets @@ -412,4 +396,39 @@ Fichiers de ressources + + + Fonts + + + Fonts + + + shader + + + shader + + + Fonts + + + fonts + + + + + assets + + + Assets + + + + Assets + + + Assets + + \ No newline at end of file diff --git a/enginecustom/imgui.ini b/enginecustom/imgui.ini index 71a8db3..19fa4df 100644 --- a/enginecustom/imgui.ini +++ b/enginecustom/imgui.ini @@ -3,19 +3,18 @@ Pos=60,60 Size=400,400 [Window][Khaotic Engine] -Pos=24,182 -Size=694,210 +Pos=429,57 +Size=392,218 [Window][Objects] -Pos=35,13 -Size=492,353 -Collapsed=1 +Pos=39,222 +Size=379,299 [Window][Terrain] -Pos=816,75 -Size=418,94 +Pos=60,60 +Size=342,82 [Window][Light] -Pos=58,418 -Size=418,240 +Pos=95,296 +Size=345,230 diff --git a/enginecustom/imguiManager.cpp b/enginecustom/imguiManager.cpp index 4e795f7..276b6ea 100644 --- a/enginecustom/imguiManager.cpp +++ b/enginecustom/imguiManager.cpp @@ -13,6 +13,8 @@ imguiManager::~imguiManager() bool imguiManager::Initialize(HWND hwnd, ID3D11Device* device, ID3D11DeviceContext* deviceContext) { + logger.Log("Initializing imgui", __FILE__, __LINE__); + IMGUI_CHECKVERSION(); ImGui::CreateContext(); io = &ImGui::GetIO(); @@ -21,6 +23,8 @@ bool imguiManager::Initialize(HWND hwnd, ID3D11Device* device, ID3D11DeviceConte ImGui_ImplDX11_Init(device, deviceContext); ImGui::StyleColorsDark(); + logger.Log("imgui initialized", __FILE__, __LINE__); + return true; } diff --git a/enginecustom/imguiManager.h b/enginecustom/imguiManager.h index b1d5dfc..6d59fe0 100644 --- a/enginecustom/imguiManager.h +++ b/enginecustom/imguiManager.h @@ -2,6 +2,8 @@ #ifndef _IMGUI_MANAGER_H_ #define _IMGUI_MANAGER_H_ +#include "Logger.h" + #include #include #include @@ -39,6 +41,8 @@ private : private: ImGuiIO* io; + + Logger logger; }; #endif \ No newline at end of file diff --git a/enginecustom/modelclass.cpp b/enginecustom/modelclass.cpp index c47f3b1..a93de61 100644 --- a/enginecustom/modelclass.cpp +++ b/enginecustom/modelclass.cpp @@ -22,12 +22,15 @@ ModelClass::~ModelClass() bool ModelClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceContext, char* modelFilename, char* textureFilename1, char* textureFilename2, char* textureFilename3, char* textureFilename4, char* textureFilename5, char* textureFilename6) { + logger.Log("Initializing model class", __FILE__, __LINE__); + bool result; // Load in the model data. result = LoadModel(modelFilename); if (!result) { + logger.Log("Failed to load model data", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -38,15 +41,19 @@ bool ModelClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceCon result = InitializeBuffers(device); if (!result) { + logger.Log("Failed to initialize buffers", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } // Load the textures for this model. result = LoadTextures(device, deviceContext, textureFilename1, textureFilename2, textureFilename3, textureFilename4, textureFilename5, textureFilename6); if (!result) { + logger.Log("Failed to load textures", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } + logger.Log("Model class initialized", __FILE__, __LINE__); + return true; } @@ -88,6 +95,8 @@ ID3D11ShaderResourceView* ModelClass::GetTexture(int index) bool ModelClass::InitializeBuffers(ID3D11Device* device) { + logger.Log("Initializing buffers", __FILE__, __LINE__); + VertexType* vertices; unsigned long* indices; D3D11_BUFFER_DESC vertexBufferDesc, indexBufferDesc; @@ -130,6 +139,7 @@ bool ModelClass::InitializeBuffers(ID3D11Device* device) result = device->CreateBuffer(&vertexBufferDesc, &vertexData, &m_vertexBuffer); if (FAILED(result)) { + logger.Log("Failed to create vertex buffer", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -150,6 +160,7 @@ bool ModelClass::InitializeBuffers(ID3D11Device* device) result = device->CreateBuffer(&indexBufferDesc, &indexData, &m_indexBuffer); if (FAILED(result)) { + logger.Log("Failed to create index buffer", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -160,6 +171,8 @@ bool ModelClass::InitializeBuffers(ID3D11Device* device) delete[] indices; indices = 0; + logger.Log("Buffers initialized", __FILE__, __LINE__); + return true; } @@ -210,6 +223,8 @@ void ModelClass::RenderBuffers(ID3D11DeviceContext* deviceContext) bool ModelClass::LoadTextures(ID3D11Device* device, ID3D11DeviceContext* deviceContext, char* filename1, char* filename2, char* filename3, char* filename4, char* filename5, char* filename6) { + logger.Log("Loading textures", __FILE__, __LINE__); + bool result; @@ -219,45 +234,54 @@ bool ModelClass::LoadTextures(ID3D11Device* device, ID3D11DeviceContext* deviceC result = m_Textures[0].Initialize(device, deviceContext, filename1); if (!result) { + logger.Log("Failed to initialize texture", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } result = m_Textures[1].Initialize(device, deviceContext, filename2); if (!result) { + logger.Log("Failed to initialize texture", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } result = m_Textures[2].Initialize(device, deviceContext, filename3); if (!result) { + logger.Log("Failed to initialize texture", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } result = m_Textures[3].Initialize(device, deviceContext, filename4); if (!result) { + logger.Log("Failed to initialize texture", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } result = m_Textures[4].Initialize(device, deviceContext, filename5); if (!result) { + logger.Log("Failed to initialize texture", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } result = m_Textures[5].Initialize(device, deviceContext, filename6); if (!result) { + logger.Log("Failed to initialize texture", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } + logger.Log("Textures loaded", __FILE__, __LINE__); return true; } void ModelClass::ReleaseTextures() { + logger.Log("Releasing textures", __FILE__, __LINE__); + // Release the texture object array. if (m_Textures) { @@ -272,11 +296,15 @@ void ModelClass::ReleaseTextures() m_Textures = 0; } + logger.Log("Textures released", __FILE__, __LINE__); + return; } bool ModelClass::LoadModel(char* filename) { + logger.Log("Loading model", __FILE__, __LINE__); + ifstream fin; char input; int i; @@ -288,6 +316,7 @@ bool ModelClass::LoadModel(char* filename) // If it could not open the file then exit. if (fin.fail()) { + logger.Log("Failed to open model file", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -327,11 +356,15 @@ bool ModelClass::LoadModel(char* filename) // Close the model file. fin.close(); + logger.Log("Model loaded", __FILE__, __LINE__); + return true; } void ModelClass::CalculateModelVectors() { + logger.Log("Calculating model vectors", __FILE__, __LINE__); + int faceCount, i, index; TempVertexType vertex1, vertex2, vertex3; VectorType tangent, binormal; @@ -394,11 +427,15 @@ void ModelClass::CalculateModelVectors() m_model[index - 3].bz = binormal.z; } + logger.Log("Model vectors calculated", __FILE__, __LINE__); + return; } void ModelClass::CalculateTangentBinormal(TempVertexType vertex1, TempVertexType vertex2, TempVertexType vertex3, VectorType& tangent, VectorType& binormal) { + logger.Log("Calculating tangent and binormal", __FILE__, __LINE__); + float vector1[3], vector2[3]; float tuVector[2], tvVector[2]; float den; @@ -449,16 +486,22 @@ void ModelClass::CalculateTangentBinormal(TempVertexType vertex1, TempVertexType binormal.y = binormal.y / length; binormal.z = binormal.z / length; + logger.Log("Tangent and binormal calculated", __FILE__, __LINE__); + return; } void ModelClass::ReleaseModel() { + logger.Log("Releasing model", __FILE__, __LINE__); + if (m_model) { delete[] m_model; m_model = 0; } + logger.Log("Model released", __FILE__, __LINE__); + return; } \ No newline at end of file diff --git a/enginecustom/modelclass.h b/enginecustom/modelclass.h index 3db14c8..409bc3d 100644 --- a/enginecustom/modelclass.h +++ b/enginecustom/modelclass.h @@ -5,6 +5,8 @@ ////////////// // INCLUDES // ////////////// +#include "Logger.h" + #include #include #include @@ -105,6 +107,8 @@ private: int m_vertexCount, m_indexCount; TextureClass* m_Textures; ModelType* m_model; + + Logger logger; }; #endif \ No newline at end of file diff --git a/enginecustom/object.h b/enginecustom/object.h index c7045f3..ded09c0 100644 --- a/enginecustom/object.h +++ b/enginecustom/object.h @@ -49,4 +49,5 @@ private: XMMATRIX m_worldMatrix; std::string m_name; + }; diff --git a/enginecustom/systemclass.h b/enginecustom/systemclass.h index 41f9b38..8b62c64 100644 --- a/enginecustom/systemclass.h +++ b/enginecustom/systemclass.h @@ -3,6 +3,8 @@ #define WIN32_LEAN_AND_MEAN +#include "Logger.h" + #include "inputclass.h" #include "applicationclass.h" #include "imguiManager.h" @@ -30,6 +32,7 @@ private: LPCWSTR m_applicationName; HINSTANCE m_hinstance; HWND m_hwnd; + Logger logger; InputClass* m_Input; ApplicationClass* m_Application;