diff --git a/CMakeLists.txt b/CMakeLists.txt index e8ba705..7fa03dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -111,6 +111,15 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug") target_link_options(${PROJECT_NAME} PRIVATE -fsanitize=address ) + + target_compile_definitions(${PROJECT_NAME} PRIVATE DEBUG_MODE) + target_compile_definitions(${PROJECT_NAME} PRIVATE + ASSETS_PATH="${CMAKE_SOURCE_DIR}/assets/" + ) +else() + target_compile_definitions(${PROJECT_NAME} PRIVATE + ASSETS_PATH="./assets/" + ) endif() target_include_directories(${PROJECT_NAME} PUBLIC ${INCLUDE_DIR}) diff --git a/include/Cubed/tools/cubed_assert.hpp b/include/Cubed/tools/cubed_assert.hpp index c3185db..e2ad948 100644 --- a/include/Cubed/tools/cubed_assert.hpp +++ b/include/Cubed/tools/cubed_assert.hpp @@ -16,10 +16,7 @@ namespace Assert { } } -#ifdef NDEBUG -#define CUBED_ASSERT(cond) ((void)0) -#define CUBED_ASSERT_MSG(cond, message) ((void)0) -#else +#ifdef DEBUG_MODE #define CUBED_ASSERT(cond) \ do { \ if (!(cond)) { \ @@ -32,4 +29,8 @@ namespace Assert { ::Assert::msg(#cond, __FILE__, __LINE__, __func__, message); \ } \ } while (0) + +#else +#define CUBED_ASSERT(cond) ((void)0) +#define CUBED_ASSERT_MSG(cond, message) ((void)0) #endif \ No newline at end of file diff --git a/src/renderer.cpp b/src/renderer.cpp index 1d0f863..ddc4013 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -63,7 +63,7 @@ void Renderer::init() { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - #ifndef NDEBUG + #ifdef DEBUG_MODE glEnable(GL_DEBUG_OUTPUT); glDebugMessageCallback([](GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* user_param) { Logger::log(Logger::Level::DEBUG, std::source_location::current(),"GL Debug: {}", reinterpret_cast(message)); diff --git a/src/texture_manager.cpp b/src/texture_manager.cpp index cb09ba8..e12c3b7 100644 --- a/src/texture_manager.cpp +++ b/src/texture_manager.cpp @@ -32,7 +32,7 @@ GLuint TextureManager::get_ui_array() const{ void TextureManager::load_block_status(unsigned id) { CUBED_ASSERT_MSG(id < MAX_BLOCK_STATUS, "Exceed the max status sum limit"); - std::string path = "assets/texture/status/" + std::to_string(id) + ".png"; + std::string path = "texture/status/" + std::to_string(id) + ".png"; unsigned char* image_data = nullptr; image_data = (Tools::load_image_data(path)); glBindTexture(GL_TEXTURE_2D_ARRAY, m_block_status_array); @@ -54,7 +54,7 @@ void TextureManager::load_block_texture(unsigned id) { } unsigned char* image_data[6]; - std::string block_texture_path = "assets/texture/block/" + name; + std::string block_texture_path = "texture/block/" + name; image_data[0] = (Tools::load_image_data(block_texture_path + "/front.png")); image_data[1] = (Tools::load_image_data(block_texture_path + "/right.png")); image_data[2] = (Tools::load_image_data(block_texture_path + "/back.png")); @@ -80,7 +80,7 @@ void TextureManager::load_block_texture(unsigned id) { void TextureManager::load_ui_texture(unsigned id) { CUBED_ASSERT_MSG(id < MAX_UI_NUM, "Exceed the max ui sum limit"); - std::string path = "assets/texture/ui/" + std::to_string(id) + ".png"; + std::string path = "texture/ui/" + std::to_string(id) + ".png"; unsigned char* image_data = nullptr; image_data = (Tools::load_image_data(path)); glBindTexture(GL_TEXTURE_2D_ARRAY, m_ui_array); diff --git a/src/tools/shader_tools.cpp b/src/tools/shader_tools.cpp index 5f7f4de..2992be9 100644 --- a/src/tools/shader_tools.cpp +++ b/src/tools/shader_tools.cpp @@ -1,10 +1,12 @@ #include +#include #include #include #include #include +namespace fs = std::filesystem; namespace Tools { @@ -119,11 +121,12 @@ namespace Tools { } unsigned char* load_image_data(const std::string& tex_image_path) { + fs::path path = ASSETS_PATH + tex_image_path; + CUBED_ASSERT_MSG(fs::is_regular_file(path), path.c_str()); unsigned char* data = nullptr; int width, height, channels; - data = SOIL_load_image(tex_image_path.c_str(), &width, &height, &channels, SOIL_LOAD_AUTO); - std::string error_info = "Could not load texture " + tex_image_path; - CUBED_ASSERT_MSG(data, error_info.c_str()); + data = SOIL_load_image(path.c_str(), &width, &height, &channels, SOIL_LOAD_AUTO); + CUBED_ASSERT_MSG(data, "Could not load texture" + path.string()); return data; }