diff --git a/.gitignore b/.gitignore index 4e806eb..0f28dcb 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ vsxmake*/ engine/logs/zengine.log +tools/ diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..da4755b --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,34 @@ +{ + // 使用 IntelliSense 了解相关属性。 + // 悬停以查看现有属性的描述。 + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "lua", + "request": "launch", + "tag": "normal", + "name": "LuaPanda", + "description": "通用模式,通常调试项目请选择此模式 | launchVer:3.2.0", + "cwd": "${workspaceFolder}", + "luaFileExtension": "", + "connectionPort": 8818, + "stopOnEntry": true, + "useCHook": true, + "autoPathMode": true + }, + { + "type": "lua", + "request": "launch", + "tag": "independent_file", + "name": "LuaPanda-IndependentFile", + "description": "独立文件调试模式,使用前请参考文档", + "luaPath": "", + "packagePath": [], + "luaFileExtension": "", + "connectionPort": 8820, + "stopOnEntry": true, + "useCHook": true + } + ] +} \ No newline at end of file diff --git a/engine/.vscode/launch.json b/engine/.vscode/launch.json new file mode 100644 index 0000000..da4755b --- /dev/null +++ b/engine/.vscode/launch.json @@ -0,0 +1,34 @@ +{ + // 使用 IntelliSense 了解相关属性。 + // 悬停以查看现有属性的描述。 + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "lua", + "request": "launch", + "tag": "normal", + "name": "LuaPanda", + "description": "通用模式,通常调试项目请选择此模式 | launchVer:3.2.0", + "cwd": "${workspaceFolder}", + "luaFileExtension": "", + "connectionPort": 8818, + "stopOnEntry": true, + "useCHook": true, + "autoPathMode": true + }, + { + "type": "lua", + "request": "launch", + "tag": "independent_file", + "name": "LuaPanda-IndependentFile", + "description": "独立文件调试模式,使用前请参考文档", + "luaPath": "", + "packagePath": [], + "luaFileExtension": "", + "connectionPort": 8820, + "stopOnEntry": true, + "useCHook": true + } + ] +} \ No newline at end of file diff --git a/engine/3rdparty/zlib/include/refl/detail/field.h b/engine/3rdparty/zlib/include/refl/detail/field.h index f98ff6e..0503cf1 100644 --- a/engine/3rdparty/zlib/include/refl/detail/field.h +++ b/engine/3rdparty/zlib/include/refl/detail/field.h @@ -6,10 +6,12 @@ #include using Ubpa::Name; using Ubpa::type_name; +consteval Name FName(const char* buf) { + return Name(buf); +} namespace refl { using Offset = uint32_t; using Method = void*; - struct MemberData { Offset offset; Any value; diff --git a/engine/3rdparty/zlib/test/refl/vertex.h b/engine/3rdparty/zlib/test/refl/vertex.h index 96f2444..e6149f0 100644 --- a/engine/3rdparty/zlib/test/refl/vertex.h +++ b/engine/3rdparty/zlib/test/refl/vertex.h @@ -21,7 +21,7 @@ struct vec3 : public vec3_parent { float y = 2; __cppast(Meta = { 0.f}) float z = 3; - string name{ "hellohellohellohellohellohello" }; + string name{ "hello" }; __cppast(Meta = { {3,4} }) int norm(int x1, int& x2)override { int tmp = x1 * 2 + 1; @@ -32,8 +32,8 @@ struct vec3 : public vec3_parent { } virtual float norm1(int& x1) { x1 = x1 * x * y * z; - //x = x1; - //y = x1 - 1; + x = x1; + y = x1 - 1; //z = x1 - 10; //cout << x1 << "::norm1" << endl; return x1; @@ -53,19 +53,18 @@ struct vec3_Static_Meta { }; consteval static auto __MakeStaticFields() { return std::array{ - StaticMemberField(&vec3::x, "x", {0.f,vec4{}}), - StaticMemberField(&vec3::y, "y", {0.f,{}}), - StaticMemberField(&vec3::z, "z", {0.f,{}}), - StaticMethodField(&vec3::norm, "norm", {{10,9},{}}), - StaticMethodField(&vec3::norm1, "norm1", {{10},{}}), - StaticMethodField(&vec3::norm2, "norm2", {{10},{}}), + StaticMemberField(&vec3::x, FName("x"), {0.f,vec4{}}), + StaticMemberField(&vec3::y, FName("y"), {0.f,{}}), + StaticMemberField(&vec3::z, FName("z"), {0.f,{}}), + StaticMethodField(&vec3::norm, FName("norm"), {{10,9},{}}), + StaticMethodField(&vec3::norm1, FName("norm1"), {{10},{}}), + StaticMethodField(&vec3::norm2, FName("norm2"), {{10},{}}), }; } consteval static int Size() { return fetch_meta_size(); } }; -constexpr int size = vec3_Static_Meta::Size(); struct vec3_Meta : public Meta{ using MyStatic = vec3_Static_Meta; using MyUClass = UClass_Meta; @@ -73,12 +72,13 @@ struct vec3_Meta : public Meta{ static auto __MakeFields() { char* memory = &s_data[0]; return std::array{ - MemberField(&vec3::x, "x",memory, {0.f,vec4{}}), - MemberField(&vec3::y, "y",memory, {0.f,{}}), - MemberField(&vec3::z, "z",memory, {0.f,{}}), - MethodField(&vec3::norm, "norm", memory, {{10,9},{}}), - MethodField(&vec3::norm1, "norm1",memory, {{10},{}}), - MethodField(&vec3::norm2, "norm2",memory, {{10},{}}), + MemberField(&vec3::x, FName("x"),memory, {0.f,vec4{}}), + MemberField(&vec3::y, FName("y"),memory, {0.f,{}}), + MemberField(&vec3::z, FName("z"),memory, {0.f,{}}), + MethodField(&vec3::norm, FName("norm"), memory, {{10,9},{}}), + MethodField(&vec3::norm1, FName("norm1"),memory, {{10},{}}), + MethodField(&vec3::norm2, FName("norm2"),memory, {{10},{}}), }; }; -}; \ No newline at end of file +}; +#include "meta_vertex.inl" \ No newline at end of file diff --git a/engine/3rdparty/zlib/test/refl_01.cpp b/engine/3rdparty/zlib/test/refl_01.cpp index bcd8178..eb6cf0b 100644 --- a/engine/3rdparty/zlib/test/refl_01.cpp +++ b/engine/3rdparty/zlib/test/refl_01.cpp @@ -5,19 +5,19 @@ vec3 v; constexpr int smeta = sizeof(vec3_Meta); constexpr int scls = sizeof(decltype(*cls)); auto ov = cls->New((void*)&v); -constexpr Name func("norm"); +constexpr Name func = FName("norm"); void TestRefl1(benchmark::State& state) { int x = 1, y = 2; for (auto _ : state) { std::array arr{&x, ov.ptr}; svector svec(&arr.front(), arr.size(), 2); - ov.Invoke("norm", svec); + ov.Invoke(FName("norm"), svec); } } BENCHMARK(TestRefl1); void TestRefl2(benchmark::State& state) { int x = 1, y = 2; - constexpr auto id = GetStaticFieldID(func); + constexpr auto id = GetStaticFieldID(FName("norm")); auto field = cls->GetField(id); for (auto _ : state) { std::array arr{&x, ov.ptr}; @@ -28,7 +28,7 @@ void TestRefl2(benchmark::State& state) { BENCHMARK(TestRefl2); void TestRefl3(benchmark::State& state) { int x = 1, y = 2; - constexpr auto id = GetStaticFieldID(func); + constexpr auto id = GetStaticFieldID(FName("norm")); auto field = cls->GetField(id); for (auto _ : state) { field->Invoke({ &x,ov.ptr, x, y }); diff --git a/engine/3rdparty/zlib/xmake.lua b/engine/3rdparty/zlib/xmake.lua index 0455c1a..02107fd 100644 --- a/engine/3rdparty/zlib/xmake.lua +++ b/engine/3rdparty/zlib/xmake.lua @@ -31,6 +31,9 @@ target("zlib_test") -- add_files("test/04promise.cpp") target("refl_zlib") + add_rules("c++.codegen",{ + files = {"test/refl/*.h", "test/refl/*.hpp"} + }) set_kind("binary") add_deps("zlib") add_packages("benchmark") diff --git a/engine/xmake.lua b/engine/xmake.lua index da1bbc2..3b4e6b8 100644 --- a/engine/xmake.lua +++ b/engine/xmake.lua @@ -1,5 +1,5 @@ includes("3rdparty/xmake.lua") -includes("xmake/**xmake.lua") +includes("xmake/xmake.lua") --includes("test/**xmake.lua") target("zengine") set_kind("binary") diff --git a/engine/xmake/gen/meta_refl.lua b/engine/xmake/gen/meta_refl.lua new file mode 100644 index 0000000..afd6be0 --- /dev/null +++ b/engine/xmake/gen/meta_refl.lua @@ -0,0 +1,45 @@ +import("core.project.depend") +function cmd_compile(genfile, sourcefile) + print(os.programdir()) + import("find_sdk") + local meta = find_sdk.find_my_program("refl") + argv = {"build", sourcefile, "--output=" .. genfile} + print("cmd_compile", genfile) + os.execv(meta.program, argv, {envs = {PATH = meta.sdkdir}}) + return argv +end + +function _listen_gen_file(target, batch) + genfile, sourcefile = batch[1], batch[2] + local dependfile = target:dependfile(genfile) + depend.on_changed( + function() + cmd_compile(genfile, sourcefile) + end, + {dependfile = dependfile, files = sourcefile} + ) +end +function gen(target) + local gen_batch = target:data("codegen.batch") + if not gen_batch then + return + end + for _, batch in ipairs(gen_batch) do + if batch[2] then + _listen_gen_file(target, batch) + end + end +end + +function main(target, headerfiles) + local sourcedir = path.join(target:autogendir({root = true}), target:plat(), "inl") + target:add("includedirs", sourcedir, {public = true}) + local gen_batch = {} + for idx, headerfile in pairs(headerfiles) do + -- batch + sourcefile = path.join(sourcedir, "meta_" .. path.basename(headerfile) .. ".inl") + table.insert(gen_batch, {sourcefile, headerfile}) + end + -- save unit batch + target:data_set("codegen.batch", gen_batch) +end diff --git a/engine/xmake/gen/xmake.lua b/engine/xmake/gen/xmake.lua new file mode 100644 index 0000000..1d25039 --- /dev/null +++ b/engine/xmake/gen/xmake.lua @@ -0,0 +1,18 @@ +rule("c++.codegen") + set_extensions(".inl") + after_load(function (target) + import("meta_refl") + local headerfiles = {} + local files = target:extraconf("rules", "c++.codegen", "files") + for _, file in ipairs(files) do + local p = path.join(target:scriptdir(), file) + for __, filepath in ipairs(os.files(p)) do + table.insert(headerfiles, filepath) + end + end + meta_refl(target, headerfiles) + end) + on_config(function (target) + print("c++.codegen on_config") + import("meta_refl").gen(target) + 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..d944fe6 --- /dev/null +++ b/engine/xmake/modules/find_sdk.lua @@ -0,0 +1,28 @@ +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 tool = find_tool(name, {pathes = {sdkdir, "/usr/local/bin"}}) + local prog = tool and tool.program or find_program(name, {pathes = {sdkdir, "/usr/local/bin"}}) + prog = prog or find_file(name, {sdkdir}) + 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 .. "_f not found! under " .. sdkdir) + return + end + return {program = prog, sdkdir = sdkdir} +end diff --git a/engine/xmake/xmake.lua b/engine/xmake/xmake.lua new file mode 100644 index 0000000..86fa590 --- /dev/null +++ b/engine/xmake/xmake.lua @@ -0,0 +1,2 @@ +includes("*/xmake.lua") +add_moduledirs(path.join(os.projectdir(), "engine/xmake/modules")) \ No newline at end of file