diff --git a/engine/include/api.h b/engine/include/api.h index ad288c4..06dff05 100644 --- a/engine/include/api.h +++ b/engine/include/api.h @@ -1,4 +1,8 @@ #pragma once #include "zlib.h" ENGINE_API const char* engine(); -inline Module engine_module{engine(), true}; \ No newline at end of file +#ifdef ENGINE_API_VAL +ENGINE_API inline Module engine_module{ engine(), false }; +#else +ENGINE_API extern Module engine_module; +#endif \ No newline at end of file diff --git a/engine/modules/asset/include/asset.h b/engine/modules/asset/include/asset.h index afe3392..1eaff15 100644 --- a/engine/modules/asset/include/asset.h +++ b/engine/modules/asset/include/asset.h @@ -1,4 +1,5 @@ #pragma once #include "zlib.h" +#include "core.h" const char* asset(); inline Module asset_module{ asset(), false}; \ No newline at end of file diff --git a/engine/modules/core/include/core.h b/engine/modules/core/include/core.h index 754e931..1df9a48 100644 --- a/engine/modules/core/include/core.h +++ b/engine/modules/core/include/core.h @@ -1,4 +1,14 @@ #pragma once #include "zlib.h" const char* core(); -inline Module core_module{ core(), false}; \ No newline at end of file +inline Module core_module{ core(), false}; +struct ModuleManager; +struct ModuleManagerPtr { + ModuleManager* ptr; + ModuleManagerPtr(); +}; +CORE_API inline ModuleManagerPtr ms_instance; +struct ModuleManager { + ModuleManager(); + static ModuleManager* Ptr(); +}; \ No newline at end of file diff --git a/engine/modules/core/src/core.cpp b/engine/modules/core/src/core.cpp index b0886ab..57bb94a 100644 --- a/engine/modules/core/src/core.cpp +++ b/engine/modules/core/src/core.cpp @@ -3,3 +3,20 @@ const char* core() { return "core"; } + +ModuleManager::ModuleManager() +{ + std::cout << "ModuleManager::" << uintptr_t(this) << std::endl; +} + +ModuleManager* ModuleManager::Ptr() +{ + static ModuleManager module; + auto* ptr = &module; + return ptr; +} + +ModuleManagerPtr::ModuleManagerPtr() +{ + ptr = ModuleManager::Ptr(); +} diff --git a/engine/modules/zlib/include/zlib.h b/engine/modules/zlib/include/zlib.h index fb2415c..b301222 100644 --- a/engine/modules/zlib/include/zlib.h +++ b/engine/modules/zlib/include/zlib.h @@ -8,8 +8,8 @@ struct Detail { int del_count = 0; }; struct Module; -inline Detail detail{}; -inline std::vector* pModuleList{}; +ZLIB_API inline Detail detail; +ZLIB_API inline std::vector* pModuleList; struct Module { std::string name; bool kind; diff --git a/engine/modules/zlib/xmake.lua b/engine/modules/zlib/xmake.lua index c5a7f6c..b0acf32 100644 --- a/engine/modules/zlib/xmake.lua +++ b/engine/modules/zlib/xmake.lua @@ -6,3 +6,4 @@ target("zlib") add_includedirs("include", {public = true}) add_packages("spdlog", {public = true}) add_rules("engine.api") + add_defines("ZLIB_API_TEST") diff --git a/engine/xmake/api_define.lua b/engine/xmake/api_define.lua deleted file mode 100644 index f6ceee5..0000000 --- a/engine/xmake/api_define.lua +++ /dev/null @@ -1,9 +0,0 @@ -function main(target, name) - local api = string.upper(name) .. "_API" - if target:kind() == "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)", {public=false}) - end -end \ No newline at end of file diff --git a/engine/xmake/modules/find_sdk.lua b/engine/xmake/modules/find_sdk.lua new file mode 100644 index 0000000..e603a16 --- /dev/null +++ b/engine/xmake/modules/find_sdk.lua @@ -0,0 +1,37 @@ +function find_exe_dir() + local os_name = os.host() + local arch_name = os.arch() + local mode_name = is_mode("debug") and "debug" or "release" + + -- 构建生成目录路径 + return path.join(os.projectdir(), "build", os_name, arch_name, mode_name) +end +function find_my_program(name, sdkdir, use_next) + import("lib.detect.find_file") + import("lib.detect.find_program") + import("lib.detect.find_tool") + + local sdkdir = sdkdir or path.join(os.projectdir(), "tools") + local exedir = find_exe_dir() + local tool = find_tool(name, {pathes = {sdkdir, exedir, "/usr/local/bin"}}) + local prog = tool and tool.program or find_program(name, {pathes = {sdkdir, exedir, "/usr/local/bin"}}) + prog = prog or find_file(name, {sdkdir, exedir}) + if (prog == nil) then + if os.host() ~= "windows" then + local outdata, errdata = os.iorun("which " .. name) + if (errdata ~= nil or errdata ~= "") then + prog = string.gsub(outdata, "%s+", "") + end + else + prog = find_file(name .. ".exe", {sdkdir}) + end + end + if (prog == nil) then + if not use_next then + return find_my_program(name, path.join(sdkdir, name), true) + end + print(name .. " not found! under " .. sdkdir, exedir) + return + end + return {program = prog, sdkdir = sdkdir} +end diff --git a/engine/xmake/rule_api/rule_api.lua b/engine/xmake/rule_api/rule_api.lua new file mode 100644 index 0000000..1db47c1 --- /dev/null +++ b/engine/xmake/rule_api/rule_api.lua @@ -0,0 +1,23 @@ +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)", {public=false}) + end +end +function main(target) + local name = target:name() + local is_static = target:kind() == "static" + add_define(target, name, is_static) + local deps = target:get("deps") + if not deps then return end + import("core.project.project") + for _,dep in ipairs(deps) do + local deptarget = project.target(dep) + if deptarget:kind() == "static" 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/xmake.lua b/engine/xmake/xmake.lua index 00d3cee..86fa590 100644 --- a/engine/xmake/xmake.lua +++ b/engine/xmake/xmake.lua @@ -1,16 +1,2 @@ -rule("engine.api") - on_load(function (target) - print(target:name()) - import("api_define") - api_define(target, target:name()) - local deps = target:get("deps") - if not deps then return end - import("core.project.project") - local is_static = target:kind() == "static" - for _,name in ipairs(deps) do - local deptarget = project.target(name) - if deptarget:kind() == "static" then - api_define(target, name) - end - end - end) \ No newline at end of file +includes("*/xmake.lua") +add_moduledirs(path.join(os.projectdir(), "engine/xmake/modules")) \ No newline at end of file diff --git a/game/vulkan/include/vulkan.h b/game/vulkan/include/vulkan.h index 92a1abe..0980798 100644 --- a/game/vulkan/include/vulkan.h +++ b/game/vulkan/include/vulkan.h @@ -1,4 +1,5 @@ #pragma once #include "zlib.h" +#include "core.h" VULKAN_API const char* vulkan(); -inline Module vulkan_module{vulkan(), true}; \ No newline at end of file +inline Module vulkan_module{vulkan(), true}; diff --git a/game/zworld/include/zworld.h b/game/zworld/include/zworld.h index 1b3fae6..02848be 100644 --- a/game/zworld/include/zworld.h +++ b/game/zworld/include/zworld.h @@ -1,4 +1,9 @@ #pragma once #include "zlib.h" +#include "core.h" ZWORLD_API const char* zworld(); -inline Module zworld_module{zworld(), true}; \ No newline at end of file +#ifdef ZWORLD_API_VAL +ZWORLD_API inline Module zworld_module{ zworld(), false }; +#else +ZWORLD_API extern Module zworld_module; +#endif \ No newline at end of file