diff --git a/.vscode/emmyrc.json b/.vscode/emmyrc.json new file mode 100644 index 0000000..585bfa4 --- /dev/null +++ b/.vscode/emmyrc.json @@ -0,0 +1,7 @@ +{ + "diagnostics": { + "disable": [ + "undefined-global" + ] + } +} diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..f213c82 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "tangzx.emmylua" + ] +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index acf978e..07a5c90 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -17,5 +17,10 @@ ], "ideConnectDebugger": true } - ] + ], + "diagnostics": { + "disable": [ + "undefined-global" + ] + }, } \ No newline at end of file diff --git a/engine/modules/engine/asset/xmake.lua b/engine/modules/engine/asset/xmake.lua index 076121c..1b616d8 100644 --- a/engine/modules/engine/asset/xmake.lua +++ b/engine/modules/engine/asset/xmake.lua @@ -5,4 +5,4 @@ static_component("asset","engine") add_includedirs("include/asset") add_headerfiles("include/**.h","include/**.inl") add_files("src/**.cpp") - add_deps("core", {public = true}) \ No newline at end of file + add_deps("core", "zlib") \ No newline at end of file diff --git a/engine/modules/engine/core/include/3rdparty/zlog.h b/engine/modules/engine/core/include/3rdparty/zlog.h index f436cbf..c2c8337 100644 --- a/engine/modules/engine/core/include/3rdparty/zlog.h +++ b/engine/modules/engine/core/include/3rdparty/zlog.h @@ -20,7 +20,7 @@ namespace zlog { m_logger->flush(); } }; - extern zloger zlog; + CORE_API inline zloger zlog; template void info(format_with_location fmt, Args &&...args) { zlog.log(level_enum::info, fmt, std::forward(args)...); @@ -43,5 +43,7 @@ namespace zlog { const std::string format_str = fmt::format(std::forward(args)...); throw std::runtime_error(format_str); }; - void flush(); + inline void flush() { + zlog.flush(); + } }; \ No newline at end of file diff --git a/engine/modules/engine/core/include/archive/json/serialize.h b/engine/modules/engine/core/include/archive/json/serialize.h index 1a41ce6..0b5008e 100644 --- a/engine/modules/engine/core/include/archive/json/serialize.h +++ b/engine/modules/engine/core/include/archive/json/serialize.h @@ -11,9 +11,8 @@ namespace api { using Write = yyjson_mut_val*(*)(yyjson_mut_doc*, const void*); }; struct JsonArchive { - private: - static bool InitJsonSerde(); - inline static bool HasInit = InitJsonSerde(); + public: + static void InitJsonSerde(); public: template static void Register(); diff --git a/engine/modules/engine/core/include/archive/json/serialize.inl b/engine/modules/engine/core/include/archive/json/serialize.inl index ab77072..9213f7f 100644 --- a/engine/modules/engine/core/include/archive/json/serialize.inl +++ b/engine/modules/engine/core/include/archive/json/serialize.inl @@ -27,13 +27,12 @@ namespace api { alc.ctx = mr; return alc; } - inline bool JsonArchive::InitJsonSerde() + inline void JsonArchive::InitJsonSerde() { using std::string_view; #define RegisterAny(T) Register(); #include "../register.inl" #undef RegisterAny - return true; } constexpr size_t VJsonSerdeRead() { return string_hash("JsonSerdeRead"); diff --git a/engine/modules/engine/core/include/module/module.h b/engine/modules/engine/core/include/module/module.h index 2bcb9ab..5c30def 100644 --- a/engine/modules/engine/core/include/module/module.h +++ b/engine/modules/engine/core/include/module/module.h @@ -3,8 +3,6 @@ #include "enum_macro.h" #include "os/shared_library.h" #include "refl/pch.h" -//可变生命周期,回收内存 -inline thread_local pmr::unsynchronized_pool_resource MemPool; // 默认对齐方式 new void* operator new(std::size_t size); // 默认对齐方式 delete diff --git a/engine/modules/engine/core/include/module/module_manager.h b/engine/modules/engine/core/include/module/module_manager.h index 2f66498..ee33edf 100644 --- a/engine/modules/engine/core/include/module/module_manager.h +++ b/engine/modules/engine/core/include/module/module_manager.h @@ -1,7 +1,7 @@ #pragma once #include "module.h" namespace api { - class DLL_API ModuleManager + class CORE_API ModuleManager { friend struct IModule; private: diff --git a/engine/modules/engine/core/src/3rdparty/zlog.cpp b/engine/modules/engine/core/src/3rdparty/zlog.cpp index e4b0ea3..d297c12 100644 --- a/engine/modules/engine/core/src/3rdparty/zlog.cpp +++ b/engine/modules/engine/core/src/3rdparty/zlog.cpp @@ -4,7 +4,6 @@ #include #include namespace zlog { - zloger zlog; zloger::zloger() { auto console_sink = std::make_shared(); @@ -33,7 +32,4 @@ namespace zlog { m_logger->flush(); spdlog::drop_all(); } - void flush(){ - zlog.flush(); - } } diff --git a/engine/modules/engine/core/src/module/module.cpp b/engine/modules/engine/core/src/module/module.cpp index ed421a7..e72b930 100644 --- a/engine/modules/engine/core/src/module/module.cpp +++ b/engine/modules/engine/core/src/module/module.cpp @@ -5,6 +5,7 @@ struct MemDetail { int new_count{ 0 }; int del_count{ 0 }; }; +thread_local pmr::unsynchronized_pool_resource MemPool; thread_local MemDetail detail; void* operator new(std::size_t size) { std::size_t alignment = alignof(std::max_align_t); diff --git a/engine/modules/engine/core/xmake.lua b/engine/modules/engine/core/xmake.lua index 1a0d9be..686ac16 100644 --- a/engine/modules/engine/core/xmake.lua +++ b/engine/modules/engine/core/xmake.lua @@ -5,5 +5,5 @@ static_component("core","engine") add_includedirs("include", "include/3rdparty", {public = true}) add_headerfiles("include/**.h","include/**.inl") add_files("src/**.cpp") - add_deps("zlib", {public = true}) + add_deps("zlib") add_packages("spdlog", {public = true}) \ No newline at end of file diff --git a/engine/modules/engine/zlib/include/pmr/frame_allocator.h b/engine/modules/engine/zlib/include/pmr/frame_allocator.h index aa630ce..9436b11 100644 --- a/engine/modules/engine/zlib/include/pmr/frame_allocator.h +++ b/engine/modules/engine/zlib/include/pmr/frame_allocator.h @@ -48,18 +48,10 @@ inline void* operator new(size_t size, pmr::FrameAllocatorPool* pool, size_t ali return pool->allocate(size, alignment); } #include "frame_allocator.inl" -#ifdef DLL_API_VALUE //全局生命周期,不回收内存 -extern DLL_API inline pmr::FrameAllocatorPool* GlobalPool; +ZLIB_API inline pmr::FrameAllocatorPool* GlobalPool; //局部生命周期,每帧回收内存 -extern DLL_API inline pmr::FrameAllocatorPool* FramePool; -DLL_API pmr::FrameAllocatorPool* GetGlobalPool(); -DLL_API pmr::FrameAllocatorPool* GetFramePool(); -#else -//全局生命周期,不回收内存 -inline pmr::FrameAllocatorPool* GlobalPool; -//局部生命周期,每帧回收内存 -inline pmr::FrameAllocatorPool* FramePool; +ZLIB_API inline pmr::FrameAllocatorPool* FramePool; inline pmr::FrameAllocatorPool* GetGlobalPool() { if (!GlobalPool) { GlobalPool = new pmr::FrameAllocatorPool(); @@ -71,5 +63,4 @@ inline pmr::FrameAllocatorPool* GetFramePool() { FramePool = new(GetGlobalPool()) pmr::FrameAllocatorPool(); } return FramePool; -} -#endif // DLL_API \ No newline at end of file +} \ No newline at end of file diff --git a/engine/modules/engine/zlib/include/pmr/name.inl b/engine/modules/engine/zlib/include/pmr/name.inl index f99e3cd..094f0fc 100644 --- a/engine/modules/engine/zlib/include/pmr/name.inl +++ b/engine/modules/engine/zlib/include/pmr/name.inl @@ -1,7 +1,6 @@ -#include "name.h" namespace pmr { using NameTable_t = table; - struct NameTable { + struct ZLIB_API NameTable { static const string& Find(size_t id); template static std::string_view MakePair(size_t id, T&& str); diff --git a/engine/modules/render/vulkan/include/vulkan/module.h b/engine/modules/render/vulkan/include/vulkan/module.h index aabb287..180abaa 100644 --- a/engine/modules/render/vulkan/include/vulkan/module.h +++ b/engine/modules/render/vulkan/include/vulkan/module.h @@ -1,6 +1,5 @@ #pragma once #include "module/module.h" -#include "asset/asset.h" class VULKAN_API VulkanModule : public api::IDynamicModule { public: diff --git a/engine/modules/xmake.lua b/engine/modules/xmake.lua index 9aa4190..577dc7a 100644 --- a/engine/modules/xmake.lua +++ b/engine/modules/xmake.lua @@ -1,24 +1,22 @@ function header_component(name, owner, opt) target(owner) - add_deps(name, { public = opt and opt.public or true }) + add_deps(name) target_end() target(name) set_kind("headeronly") set_group("Engine/"..owner.."__comp") + add_rules("engine.api") add_includedirs("include", {public = true}) end function static_component(name, owner, opt) target(owner) add_deps(name) - add_defines("DLL_API_VALUE", {public = true}) - add_includedirs("include", {public = true}) target_end() target(name) - set_kind("static") + set_kind("moduleonly") set_group("Engine/"..owner.."__comp") add_rules("engine.api") - add_defines("DLL_API=") - add_includedirs("include") + add_includedirs("include", {public = true}) end function shared_module(name, owner, opt) target(name) diff --git a/engine/src/engine/api.cpp b/engine/src/engine/api.cpp index 25e5fc3..c0f4c98 100644 --- a/engine/src/engine/api.cpp +++ b/engine/src/engine/api.cpp @@ -1,4 +1,6 @@ #include "api.h" +#include "pmr/frame_allocator.h" +#include "pmr/name.h" class ENGINE_API EngineModule : public api::IDynamicModule { public: diff --git a/engine/xmake.lua b/engine/xmake.lua index efa148f..b1acb43 100644 --- a/engine/xmake.lua +++ b/engine/xmake.lua @@ -1,7 +1,7 @@ target("editor") set_kind("shared") set_group("Engine") - add_rules("engine.api", {targets = {"dll", "editor"}}) + add_rules("engine.api") add_headerfiles("include/editor/*.h") add_includedirs("include/editor") add_files("src/editor/*.cpp") @@ -9,7 +9,7 @@ target("engine") add_includedirs("include", {public = true}) set_kind("shared") set_group("Engine") - add_rules("engine.api", {targets = {"dll", "engine"}}) + add_rules("engine.api") add_headerfiles("include/engine/*.h") add_includedirs("include/engine") add_files("src/engine/*.cpp") diff --git a/engine/xmake/rule_api/rule_api.lua b/engine/xmake/rule_api/rule_api.lua new file mode 100644 index 0000000..456dde6 --- /dev/null +++ b/engine/xmake/rule_api/rule_api.lua @@ -0,0 +1,26 @@ +import("core.project.project") +function add_define(target, name, is_static) + local api = string.upper(name) .. "_API" + if is_static then + target:add("defines", api .. "=", api .. "_VAL", {public = false}) + else + target:add("defines", api.."=__declspec(dllimport)", {interface=true}) + target:add("defines", api.."=__declspec(dllexport)", api .. "_VAL", {public=false}) + end +end +function is_static_f(kind) + return kind == "static" or kind == "headeronly" or kind == "moduleonly" +end +function main(target) + local name = target:name() + local is_static = is_static_f(target:kind()) + add_define(target, name, is_static) + local deps = target:get("deps") + if not deps then return end + for _,dep in ipairs(deps) do + local deptarget = project.target(dep) + if is_static_f(deptarget:kind()) then + add_define(target, dep, is_static) + end + end +end \ No newline at end of file diff --git a/engine/xmake/rule_api/xmake.lua b/engine/xmake/rule_api/xmake.lua new file mode 100644 index 0000000..6ad9645 --- /dev/null +++ b/engine/xmake/rule_api/xmake.lua @@ -0,0 +1,5 @@ +rule("engine.api") + on_config(function (target) + import("rule_api") + rule_api(target) + end) \ No newline at end of file diff --git a/engine/xmake/rule_plugin/make_plugin.lua b/engine/xmake/rule_plugin/make_plugin.lua index 6613f8c..e6aef17 100644 --- a/engine/xmake/rule_plugin/make_plugin.lua +++ b/engine/xmake/rule_plugin/make_plugin.lua @@ -1,13 +1,7 @@ import("core.project.depend") -local loadTable = {} function cmd_compile(target, genfile, file) - local name = target:name() - if loadTable[name] then - return - end - loadTable[name] = true import("core.project.project") - target:data_set("compile", true) + local name = target:name() local pub_deps = target:values("module.public_dependencies") local cpp_content = "inline void __" .. name .. "__module::InitMetaData(void){\n" cpp_content = cpp_content.."\tmInfo.name = \"" .. name.."\";\n" diff --git a/engine/xmake/rule_plugin/xmake.lua b/engine/xmake/rule_plugin/xmake.lua index 923a202..e87a77a 100644 --- a/engine/xmake/rule_plugin/xmake.lua +++ b/engine/xmake/rule_plugin/xmake.lua @@ -1,6 +1,6 @@ rule("engine.plugin") set_extensions(".h") - on_load(function (target) + on_config(function (target) import("make_plugin") local file = target:extraconf("rules", "engine.plugin", "file") make_plugin(target, file or "module.h") diff --git a/engine/xmake/rule_tool/xmake.lua b/engine/xmake/rule_tool/xmake.lua index 34d1378..c3b4566 100644 --- a/engine/xmake/rule_tool/xmake.lua +++ b/engine/xmake/rule_tool/xmake.lua @@ -6,14 +6,4 @@ rule("engine.tool") end local exefile = target:targetfile() os.cp(exefile, path.join(tooldir, path.filename(exefile))) - end) -rule("engine.api") - on_load(function (target) - local deps = target:extraconf("rules", "engine.api", "targets") - deps = deps or {target:name()} - for k,v in ipairs(deps) do - local api = string.upper(v) .. "_API" - target:add("defines", api.."=__declspec(dllimport)", {interface=true}) - target:add("defines", api.."=__declspec(dllexport)", {public=false}) - end end) \ No newline at end of file