mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-06-17 16:17:02 +08:00
feat: add DEBUG_MODE and ASSETS_PATH macro
This commit is contained in:
@@ -111,6 +111,15 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|||||||
target_link_options(${PROJECT_NAME} PRIVATE
|
target_link_options(${PROJECT_NAME} PRIVATE
|
||||||
-fsanitize=address
|
-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()
|
endif()
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME} PUBLIC ${INCLUDE_DIR})
|
target_include_directories(${PROJECT_NAME} PUBLIC ${INCLUDE_DIR})
|
||||||
|
|||||||
@@ -16,10 +16,7 @@ namespace Assert {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef NDEBUG
|
#ifdef DEBUG_MODE
|
||||||
#define CUBED_ASSERT(cond) ((void)0)
|
|
||||||
#define CUBED_ASSERT_MSG(cond, message) ((void)0)
|
|
||||||
#else
|
|
||||||
#define CUBED_ASSERT(cond) \
|
#define CUBED_ASSERT(cond) \
|
||||||
do { \
|
do { \
|
||||||
if (!(cond)) { \
|
if (!(cond)) { \
|
||||||
@@ -32,4 +29,8 @@ namespace Assert {
|
|||||||
::Assert::msg(#cond, __FILE__, __LINE__, __func__, message); \
|
::Assert::msg(#cond, __FILE__, __LINE__, __func__, message); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#else
|
||||||
|
#define CUBED_ASSERT(cond) ((void)0)
|
||||||
|
#define CUBED_ASSERT_MSG(cond, message) ((void)0)
|
||||||
#endif
|
#endif
|
||||||
@@ -63,7 +63,7 @@ void Renderer::init() {
|
|||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifdef DEBUG_MODE
|
||||||
glEnable(GL_DEBUG_OUTPUT);
|
glEnable(GL_DEBUG_OUTPUT);
|
||||||
glDebugMessageCallback([](GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* user_param) {
|
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<const char*>(message));
|
Logger::log(Logger::Level::DEBUG, std::source_location::current(),"GL Debug: {}", reinterpret_cast<const char*>(message));
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ GLuint TextureManager::get_ui_array() const{
|
|||||||
void TextureManager::load_block_status(unsigned id) {
|
void TextureManager::load_block_status(unsigned id) {
|
||||||
|
|
||||||
CUBED_ASSERT_MSG(id < MAX_BLOCK_STATUS, "Exceed the max status sum limit");
|
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;
|
unsigned char* image_data = nullptr;
|
||||||
image_data = (Tools::load_image_data(path));
|
image_data = (Tools::load_image_data(path));
|
||||||
glBindTexture(GL_TEXTURE_2D_ARRAY, m_block_status_array);
|
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];
|
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[0] = (Tools::load_image_data(block_texture_path + "/front.png"));
|
||||||
image_data[1] = (Tools::load_image_data(block_texture_path + "/right.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"));
|
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) {
|
void TextureManager::load_ui_texture(unsigned id) {
|
||||||
CUBED_ASSERT_MSG(id < MAX_UI_NUM, "Exceed the max ui sum limit");
|
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;
|
unsigned char* image_data = nullptr;
|
||||||
image_data = (Tools::load_image_data(path));
|
image_data = (Tools::load_image_data(path));
|
||||||
glBindTexture(GL_TEXTURE_2D_ARRAY, m_ui_array);
|
glBindTexture(GL_TEXTURE_2D_ARRAY, m_ui_array);
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
#include <Cubed/config.hpp>
|
#include <Cubed/config.hpp>
|
||||||
#include <Cubed/tools/cubed_assert.hpp>
|
#include <Cubed/tools/cubed_assert.hpp>
|
||||||
#include <Cubed/tools/shader_tools.hpp>
|
#include <Cubed/tools/shader_tools.hpp>
|
||||||
#include <Cubed/tools/log.hpp>
|
#include <Cubed/tools/log.hpp>
|
||||||
|
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
namespace Tools {
|
namespace Tools {
|
||||||
|
|
||||||
@@ -119,11 +121,12 @@ namespace Tools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned char* load_image_data(const std::string& tex_image_path) {
|
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;
|
unsigned char* data = nullptr;
|
||||||
int width, height, channels;
|
int width, height, channels;
|
||||||
data = SOIL_load_image(tex_image_path.c_str(), &width, &height, &channels, SOIL_LOAD_AUTO);
|
data = SOIL_load_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, "Could not load texture" + path.string());
|
||||||
CUBED_ASSERT_MSG(data, error_info.c_str());
|
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user