diff --git a/engine/3rdparty/zlib/include/refl/detail/convert.h b/engine/3rdparty/zlib/include/refl/detail/convert.h index f6ac140..96cdaba 100644 --- a/engine/3rdparty/zlib/include/refl/detail/convert.h +++ b/engine/3rdparty/zlib/include/refl/detail/convert.h @@ -2,17 +2,28 @@ #include "any.h" #include namespace refl { - - using ConvertFunc = bool (*)(Any&, const Any&); - using ConvertMap = std::unordered_map; + using UClassPair = std::pair; + // 自定义哈希函数 + struct UClassPairHash { + std::size_t operator()(const UClassPair& pair) const { + std::hash ptr_hash; + return ptr_hash(pair.first) ^ (ptr_hash(pair.second) << 1); + } + }; + struct UClassPairEqual { + bool operator()(const UClassPair& lhs, const UClassPair& rhs) const { + return lhs.first == rhs.first && lhs.second == rhs.second; + } + }; + using ConvertFunc = bool (*)(Any& to, const Any& from); + using ConvertMap = std::unordered_map; class Convert { protected: static ConvertMap BuildClassMap(); + template + static bool ConvertTo(Any& to, const Any& from); public: - static bool ToInt32(Any& dst, const Any& src); - static bool ToFloat(Any& dst, const Any& src); - static bool ToString(Any& dst,const Any& src); - static bool Construct(Any& dst, const Any& src); + static bool Construct(Any& to,const Any& from); inline static ConvertMap ClassMap = BuildClassMap(); }; } \ No newline at end of file diff --git a/engine/3rdparty/zlib/include/refl/detail/convert.inl b/engine/3rdparty/zlib/include/refl/detail/convert.inl index 39e3d87..8a65f28 100644 --- a/engine/3rdparty/zlib/include/refl/detail/convert.inl +++ b/engine/3rdparty/zlib/include/refl/detail/convert.inl @@ -2,48 +2,48 @@ #include #include "convert.h" namespace refl { - inline bool Convert::ToString(Any& dst, const Any& src) - { - if (src.cls == &TypeInfo::StaticClass) { - std::construct_at(dst.CastTo(), src.CastTo()); - return true; - } - return false; - } - inline bool Convert::ToInt32(Any& dst, const Any& src) - { - if (src.cls == &TypeInfo::StaticClass) { - *dst.CastTo() = *src.CastTo(); - return true; - } - return false; - } - inline bool Convert::ToFloat(Any& dst, const Any& src) - { - if (src.cls == &TypeInfo::StaticClass) { - *dst.CastTo() = *src.CastTo(); - return true; - } - return false; - } - inline bool Convert::Construct(Any& dst, const Any& src) - { - if (dst.cls->Construct((void*)dst.ptr, src)) { - return true; - } - auto it = ClassMap.find(dst.cls); - if (it == ClassMap.end()) { + template + inline bool Convert::ConvertTo(Any& to, const Any& from) { + if constexpr (std::is_same_v) { + if constexpr (std::is_same_v) { + std::construct_at(to.CastTo(), from.CastTo()); + return true; + } return false; } - return it->second(dst, src); + else if constexpr (std::is_arithmetic_v) { + if constexpr (std::is_arithmetic_v) { + *to.CastTo() = (To)*from.CastTo(); + return true; + } + return false; + } + return false; } inline ConvertMap Convert::BuildClassMap() { ConvertMap classMap; - classMap.emplace(&TypeInfo::StaticClass, &ToString); - classMap.emplace(&TypeInfo::StaticClass, &ToInt32); - classMap.emplace(&TypeInfo::StaticClass, &ToInt32); - classMap.emplace(&TypeInfo::StaticClass, &ToFloat); +#define RegisterToFrom(To, From) classMap.emplace(std::make_pair(&TypeInfo::StaticClass, &TypeInfo::StaticClass), &Convert::ConvertTo);\ + classMap.emplace(std::make_pair(&TypeInfo::StaticClass, &TypeInfo::StaticClass), &Convert::ConvertTo) + + RegisterToFrom(int, uint32_t); + RegisterToFrom(int, uint16_t); + RegisterToFrom(int, float); + RegisterToFrom(int, double); + RegisterToFrom(float, uint32_t); + RegisterToFrom(float, double); + RegisterToFrom(std::string, char); +#undef RegisterToFrom return classMap; } + inline bool Convert::Construct(Any& to,const Any& from) + { + if (to.Construct(from)) + return true; + auto it = ClassMap.find(std::make_pair(to.cls, from.cls)); + if (it != ClassMap.end()) { + return it->second(to, from); + } + return false; + } } \ No newline at end of file diff --git a/engine/3rdparty/zlib/include/refl/detail/meta.h b/engine/3rdparty/zlib/include/refl/detail/meta.h index ea51959..7a7c1a4 100644 --- a/engine/3rdparty/zlib/include/refl/detail/meta.h +++ b/engine/3rdparty/zlib/include/refl/detail/meta.h @@ -11,6 +11,22 @@ namespace refl { using MethodType = R(*)(Args...); return MethodType{ nullptr }; } + template + consteval int fetch_tuple_elm_size(int first = 0) { + using T = std::tuple_element::type; + if constexpr (std::is_same_v) { + return 0; + } + else { + return Index >= first ? sizeof(T) : 0; + } + } + template + consteval int fetch_tuple_size(std::index_sequence, int first = 0) { + int size = 0; + (..., (size += fetch_tuple_elm_size(first))); + return size; + } template consteval int fetch_meta_size() { auto fields = T::__MakeStaticFields(); @@ -32,7 +48,7 @@ namespace refl { class MetaHelp { public: template - static FieldPtr CtorField(char*& memory, const MethodData& data = {}); + static FieldPtr CtorField(T(*ptr)(Args...), char*& memory, const MethodData& data = {}); template static FieldPtr MemberField(T Obj::* ptr, const Name& name, char*& memory, const MemberData& data = {}); diff --git a/engine/3rdparty/zlib/include/refl/detail/meta.inl b/engine/3rdparty/zlib/include/refl/detail/meta.inl index 025141e..ba42fa2 100644 --- a/engine/3rdparty/zlib/include/refl/detail/meta.inl +++ b/engine/3rdparty/zlib/include/refl/detail/meta.inl @@ -8,7 +8,7 @@ namespace refl { new (mem) T(std::forward(args)...); } template - inline FieldPtr MetaHelp::CtorField(char*& memory, const MethodData& data) + inline FieldPtr MetaHelp::CtorField(T(*ptr)(Args...), char*& memory, const MethodData& data) { MethodData method; uint32_t flag = FIELD_MEMBER_FLAG | FIELD_CTOR_FLAG; diff --git a/engine/3rdparty/zlib/include/refl/detail/type.h b/engine/3rdparty/zlib/include/refl/detail/type.h index 13febb2..742ebda 100644 --- a/engine/3rdparty/zlib/include/refl/detail/type.h +++ b/engine/3rdparty/zlib/include/refl/detail/type.h @@ -12,9 +12,6 @@ namespace refl_impl { template struct _Meta; - - template - struct _ContainerMeta; } namespace refl { // 定义一个模板结构体用于检测是否为 数组 @@ -53,7 +50,12 @@ namespace refl { concept is_tuple_v = is_tuple::value; template - concept is_container_v = !is_array::value && !std::is_same_v && requires(T a) { + concept is_string_v = requires(T t) { + { static_cast(t) } -> std::convertible_to; + }; + + template + concept is_container_v = !is_array::value && !is_string_v && requires(T a) { { a.begin() } -> std::input_iterator; { a.end() } -> std::input_iterator; }; @@ -114,4 +116,10 @@ namespace refl { template using TypeInfo = TypeInfoImpl>; +} +namespace refl { + constexpr static std::array IndexNames = { + "1", "2", "3", "4", "5", "6", "7", "8", + "9", "10", "11", "12", "13", "14", "15", "16" + }; } \ No newline at end of file diff --git a/engine/3rdparty/zlib/include/refl/detail/uclass.inl b/engine/3rdparty/zlib/include/refl/detail/uclass.inl index bee7386..0d40cc6 100644 --- a/engine/3rdparty/zlib/include/refl/detail/uclass.inl +++ b/engine/3rdparty/zlib/include/refl/detail/uclass.inl @@ -93,7 +93,7 @@ namespace refl { } if constexpr (sizeof...(Args) > 0) { auto ptr = &UList[1]; - (..., (*ptr = &TypeInfo>::StaticClass, ptr++)); + (..., (*ptr = &TypeInfo::StaticClass, ptr++)); } } public: @@ -107,10 +107,6 @@ namespace refl { return cls; } }; - constexpr static std::array IndexNames = { - "1", "2", "3", "4", "5", "6", "7", "8", - "9", "10", "11", "12", "13", "14", "15", "16" - }; template class UClass_Tuple : public UClass { using UClass::UClass; @@ -255,12 +251,12 @@ namespace refl { pit.val = &*it; } static void add(iterator* pit) { - auto it = ++(*(T::iterator*)pit); + auto it = ++(*(typename T::iterator*)pit); memcpy(pit, &it, sizeof(it)); pit->val = &*it; } static void sub(iterator* pit) { - auto it = --(*(T::iterator*)pit); + auto it = --(*(typename T::iterator*)pit); memcpy(pit, &it, sizeof(it)); pit->val = &*it; } diff --git a/engine/3rdparty/zlib/include/refl/detail/view.h b/engine/3rdparty/zlib/include/refl/detail/view.h index ba9fc38..b4678e0 100644 --- a/engine/3rdparty/zlib/include/refl/detail/view.h +++ b/engine/3rdparty/zlib/include/refl/detail/view.h @@ -12,6 +12,8 @@ namespace refl { int Size(); const sarray ToSArray(); constexpr static Offset GetArgsSize(const sarray& args, const sarray& params); + template + consteval static Offset GetArgsSize(const sarray& args); }; class AnyView : public Any{ public: diff --git a/engine/3rdparty/zlib/include/refl/detail/view.inl b/engine/3rdparty/zlib/include/refl/detail/view.inl index 0458939..e5f8e3a 100644 --- a/engine/3rdparty/zlib/include/refl/detail/view.inl +++ b/engine/3rdparty/zlib/include/refl/detail/view.inl @@ -128,6 +128,18 @@ namespace refl { } return offset; } + template + inline consteval Offset AnyArgs::GetArgsSize(const sarray& args) + { + constexpr int N = sizeof...(Args); + if (args.size() == 0 || N < args.size() + 1) { + return 0; + } + int first = N - args.size(); + Offset offset = args.size() * sizeof(Any); + offset += fetch_tuple_size>(std::index_sequence_for{}, first); + return 0; + } template inline bool AnyView::Get(const Name& name, T& t) { diff --git a/engine/3rdparty/zlib/include/refl/macro.h b/engine/3rdparty/zlib/include/refl/macro.h index 084e7cb..db7cd67 100644 --- a/engine/3rdparty/zlib/include/refl/macro.h +++ b/engine/3rdparty/zlib/include/refl/macro.h @@ -26,6 +26,14 @@ #define USING_OVERLOAD_CTOR(Class, ...) using USING_CTOR_NAME = Class(*)(__VA_ARGS__); #define USING_OVERLOAD_FUNC(R, ...) using USING_FUNC_NAME = R(*)(__VA_ARGS__); #define USING_OVERLOAD_CLASS_FUNC(R, Class, ...) using USING_FUNC_NAME = R(Class::*)(__VA_ARGS__); + +/* +struct vec3{ + USING_OVERLOAD_CTOR(vec3) + UFUNCTION({},ref = USING_CTOR_NAME) + vec3(){} +} +*/ namespace refl_impl { struct Meta {}; struct vkMeta {}; diff --git a/engine/3rdparty/zlib/include/refl/refl.h b/engine/3rdparty/zlib/include/refl/refl.h index acca9e8..bd4dc2b 100644 --- a/engine/3rdparty/zlib/include/refl/refl.h +++ b/engine/3rdparty/zlib/include/refl/refl.h @@ -8,15 +8,14 @@ #include "macro.h" namespace refl { template - consteval FieldPtr StaticCtorField(const MethodData& data = {}) { + consteval FieldPtr StaticCtorField(T(*ptr)(Args...), const MethodData& data = {}) { uint32_t flag = FIELD_CTOR_FLAG; - auto cls = &TypeInfo...)>::StaticClass; - Offset offset = AnyArgs::GetArgsSize(data.value, cls->GetParams()); + Offset offset = AnyArgs::GetArgsSize(data.value); if (data.meta.IsValid()) { offset += data.meta.Size(); } FieldPtr::Data method(offset); - return {FName("Ctor"),cls,method, flag}; + return {FName("Ctor"), nullptr, method, flag}; } template consteval FieldPtr StaticMemberField(T Obj::* ptr, const Name& name, const MemberData& data = {}) { @@ -26,39 +25,36 @@ namespace refl { } FieldPtr::Data member(offset); uint32_t flag = FIELD_MEMBER_FLAG | FIELD_ATTRIBUTE_FLAG; - return { name,&TypeInfo::StaticClass, member,flag}; + return { name, nullptr , member , flag}; } template consteval FieldPtr StaticMethodField(R(*ptr)(Args...), const Name& name, const MethodData& data = {}) { uint32_t flag = FIELD_METHOD_FLAG; - auto cls = &TypeInfo(*)(real_type_t...)>::StaticClass; - Offset offset = AnyArgs::GetArgsSize(data.value, cls->GetParams()); + Offset offset = AnyArgs::GetArgsSize(data.value); if (data.meta.IsValid()) { offset += data.meta.Size(); } FieldPtr::Data method(offset); - return { name,cls,method, flag }; + return { name,nullptr,method, flag }; } template consteval FieldPtr StaticMethodField(R(T::* ptr)(Args...), const Name& name, const MethodData& data = {}) { uint32_t flag = FIELD_MEMBER_FLAG | FIELD_METHOD_FLAG; - auto cls = &TypeInfo(*)(const void*, real_type_t...)>::StaticClass; - Offset offset = AnyArgs::GetArgsSize(data.value, cls->GetParams()); + Offset offset = AnyArgs::GetArgsSize(data.value); if (data.meta.IsValid()) { offset += data.meta.Size(); } FieldPtr::Data method(offset); - return { name, cls,method,flag }; + return { name, nullptr,method,flag }; } template consteval FieldPtr StaticMethodField(R(T::* ptr)(Args...)const, const Name& name, const MethodData& data = {}) { uint32_t flag = FIELD_MEMBER_FLAG | FIELD_METHOD_FLAG; - auto cls = &TypeInfo(*)(const void*, real_type_t...)>::StaticClass; - Offset offset = AnyArgs::GetArgsSize(data.value, cls->GetParams()); + Offset offset = AnyArgs::GetArgsSize(data.value); if (data.meta.IsValid()) { offset += data.meta.Size(); } FieldPtr::Data method(offset); - return { name, cls,method,flag }; + return { name, nullptr, method,flag }; } } \ No newline at end of file diff --git a/engine/3rdparty/zlib/test/refl/vertex.cpp b/engine/3rdparty/zlib/test/refl/vertex.cpp index a649f17..fce28d3 100644 --- a/engine/3rdparty/zlib/test/refl/vertex.cpp +++ b/engine/3rdparty/zlib/test/refl/vertex.cpp @@ -1 +1,3 @@ -#include "vertex.h" \ No newline at end of file +#include "vertex.h" +#include "vkmeta_vertex_gen.inl" +#include "dxmeta_vertex_gen.inl" \ No newline at end of file diff --git a/engine/3rdparty/zlib/test/refl/vertex.h b/engine/3rdparty/zlib/test/refl/vertex.h index e4ffd19..21b3908 100644 --- a/engine/3rdparty/zlib/test/refl/vertex.h +++ b/engine/3rdparty/zlib/test/refl/vertex.h @@ -18,14 +18,20 @@ struct vec3 : public vec3_parent { uint32_t z = 3; UPROPERTY({ "hello meta"}) string name = "???a"; - UFUNCTION({}) + USING_OVERLOAD_CTOR(vec3) + UFUNCTION({},ref = USING_CTOR_NAME) vec3() { } - UFUNCTION({1, 2.f, 3.f}) + USING_OVERLOAD_CTOR(vec3,float, int , uint32_t) + UFUNCTION({1, 2.f, 3.f}, ref = USING_CTOR_NAME) vec3(float x1, int y1, uint32_t z1) { x = x1; y = y1; z = z1; } + UFUNCTION() + vec3 make() { + return vec3{}; + } }; #include "vertex_gen.inl" \ No newline at end of file diff --git a/engine/3rdparty/zlib/test/yaml/guid.h b/engine/3rdparty/zlib/test/yaml/guid.h index f5e8a86..95871b6 100644 --- a/engine/3rdparty/zlib/test/yaml/guid.h +++ b/engine/3rdparty/zlib/test/yaml/guid.h @@ -7,7 +7,7 @@ using std::vector; struct Guid { using MyMeta = class Guid_Meta; - UPROPERTY({}) + UPROPERTY({1}) unsigned int Data1; UPROPERTY({}) unsigned short Data2; @@ -59,9 +59,6 @@ struct Guid return std::string{ guid_cstr }; } UFUNCTION({}) - bool test(int a, float* b, char** c){ - return false; - } static Guid Make() { Guid guid; diff --git a/engine/src/engine/render/meta/vertex.h b/engine/src/engine/render/meta/vertex.h index 063b5da..27d0e45 100644 --- a/engine/src/engine/render/meta/vertex.h +++ b/engine/src/engine/render/meta/vertex.h @@ -38,5 +38,4 @@ namespace engineapi { void AddBoneData(uint32_t boneID, float weight); }; }; - #include "vertex_gen.inl" \ No newline at end of file diff --git a/engine/src/engine/vulkanapi/vulkanapi.cpp b/engine/src/engine/vulkanapi/vulkanapi.cpp index efac88b..1e3381c 100644 --- a/engine/src/engine/vulkanapi/vulkanapi.cpp +++ b/engine/src/engine/vulkanapi/vulkanapi.cpp @@ -12,7 +12,6 @@ #include "wrapper/descriptorpool.h" #include "window.h" #include "zlog.h" -Vector3 vec3; #include "vkmeta_vertex_gen.inl" namespace vulkanapi { RenderVulkanAPI::RenderVulkanAPI() diff --git a/engine/xmake/glsl/xmake.lua b/engine/xmake/glsl/xmake.lua index dcb3535..59d0d4a 100644 --- a/engine/xmake/glsl/xmake.lua +++ b/engine/xmake/glsl/xmake.lua @@ -1,12 +1,12 @@ rule("glsl.env") after_load(function (target) - import("glsl_compiler")(target) + --import("glsl_compiler")(target) end) on_config(function (target) - import("glsl_compiler").compile(target) + --import("glsl_compiler").compile(target) end) -- before load before_build(function (target) - os.cd("$(projectdir)/engine/assets/shader") - os.execv("gen_glsl.bat") + --os.cd("$(projectdir)/engine/assets/shader") + --os.execv("gen_glsl.bat") end ) \ No newline at end of file