diff --git a/engine/3rdparty/ubpa/USmallFlat/xmake.lua b/engine/3rdparty/ubpa/USmallFlat/xmake.lua new file mode 100644 index 0000000..0dc3cba --- /dev/null +++ b/engine/3rdparty/ubpa/USmallFlat/xmake.lua @@ -0,0 +1,8 @@ + +package("USmallFlat") + set_kind("library", {headeronly = true}) + set_urls("https://github.com/Ubpa/USmallFlat.git") + add_includedirs("include") + on_install(function (package) + os.cp("include", package:installdir()) + end) \ No newline at end of file diff --git a/engine/3rdparty/ubpa/UTemplate/xmake.lua b/engine/3rdparty/ubpa/UTemplate/xmake.lua new file mode 100644 index 0000000..ccc2005 --- /dev/null +++ b/engine/3rdparty/ubpa/UTemplate/xmake.lua @@ -0,0 +1,7 @@ +package("UTemplate") + set_kind("library", {headeronly = true}) + set_urls("https://github.com/Ubpa/UTemplate.git") + add_includedirs("include") + on_install(function (package) + os.cp("include", package:installdir()) + end) \ No newline at end of file diff --git a/engine/3rdparty/zlib/include/refl/field.h b/engine/3rdparty/zlib/include/refl/field.h new file mode 100644 index 0000000..0b39a4a --- /dev/null +++ b/engine/3rdparty/zlib/include/refl/field.h @@ -0,0 +1,27 @@ +#pragma once +#include "UTemplate/Type.hpp" +#include +#include +using Ubpa::Name; +using Ubpa::type_name; +namespace refl { + struct MemberField { + uint32_t offset; + }; + struct MemberFuncField { + using Offsetor = std::function; + Offsetor func; + }; + class UClass; + struct FieldPtr { + using Offsetor = std::function; + // raw offsetor + using Data = std::variant< + uint32_t, // forward_offset_value 0 BASIC + double // static_obj 2 STATIC + >; + Name name; + const UClass* type; + Data data; + }; +} \ No newline at end of file diff --git a/engine/3rdparty/zlib/include/refl/type.h b/engine/3rdparty/zlib/include/refl/type.h new file mode 100644 index 0000000..f184037 --- /dev/null +++ b/engine/3rdparty/zlib/include/refl/type.h @@ -0,0 +1,13 @@ +#pragma once +#include +namespace refl { + template + struct TypeInfo; + + template + struct TypeInfo> { + using UClass = typename T::UClass; + //这里的特性怎么走不到呢 + inline static UClass StaticClass = UClass::BuildClass(); + }; +} \ No newline at end of file diff --git a/engine/3rdparty/zlib/include/refl/uclass.h b/engine/3rdparty/zlib/include/refl/uclass.h new file mode 100644 index 0000000..0d2009c --- /dev/null +++ b/engine/3rdparty/zlib/include/refl/uclass.h @@ -0,0 +1,32 @@ +#pragma once +#include "type.h" +#include "field.h" +namespace refl { + class UClass{ + public: + Name name; + uint32_t size; + public: + void Var() { + + } + + public: + template + constexpr static UClass BuildClass() { + return {type_name().View(), sizeof(T)}; + } + protected: + template + FieldPtr MakeMemberField(T U::* ptr, Name name) { + FieldPtr::Data member = { offset }; + return { name, &TypeInfo::StaticClass, {member} }; + } + }; + template + struct TypeInfo { + using UClass = UClass; + //这里的语法我也看不懂呀,防警告的,显示声明为模板调用 + inline constexpr static UClass StaticClass = UClass::template BuildClass(); + }; +} \ No newline at end of file diff --git a/engine/3rdparty/zlib/test/refl/vertex.h b/engine/3rdparty/zlib/test/refl/vertex.h new file mode 100644 index 0000000..1e41df0 --- /dev/null +++ b/engine/3rdparty/zlib/test/refl/vertex.h @@ -0,0 +1,53 @@ +#pragma once +#include +#include +#include +using namespace std; +#define sizeof_field(_struct, _field) sizeof(((_struct*)0)->_field) +// 顶点最多关联4个骨骼 +#define MAX_NUM_BONES_PER_VERTEX 4 +struct Vector2 { + float x; + float y; +}; +struct Vector3 { + float x; + float y; + float z; +}; +struct Vertex { + struct UClass { + virtual void BindLayout() = 0; + + }; +}; +struct PosVertex : public Vertex { + Vector3 Position = {}; + struct UClass : public Vertex::UClass{ + int MemCount = 1; + tuple Position{sizeof_field(PosVertex, Position), offsetof(PosVertex, Position)}; + + virtual void BindLayout() {}; + }; +}; + +struct TexVertex : public Vertex { + Vector3 Position = {}; + Vector3 Normal = {}; + Vector2 TexCoords = {}; +}; +struct BoneVertex : public Vertex +{ + Vector3 Position = {}; + Vector2 TexCoords = {}; + Vector3 Normal = {}; + Vector3 Tangent = {}; + // 骨骼蒙皮数据 + float Weights[MAX_NUM_BONES_PER_VERTEX] = {}; + uint32_t BoneIDs[MAX_NUM_BONES_PER_VERTEX] = {}; + + void AddBoneData(uint32_t boneID, float weight) {}; +}; + + + diff --git a/engine/3rdparty/zlib/test/refl_01.cpp b/engine/3rdparty/zlib/test/refl_01.cpp new file mode 100644 index 0000000..829c443 --- /dev/null +++ b/engine/3rdparty/zlib/test/refl_01.cpp @@ -0,0 +1,40 @@ +#include +#include +#include "refl/uclass.h" +#include "vertex.h" +using namespace std; +using namespace refl; +struct vec3 { + using UClass = class vec3_UClass; + float x; + float y; + float z; + float norm() { + return x * y * z; + } +}; +struct vec3_UClass : public UClass { + array FList; + constexpr static vec3_UClass BuildClass() { + vec3_UClass cls{}; + cls.name = type_name().View(); + cls.size = sizeof(vec3); + //offsetof(vec3, x) 很坑,相当坑 + cls.FList[0] = cls.MakeMemberField(&vec3::x, "x"); + cls.FList[1] = cls.MakeMemberField(&vec3::y, "y"); + cls.FList[2] = cls.MakeMemberField(&vec3::z, "z"); + return cls; + } +}; +int main() { + + using uclass = TypeInfo::UClass; + auto& res = TypeInfo::StaticClass; + auto& res2 = TypeInfo::StaticClass; + + auto& res3 = TypeInfo::StaticClass; + auto t1 = res3.FList[0]; + //using t2 = t1::UClass; + std::cout << sizeof(Name) << "Type2: " << typeid(vec3).name() << std::endl; + cout << "hello world\n"; +} \ No newline at end of file diff --git a/engine/3rdparty/zlib/xmake.lua b/engine/3rdparty/zlib/xmake.lua index 88d0ace..d512e3b 100644 --- a/engine/3rdparty/zlib/xmake.lua +++ b/engine/3rdparty/zlib/xmake.lua @@ -1,6 +1,8 @@ set_languages("cxx20") +add_requires("UTemplate") target("zlib") set_kind("static") + add_packages("UTemplate", {public = true}) add_includedirs("include", {public = true}) add_files("src/**/*.cpp") add_headerfiles("include/**/*.h") @@ -18,12 +20,19 @@ target("zlib_test") -- add_deps("zlib") -- add_files("test/02condition.cpp") -target("zlib_test03_semaphore") - set_kind("binary") - add_deps("zlib") - add_files("test/03semaphore.cpp") +-- target("zlib_test03_semaphore") +-- set_kind("binary") +-- add_deps("zlib") +-- add_files("test/03semaphore.cpp") -- target("zlib_test04_promise") -- set_kind("binary") -- add_deps("zlib") --- add_files("test/04promise.cpp") \ No newline at end of file +-- add_files("test/04promise.cpp") + +target("refl_zlib") + set_kind("binary") + add_deps("zlib") + add_includedirs("test/refl") + add_files("test/refl_01.cpp") + add_headerfiles("test/refl/*.h") \ No newline at end of file