add refl
This commit is contained in:
parent
cadadd934f
commit
6e9c97f36e
8
engine/3rdparty/ubpa/USmallFlat/xmake.lua
vendored
Normal file
8
engine/3rdparty/ubpa/USmallFlat/xmake.lua
vendored
Normal file
@ -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)
|
||||||
7
engine/3rdparty/ubpa/UTemplate/xmake.lua
vendored
Normal file
7
engine/3rdparty/ubpa/UTemplate/xmake.lua
vendored
Normal file
@ -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)
|
||||||
27
engine/3rdparty/zlib/include/refl/field.h
vendored
Normal file
27
engine/3rdparty/zlib/include/refl/field.h
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "UTemplate/Type.hpp"
|
||||||
|
#include <variant>
|
||||||
|
#include <functional>
|
||||||
|
using Ubpa::Name;
|
||||||
|
using Ubpa::type_name;
|
||||||
|
namespace refl {
|
||||||
|
struct MemberField {
|
||||||
|
uint32_t offset;
|
||||||
|
};
|
||||||
|
struct MemberFuncField {
|
||||||
|
using Offsetor = std::function<void* (void*)>;
|
||||||
|
Offsetor func;
|
||||||
|
};
|
||||||
|
class UClass;
|
||||||
|
struct FieldPtr {
|
||||||
|
using Offsetor = std::function<void* (void*)>;
|
||||||
|
// 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;
|
||||||
|
};
|
||||||
|
}
|
||||||
13
engine/3rdparty/zlib/include/refl/type.h
vendored
Normal file
13
engine/3rdparty/zlib/include/refl/type.h
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <type_traits>
|
||||||
|
namespace refl {
|
||||||
|
template<typename T, typename = void>
|
||||||
|
struct TypeInfo;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct TypeInfo<T, std::void_t<typename T::UClass, decltype(T::UClass::BuildClass())>> {
|
||||||
|
using UClass = typename T::UClass;
|
||||||
|
//这里的特性怎么走不到呢
|
||||||
|
inline static UClass StaticClass = UClass::BuildClass();
|
||||||
|
};
|
||||||
|
}
|
||||||
32
engine/3rdparty/zlib/include/refl/uclass.h
vendored
Normal file
32
engine/3rdparty/zlib/include/refl/uclass.h
vendored
Normal file
@ -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<typename T>
|
||||||
|
constexpr static UClass BuildClass() {
|
||||||
|
return {type_name<T>().View(), sizeof(T)};
|
||||||
|
}
|
||||||
|
protected:
|
||||||
|
template<uint32_t offset, typename T,typename U>
|
||||||
|
FieldPtr MakeMemberField(T U::* ptr, Name name) {
|
||||||
|
FieldPtr::Data member = { offset };
|
||||||
|
return { name, &TypeInfo<T>::StaticClass, {member} };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template<typename T, typename>
|
||||||
|
struct TypeInfo {
|
||||||
|
using UClass = UClass;
|
||||||
|
//这里的语法我也看不懂呀,防警告的,显示声明为模板调用
|
||||||
|
inline constexpr static UClass StaticClass = UClass::template BuildClass<T>();
|
||||||
|
};
|
||||||
|
}
|
||||||
53
engine/3rdparty/zlib/test/refl/vertex.h
vendored
Normal file
53
engine/3rdparty/zlib/test/refl/vertex.h
vendored
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <cstdint>
|
||||||
|
#include <tuple>
|
||||||
|
#include <vector>
|
||||||
|
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<int, int> 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) {};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
40
engine/3rdparty/zlib/test/refl_01.cpp
vendored
Normal file
40
engine/3rdparty/zlib/test/refl_01.cpp
vendored
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <array>
|
||||||
|
#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<FieldPtr,3> FList;
|
||||||
|
constexpr static vec3_UClass BuildClass() {
|
||||||
|
vec3_UClass cls{};
|
||||||
|
cls.name = type_name<vec3>().View();
|
||||||
|
cls.size = sizeof(vec3);
|
||||||
|
//offsetof(vec3, x) 很坑,相当坑
|
||||||
|
cls.FList[0] = cls.MakeMemberField<offsetof(vec3, x)>(&vec3::x, "x");
|
||||||
|
cls.FList[1] = cls.MakeMemberField<offsetof(vec3, y)>(&vec3::y, "y");
|
||||||
|
cls.FList[2] = cls.MakeMemberField<offsetof(vec3, z)>(&vec3::z, "z");
|
||||||
|
return cls;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
using uclass = TypeInfo<vec3>::UClass;
|
||||||
|
auto& res = TypeInfo<int>::StaticClass;
|
||||||
|
auto& res2 = TypeInfo<float>::StaticClass;
|
||||||
|
|
||||||
|
auto& res3 = TypeInfo<vec3>::StaticClass;
|
||||||
|
auto t1 = res3.FList[0];
|
||||||
|
//using t2 = t1::UClass;
|
||||||
|
std::cout << sizeof(Name) << "Type2: " << typeid(vec3).name() << std::endl;
|
||||||
|
cout << "hello world\n";
|
||||||
|
}
|
||||||
19
engine/3rdparty/zlib/xmake.lua
vendored
19
engine/3rdparty/zlib/xmake.lua
vendored
@ -1,6 +1,8 @@
|
|||||||
set_languages("cxx20")
|
set_languages("cxx20")
|
||||||
|
add_requires("UTemplate")
|
||||||
target("zlib")
|
target("zlib")
|
||||||
set_kind("static")
|
set_kind("static")
|
||||||
|
add_packages("UTemplate", {public = true})
|
||||||
add_includedirs("include", {public = true})
|
add_includedirs("include", {public = true})
|
||||||
add_files("src/**/*.cpp")
|
add_files("src/**/*.cpp")
|
||||||
add_headerfiles("include/**/*.h")
|
add_headerfiles("include/**/*.h")
|
||||||
@ -18,12 +20,19 @@ target("zlib_test")
|
|||||||
-- add_deps("zlib")
|
-- add_deps("zlib")
|
||||||
-- add_files("test/02condition.cpp")
|
-- add_files("test/02condition.cpp")
|
||||||
|
|
||||||
target("zlib_test03_semaphore")
|
-- target("zlib_test03_semaphore")
|
||||||
set_kind("binary")
|
-- set_kind("binary")
|
||||||
add_deps("zlib")
|
-- add_deps("zlib")
|
||||||
add_files("test/03semaphore.cpp")
|
-- add_files("test/03semaphore.cpp")
|
||||||
|
|
||||||
-- target("zlib_test04_promise")
|
-- target("zlib_test04_promise")
|
||||||
-- set_kind("binary")
|
-- set_kind("binary")
|
||||||
-- add_deps("zlib")
|
-- add_deps("zlib")
|
||||||
-- add_files("test/04promise.cpp")
|
-- 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")
|
||||||
Loading…
Reference in New Issue
Block a user