diff --git a/engine/PilotEditor.ini b/engine/PilotEditor.ini deleted file mode 100644 index 4dfe8b12b..000000000 --- a/engine/PilotEditor.ini +++ /dev/null @@ -1,8 +0,0 @@ -AssetFolder=asset -SchemaFolder=schema -BigIconFile=resource/PilotEditorBigIcon.png -SmallIconFile=resource/PilotEditorSmallIcon.png -FontFile=resource/PilotEditorFont.TTF -DefaultWorld=asset/world/hello.world.json -GlobalRenderingRes=asset/global/rendering.global.json -JoltAssetFolder=jolt-asset \ No newline at end of file diff --git a/engine/PilotEditor.json b/engine/PilotEditor.json new file mode 100644 index 000000000..f26c9239f --- /dev/null +++ b/engine/PilotEditor.json @@ -0,0 +1,11 @@ +{ + "asset_folder": "asset", + "schema_folder": "schema", + "big_icon": "resource/PilotEditorBigIcon.png", + "small_icon": "resource/PilotEditorSmallIcon.png", + "font_file": "resource/PilotEditorFont.TTF", + "default_world_url": "asset/world/hello.world.json", + "global_rendering_res": "asset/global/rendering.global.json", + "jolt_asset_folder": "jolt-asset", + "log_pattern": "[%^%l%$] %!@%s+%# %v" +} \ No newline at end of file diff --git a/engine/source/editor/CMakeLists.txt b/engine/source/editor/CMakeLists.txt index ffdf850ec..a05c55c8e 100644 --- a/engine/source/editor/CMakeLists.txt +++ b/engine/source/editor/CMakeLists.txt @@ -25,7 +25,7 @@ target_link_libraries(${TARGET_NAME} PilotRuntime) if(NOT ENABLE_PHYSICS_DEBUG_RENDERER) add_custom_command(TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory "${BINARY_ROOT_DIR}" - COMMAND ${CMAKE_COMMAND} -E copy "${ENGINE_ROOT_DIR}/${TARGET_NAME}.ini" "${BINARY_ROOT_DIR}" + COMMAND ${CMAKE_COMMAND} -E copy "${ENGINE_ROOT_DIR}/${TARGET_NAME}.json" "${BINARY_ROOT_DIR}" COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/resource" "${BINARY_ROOT_DIR}/resource" COMMAND ${CMAKE_COMMAND} -E copy_directory "$/" "${BINARY_ROOT_DIR}" COMMAND ${CMAKE_COMMAND} -E remove_directory "${BINARY_ROOT_DIR}/${ENGINE_ASSET_DIR}" @@ -34,7 +34,7 @@ if(NOT ENABLE_PHYSICS_DEBUG_RENDERER) else() add_custom_command(TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory "${BINARY_ROOT_DIR}" - COMMAND ${CMAKE_COMMAND} -E copy "${ENGINE_ROOT_DIR}/${TARGET_NAME}.ini" "${BINARY_ROOT_DIR}" + COMMAND ${CMAKE_COMMAND} -E copy "${ENGINE_ROOT_DIR}/${TARGET_NAME}.json" "${BINARY_ROOT_DIR}" COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/resource" "${BINARY_ROOT_DIR}/resource" COMMAND ${CMAKE_COMMAND} -E copy_directory "$/" "${BINARY_ROOT_DIR}" COMMAND ${CMAKE_COMMAND} -E remove_directory "${BINARY_ROOT_DIR}/${ENGINE_ASSET_DIR}" diff --git a/engine/source/editor/source/main.cpp b/engine/source/editor/source/main.cpp index 175e5bcb4..5e9b8c1de 100644 --- a/engine/source/editor/source/main.cpp +++ b/engine/source/editor/source/main.cpp @@ -17,7 +17,7 @@ int main(int argc, char** argv) Pilot::EngineInitParams params; params.m_root_folder = pilot_root_folder; - params.m_config_file_path = pilot_root_folder / "PilotEditor.ini"; + params.m_config_file_path = pilot_root_folder / "PilotEditor.json"; Pilot::PilotEngine* engine = new Pilot::PilotEngine(); diff --git a/engine/source/runtime/core/base/macro.h b/engine/source/runtime/core/base/macro.h index c3c6bc5f1..d77962ea5 100644 --- a/engine/source/runtime/core/base/macro.h +++ b/engine/source/runtime/core/base/macro.h @@ -7,8 +7,9 @@ #include #include -#define LOG_HELPER(LOG_LEVEL, ...) \ - g_runtime_global_context.m_logger_system->log(LOG_LEVEL, "[" + std::string(__FUNCTION__) + "] " + __VA_ARGS__); +#define LOG_SRC spdlog::source_loc(Pilot::LogSystem::FileName(__FILE__), __LINE__, __FUNCTION__) + +#define LOG_HELPER(LOG_LEVEL, ...) g_runtime_global_context.m_logger_system->log(LOG_LEVEL, LOG_SRC, __VA_ARGS__); #define LOG_DEBUG(...) LOG_HELPER(LogSystem::LogLevel::debug, __VA_ARGS__); diff --git a/engine/source/runtime/core/log/log_system.cpp b/engine/source/runtime/core/log/log_system.cpp index 00d10e6f0..bb9ad3d4c 100644 --- a/engine/source/runtime/core/log/log_system.cpp +++ b/engine/source/runtime/core/log/log_system.cpp @@ -7,11 +7,11 @@ namespace Pilot { - LogSystem::LogSystem() + LogSystem::LogSystem(const std::string& log_pattern) { auto console_sink = std::make_shared(); console_sink->set_level(spdlog::level::trace); - console_sink->set_pattern("[%^%l%$] %v"); + console_sink->set_pattern(log_pattern); const spdlog::sinks_init_list sink_list = {console_sink}; diff --git a/engine/source/runtime/core/log/log_system.h b/engine/source/runtime/core/log/log_system.h index a2a2ae903..a6d0b290a 100644 --- a/engine/source/runtime/core/log/log_system.h +++ b/engine/source/runtime/core/log/log_system.h @@ -1,8 +1,8 @@ #pragma once -#include - #include +#include +#include #include namespace Pilot @@ -20,29 +20,47 @@ namespace Pilot fatal }; + static constexpr const char* FileName(const char* path) + { + const char* file = path; + while (*path) + { + if (*path++ == std::filesystem::path::preferred_separator) + { + file = path; + } + } + return file; + } + public: - LogSystem(); + LogSystem(const std::string& log_pattern); ~LogSystem(); template - void log(LogLevel level, TARGS&&... args) + void log(LogLevel level, spdlog::source_loc&& loc, TARGS&&... args) { switch (level) { case LogLevel::debug: - m_logger->debug(std::forward(args)...); + m_logger->log( + std::forward(loc), spdlog::level::debug, std::forward(args)...); break; case LogLevel::info: - m_logger->info(std::forward(args)...); + m_logger->log( + std::forward(loc), spdlog::level::info, std::forward(args)...); break; case LogLevel::warn: - m_logger->warn(std::forward(args)...); + m_logger->log( + std::forward(loc), spdlog::level::warn, std::forward(args)...); break; case LogLevel::error: - m_logger->error(std::forward(args)...); + m_logger->log( + std::forward(loc), spdlog::level::err, std::forward(args)...); break; case LogLevel::fatal: - m_logger->critical(std::forward(args)...); + m_logger->log( + std::forward(loc), spdlog::level::critical, std::forward(args)...); fatalCallback(std::forward(args)...); break; default: diff --git a/engine/source/runtime/function/global/global_context.cpp b/engine/source/runtime/function/global/global_context.cpp index 0c97c31fe..8be0724ac 100644 --- a/engine/source/runtime/function/global/global_context.cpp +++ b/engine/source/runtime/function/global/global_context.cpp @@ -12,8 +12,8 @@ #include "runtime/engine.h" #include "runtime/function/framework/world/world_manager.h" #include "runtime/function/input/input_system.h" -#include "runtime/function/physics/physics_system.h" #include "runtime/function/physics/physics_manager.h" +#include "runtime/function/physics/physics_system.h" #include "runtime/function/render/render_system.h" #include "runtime/function/render/window_system.h" @@ -28,7 +28,7 @@ namespace Pilot m_file_system = std::make_shared(); - m_logger_system = std::make_shared(); + m_logger_system = std::make_shared(m_config_manager->getLogPattern()); m_asset_manager = std::make_shared(); @@ -72,7 +72,6 @@ namespace Pilot m_asset_manager.reset(); - m_logger_system.reset(); m_file_system.reset(); diff --git a/engine/source/runtime/resource/config_manager/config_manager.cpp b/engine/source/runtime/resource/config_manager/config_manager.cpp index af1e8f9ad..1f90c64d8 100644 --- a/engine/source/runtime/resource/config_manager/config_manager.cpp +++ b/engine/source/runtime/resource/config_manager/config_manager.cpp @@ -1,61 +1,63 @@ #include "runtime/resource/config_manager/config_manager.h" -#include "runtime/engine.h" - #include +#include #include +#include "_generated/serializer/all_serializer.h" +#include "runtime/core/base/macro.h" +#include "runtime/engine.h" + namespace Pilot { void ConfigManager::initialize(const EngineInitParams& init_param) { m_root_folder = init_param.m_root_folder; // read configs - std::ifstream config_file(init_param.m_config_file_path); - std::string config_line; - while (std::getline(config_file, config_line)) + std::ifstream config_file(init_param.m_config_file_path); + std::stringstream buffer; + buffer << config_file.rdbuf(); + std::string config_file_text(buffer.str()); + + std::string error; + auto config_json = PJson::parse(config_file_text, error); + ASSERT(error.empty()); + + PSerializer::read(config_json, m_config); + + if (!m_config.asset_folder.empty()) + { + m_asset_folder = m_root_folder / m_config.asset_folder; + } + if (!m_config.schema_folder.empty()) + { + m_schema_folder = m_root_folder / m_config.schema_folder; + } + if (!m_config.big_icon.empty()) + { + m_editor_big_icon_path = m_root_folder / m_config.big_icon; + } + if (!m_config.small_icon.empty()) { - size_t seperate_pos = config_line.find_first_of('='); - if (seperate_pos > 0 && seperate_pos < (config_line.length() - 1)) - { - std::string name = config_line.substr(0, seperate_pos); - std::string value = config_line.substr(seperate_pos + 1, config_line.length() - seperate_pos - 1); - if (name == "AssetFolder") - { - m_asset_folder = m_root_folder / value; - } - else if (name == "SchemaFolder") - { - m_schema_folder = m_root_folder / value; - } - else if (name == "DefaultWorld") - { - m_default_world_url = value; - } - else if (name == "BigIconFile") - { - m_editor_big_icon_path = m_root_folder / value; - } - else if (name == "SmallIconFile") - { - m_editor_small_icon_path = m_root_folder / value; - } - else if (name == "FontFile") - { - m_editor_font_path = m_root_folder / value; - } - else if (name == "GlobalRenderingRes") - { - m_global_rendering_res_url = value; - } + m_editor_small_icon_path = m_root_folder / m_config.small_icon; + } + if (!m_config.font_file.empty()) + { + m_editor_font_path = m_root_folder / m_config.font_file; + } + + // set default value + if (m_config.log_pattern.empty()) + { + m_config.log_pattern = "[%^%l%$] %v"; + } + #ifdef ENABLE_PHYSICS_DEBUG_RENDERER - else if (name == "JoltAssetFolder") - { - m_jolt_physics_asset_folder = m_root_folder / value; - } -#endif - } + if (!m_config.jolt_asset_folder.empty()) + { + m_jolt_physics_asset_folder = m_root_folder / jolt_asset_folder; } +#endif } const std::filesystem::path& ConfigManager::getRootFolder() const { return m_root_folder; } @@ -70,12 +72,17 @@ namespace Pilot const std::filesystem::path& ConfigManager::getEditorFontPath() const { return m_editor_font_path; } - const std::string& ConfigManager::getDefaultWorldUrl() const { return m_default_world_url; } + const std::string& ConfigManager::getDefaultWorldUrl() const { return m_config.default_world_url; } - const std::string& ConfigManager::getGlobalRenderingResUrl() const { return m_global_rendering_res_url; } + const std::string& ConfigManager::getGlobalRenderingResUrl() const { return m_config.global_rendering_res; } + + const std::string& ConfigManager::getLogPattern() const { return m_config.log_pattern; } #ifdef ENABLE_PHYSICS_DEBUG_RENDERER - const std::filesystem::path& ConfigManager::getJoltPhysicsAssetFolder() const { return m_jolt_physics_asset_folder; } + const std::filesystem::path& ConfigManager::getJoltPhysicsAssetFolder() const + { + return m_jolt_physics_asset_folder; + } #endif } // namespace Pilot diff --git a/engine/source/runtime/resource/config_manager/config_manager.h b/engine/source/runtime/resource/config_manager/config_manager.h index 7bbcc8e43..3c2e4ee83 100644 --- a/engine/source/runtime/resource/config_manager/config_manager.h +++ b/engine/source/runtime/resource/config_manager/config_manager.h @@ -2,10 +2,32 @@ #include +#include "runtime/core/meta/reflection/reflection.h" + namespace Pilot { struct EngineInitParams; + REFLECTION_TYPE(Config) + CLASS(Config, Fields) + { + REFLECTION_BODY(Config); + + public: + std::string asset_folder; + std::string schema_folder; + std::string default_world_url; + std::string big_icon; + std::string small_icon; + std::string font_file; + std::string global_rendering_res; + std::string log_pattern; + +#ifdef ENABLE_PHYSICS_DEBUG_RENDERER + std::string jolt_asset_folder; +#endif + }; + class ConfigManager { public: @@ -24,6 +46,7 @@ namespace Pilot const std::string& getDefaultWorldUrl() const; const std::string& getGlobalRenderingResUrl() const; + const std::string& getLogPattern() const; private: std::filesystem::path m_root_folder; @@ -37,7 +60,6 @@ namespace Pilot std::filesystem::path m_jolt_physics_asset_folder; #endif - std::string m_default_world_url; - std::string m_global_rendering_res_url; + Config m_config; }; } // namespace Pilot