refl benchmark
This commit is contained in:
parent
361c6f917d
commit
a79b76c8f4
1
engine/3rdparty/xmake.lua
vendored
1
engine/3rdparty/xmake.lua
vendored
@ -6,3 +6,4 @@ add_requires("vulkansdk")
|
|||||||
add_requires("assimp")
|
add_requires("assimp")
|
||||||
add_requires("nlohmann_json")
|
add_requires("nlohmann_json")
|
||||||
add_requires("ylt")
|
add_requires("ylt")
|
||||||
|
add_requires("benchmark")
|
||||||
@ -42,6 +42,13 @@ namespace refl {
|
|||||||
Data data;
|
Data data;
|
||||||
Default value;
|
Default value;
|
||||||
uint32_t flag;
|
uint32_t flag;
|
||||||
|
|
||||||
|
//safe
|
||||||
|
bool Invoke(std::vector<ArgsView>& ArgsList)const;
|
||||||
|
//unsafe
|
||||||
|
bool Invoke(const std::vector<ArgsView>& ArgsList)const;
|
||||||
|
|
||||||
|
std::vector<const UClass*> GetParams() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
45
engine/3rdparty/zlib/include/refl/detail/field.inl
vendored
Normal file
45
engine/3rdparty/zlib/include/refl/detail/field.inl
vendored
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#include "uclass.h"
|
||||||
|
namespace refl {
|
||||||
|
bool FieldPtr::Invoke(const std::vector<ArgsView>& ArgsList)const{
|
||||||
|
auto Call = type->vtable.Call;
|
||||||
|
if (Call) {
|
||||||
|
Call(this, ArgsList);
|
||||||
|
}
|
||||||
|
return Call;
|
||||||
|
}
|
||||||
|
bool FieldPtr::Invoke(std::vector<ArgsView>& ArgsList)const {
|
||||||
|
auto Call = type->vtable.Call;
|
||||||
|
if (Call) {
|
||||||
|
auto params = GetParams();
|
||||||
|
int paramsSize = params.size();
|
||||||
|
int argsSize = ArgsList.size();
|
||||||
|
if (argsSize < paramsSize && flag & FIELD_METHOD_VALUE_FLAG) {
|
||||||
|
auto [argsPtr, valueSize] = value.method();
|
||||||
|
if (argsSize + valueSize >= paramsSize) {
|
||||||
|
for (int i = valueSize + argsSize - paramsSize; i < valueSize; i++) {
|
||||||
|
ArgsList.push_back(*(argsPtr + i));
|
||||||
|
}
|
||||||
|
argsSize = paramsSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (argsSize < paramsSize) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < paramsSize; i++) {
|
||||||
|
if (ArgsList[i].cls != params[i] && !ArgsList[i].ConvertTo(params[i])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Call(this, ArgsList);
|
||||||
|
}
|
||||||
|
return Call;
|
||||||
|
}
|
||||||
|
std::vector<const UClass*> FieldPtr::GetParams() const {
|
||||||
|
auto GetParams = type->vtable.GetParams;
|
||||||
|
if (GetParams) {
|
||||||
|
return GetParams(type);
|
||||||
|
}
|
||||||
|
return{};
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -10,7 +10,7 @@ namespace refl {
|
|||||||
//function
|
//function
|
||||||
std::vector<const UClass*>(*GetParams)(const UClass*);
|
std::vector<const UClass*>(*GetParams)(const UClass*);
|
||||||
//function
|
//function
|
||||||
void (*Call)(const FieldPtr&, std::vector<ArgsView>&);
|
void (*Call)(const FieldPtr*, const std::vector<ArgsView>&);
|
||||||
|
|
||||||
//object
|
//object
|
||||||
void (*InitObject)(void*);
|
void (*InitObject)(void*);
|
||||||
@ -78,17 +78,6 @@ namespace refl {
|
|||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
std::vector<const UClass*> GetParams() const {
|
|
||||||
if (vtable.GetParams) {
|
|
||||||
return vtable.GetParams(this);
|
|
||||||
}
|
|
||||||
return{};
|
|
||||||
}
|
|
||||||
void Call(const FieldPtr& field, std::vector<ArgsView>& ArgsList)const{
|
|
||||||
if (vtable.Call) {
|
|
||||||
return vtable.Call(field, ArgsList);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void InitObject(void* ptr)const {
|
void InitObject(void* ptr)const {
|
||||||
if (vtable.InitObject) {
|
if (vtable.InitObject) {
|
||||||
vtable.InitObject(ptr);
|
vtable.InitObject(ptr);
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <array>
|
||||||
#include "uclass.h"
|
#include "uclass.h"
|
||||||
namespace refl {
|
namespace refl {
|
||||||
template<_ReflCheck_Ctor T>
|
template<_ReflCheck_Ctor T>
|
||||||
@ -35,14 +36,14 @@ namespace refl {
|
|||||||
auto& UList = static_cast<const MyUClass*>(cls)->UList;
|
auto& UList = static_cast<const MyUClass*>(cls)->UList;
|
||||||
return { UList.data(), UList.data() + UList.size() };
|
return { UList.data(), UList.data() + UList.size() };
|
||||||
}
|
}
|
||||||
static void Call(const FieldPtr& field, std::vector<ArgsView>& ArgsList) {
|
static void Call(const FieldPtr* field, const std::vector<ArgsView>& ArgsList) {
|
||||||
if constexpr (std::is_same_v<R, void>) {
|
if constexpr (std::is_same_v<R, void>) {
|
||||||
MethodType fptr = (MethodType)field.data.method;
|
MethodType fptr = (MethodType)field->data.method;
|
||||||
auto param = ArgsList.rbegin();
|
auto param = ArgsList.rbegin();
|
||||||
fptr(param++->cast_to<Args>()...);
|
fptr(param++->cast_to<Args>()...);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
MethodType fptr = (MethodType)field.data.method;
|
MethodType fptr = (MethodType)field->data.method;
|
||||||
auto param = ArgsList.rbegin();
|
auto param = ArgsList.rbegin();
|
||||||
auto ret = ArgsList.begin();
|
auto ret = ArgsList.begin();
|
||||||
if (ret->cls == &TypeInfo<R*>::StaticClass) {
|
if (ret->cls == &TypeInfo<R*>::StaticClass) {
|
||||||
|
|||||||
54
engine/3rdparty/zlib/include/refl/detail/view.h
vendored
54
engine/3rdparty/zlib/include/refl/detail/view.h
vendored
@ -4,46 +4,28 @@
|
|||||||
namespace refl {
|
namespace refl {
|
||||||
class UClass;
|
class UClass;
|
||||||
class FieldPtr;
|
class FieldPtr;
|
||||||
class ObjectView {
|
|
||||||
public:
|
|
||||||
const char* ptr;
|
|
||||||
const UClass* cls;
|
|
||||||
const FieldPtr* cache{nullptr};
|
|
||||||
ObjectView(const void* ptr, const UClass* cls) : ptr((const char*)ptr), cls(cls){}
|
|
||||||
public:
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
bool Get(const Name& name, T& t);
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
bool Set(const Name& name, const T& t);
|
|
||||||
|
|
||||||
template<typename ...Args>
|
|
||||||
bool Invoke(const Name& name, Args&&... args);
|
|
||||||
|
|
||||||
template<typename R, typename ...Args>
|
|
||||||
R Invoke(const Name& name, Args&&... args);
|
|
||||||
|
|
||||||
ObjectView Parent();
|
|
||||||
};
|
|
||||||
//生命周期短,适用于传参,不建议保存数据
|
//生命周期短,适用于传参,不建议保存数据
|
||||||
//只能指向指针,引用=>指针,指针=>指针,T => T*,T的类型丢失
|
//只能指向指针,引用=>指针,指针=>指针,T => T*,T的类型丢失
|
||||||
struct ArgsView {
|
struct ArgsView {
|
||||||
public:
|
public:
|
||||||
const void* val;
|
const void* val;
|
||||||
const UClass* cls;
|
const UClass* cls;
|
||||||
ArgsView(const void* val = nullptr, const UClass* cls = nullptr) : val(val), cls(cls) {}
|
ArgsView() : val(nullptr), cls(nullptr) {}
|
||||||
//右值=>右值压入栈,caller入栈地址
|
//右值=>右值压入栈,caller入栈地址
|
||||||
//左值=>caller变量地址
|
//左值=>caller变量地址
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ArgsView(T&& v): val(&v), cls(&TypeInfo<args_type_t<T>*>::StaticClass){
|
ArgsView(T&& v): val(&v), cls(&TypeInfo<args_type_t<T>*>::StaticClass){
|
||||||
if constexpr (std::is_same_v<args_type_t<T>, ArgsView>) {
|
if constexpr (std::is_same_v<args_type_t<T>, void*>) {
|
||||||
|
val = v;
|
||||||
|
cls = &TypeInfo<const void*>::StaticClass;
|
||||||
|
}
|
||||||
|
else if constexpr (std::is_same_v<args_type_t<T>, ArgsView>) {
|
||||||
val = v.val;
|
val = v.val;
|
||||||
cls = v.cls;
|
cls = v.cls;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
template<typename T>//参数 T* => T*
|
template<typename T>//参数 T* => T*
|
||||||
constexpr inline T cast_to() {
|
constexpr inline T cast_to() const {
|
||||||
if constexpr (std::is_pointer_v<T>) {
|
if constexpr (std::is_pointer_v<T>) {
|
||||||
return (T)val;
|
return (T)val;
|
||||||
}
|
}
|
||||||
@ -55,7 +37,7 @@ namespace refl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T cast_ret() {
|
T cast_ret() const {
|
||||||
if constexpr (std::is_pointer_v<T>) {
|
if constexpr (std::is_pointer_v<T>) {
|
||||||
return *(T*)val;
|
return *(T*)val;
|
||||||
}
|
}
|
||||||
@ -82,4 +64,24 @@ namespace refl {
|
|||||||
ArgsValueList(const std::vector<ArgsValue>& args);
|
ArgsValueList(const std::vector<ArgsValue>& args);
|
||||||
~ArgsValueList();
|
~ArgsValueList();
|
||||||
};
|
};
|
||||||
|
class ObjectView {
|
||||||
|
public:
|
||||||
|
const char* ptr;
|
||||||
|
const UClass* cls;
|
||||||
|
const FieldPtr* cache{ nullptr };
|
||||||
|
ObjectView(const void* ptr, const UClass* cls) : ptr((const char*)ptr), cls(cls) {}
|
||||||
|
public:
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
bool Get(const Name& name, T& t);
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
bool Set(const Name& name, const T& t);
|
||||||
|
|
||||||
|
bool Invoke(const Name& name,const std::vector<ArgsView>& ArgsList);//这里是内存分配慢呀,这里是可以改成栈容器的
|
||||||
|
|
||||||
|
bool Invoke(const Name& name,std::vector<ArgsView>& ArgsList);
|
||||||
|
|
||||||
|
ObjectView Parent();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
206
engine/3rdparty/zlib/include/refl/detail/view.inl
vendored
206
engine/3rdparty/zlib/include/refl/detail/view.inl
vendored
@ -1,146 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "uclass.h"
|
#include "uclass.h"
|
||||||
|
#include "view.h"
|
||||||
namespace refl {
|
namespace refl {
|
||||||
template<typename T>
|
|
||||||
inline bool ObjectView::Get(const Name& name, T& t)
|
|
||||||
{
|
|
||||||
if (cache && cache->name == name) {
|
|
||||||
_cache_get: bool isChild = cache->type->IsChildOf<T>(true);
|
|
||||||
if (isChild) {
|
|
||||||
t = *(T*)(ptr + cache->data.offset);
|
|
||||||
}
|
|
||||||
return isChild;
|
|
||||||
}
|
|
||||||
auto field = cls->GetField(name, false);
|
|
||||||
if (field) {
|
|
||||||
cache = field;
|
|
||||||
goto _cache_get;
|
|
||||||
}
|
|
||||||
if (cls->parent) {
|
|
||||||
return Parent().Get(name, t);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
template<typename T>
|
|
||||||
inline bool ObjectView::Set(const Name& name, const T& t)
|
|
||||||
{
|
|
||||||
if (cache && cache->name == name) {
|
|
||||||
_cache_set: bool isChild = cache->type->IsChildOf<T>(true);
|
|
||||||
if (isChild) {
|
|
||||||
*(T*)(ptr + cache->data.offset) = t;
|
|
||||||
}
|
|
||||||
return isChild;
|
|
||||||
}
|
|
||||||
auto field = cls->GetField(name, false);
|
|
||||||
if (field) {
|
|
||||||
cache = field;
|
|
||||||
goto _cache_set;
|
|
||||||
}
|
|
||||||
if (cls->parent) {
|
|
||||||
return Parent().Set(name, t);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
template<typename ...Args>
|
|
||||||
bool ObjectView::Invoke(const Name& name, Args&&... args)
|
|
||||||
{
|
|
||||||
auto field = cls->GetField(name, true);
|
|
||||||
if (!field) {
|
|
||||||
if (cls->parent) {
|
|
||||||
return Parent().Invoke(name, args...);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
constexpr int inputSize = sizeof...(Args);
|
|
||||||
auto params = field->type->GetParams();
|
|
||||||
int paramsSize = params.size();
|
|
||||||
|
|
||||||
std::vector<ArgsView> ArgsList;
|
|
||||||
ArgsList.reserve(paramsSize);
|
|
||||||
ArgsList.emplace_back();
|
|
||||||
|
|
||||||
bool member = field->flag & FIELD_MEMBER_FLAG;
|
|
||||||
if (member) {
|
|
||||||
ArgsList.emplace_back(ptr, &TypeInfo<const void*>::StaticClass);
|
|
||||||
}
|
|
||||||
(..., (ArgsList.emplace_back(args)));
|
|
||||||
|
|
||||||
|
|
||||||
int argsSize = ArgsList.size();
|
|
||||||
if (argsSize < paramsSize && field->flag & FIELD_METHOD_VALUE_FLAG) {
|
|
||||||
auto [argsPtr, valueSize] = field->value.method();
|
|
||||||
if (argsSize + valueSize >= paramsSize) {
|
|
||||||
for (int i = valueSize + argsSize - paramsSize; i < valueSize; i++) {
|
|
||||||
ArgsList.push_back(*(argsPtr + i));
|
|
||||||
}
|
|
||||||
argsSize = paramsSize;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (argsSize < paramsSize) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = member + 1; i < paramsSize; i++) {
|
|
||||||
if (ArgsList[i].cls != params[i] && !ArgsList[i].ConvertTo(params[i])) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
field->type->Call(*field, ArgsList);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
template<typename R, typename ...Args>
|
|
||||||
R ObjectView::Invoke(const Name& name, Args&&... args)
|
|
||||||
{
|
|
||||||
//int x = 1; val = &x; *(int*)val = 2;//(x = 2) return *val; //val=>cast_to<int>
|
|
||||||
//int* x = nullptr; val = &x; *(int**)val = 0xff1234;//(x = 0xff1234) return *val;
|
|
||||||
real_type_t<R> data{};
|
|
||||||
ArgsView ret{ &data, &TypeInfo<real_type_t<R>*>::StaticClass };
|
|
||||||
auto field = cls->GetField(name, true);
|
|
||||||
if (!field) {
|
|
||||||
if (cls->parent) {
|
|
||||||
return Parent().Invoke<R>(name, args...);
|
|
||||||
}
|
|
||||||
return ret.cast_ret<R>();
|
|
||||||
}
|
|
||||||
constexpr int inputSize = sizeof...(Args);
|
|
||||||
auto params = field->type->GetParams();
|
|
||||||
int paramsSize = params.size();
|
|
||||||
std::vector<ArgsView> ArgsList;
|
|
||||||
ArgsList.reserve(paramsSize);
|
|
||||||
ArgsList.emplace_back(ret);
|
|
||||||
|
|
||||||
if (field->flag & FIELD_MEMBER_FLAG) {
|
|
||||||
ArgsList.emplace_back(ptr, &TypeInfo<const void*>::StaticClass);
|
|
||||||
}
|
|
||||||
(..., (ArgsList.emplace_back(args)));
|
|
||||||
|
|
||||||
int argsSize = ArgsList.size();
|
|
||||||
if (argsSize < paramsSize && field->flag & FIELD_METHOD_VALUE_FLAG) {
|
|
||||||
auto [argsPtr, valueSize] = field->value.method();
|
|
||||||
if (argsSize + valueSize >= paramsSize) {
|
|
||||||
for (int i = valueSize + argsSize - paramsSize; i < valueSize; i++) {
|
|
||||||
ArgsList.push_back(*(argsPtr + i));
|
|
||||||
}
|
|
||||||
argsSize = paramsSize;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (argsSize < paramsSize) {
|
|
||||||
return ret.cast_ret<R>();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < paramsSize; i++) {
|
|
||||||
if (ArgsList[i].cls != params[i] && !ArgsList[i].ConvertTo(params[i])) {
|
|
||||||
return ret.cast_ret<R>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
field->type->Call(*field, ArgsList);
|
|
||||||
return ret.cast_ret<R>();
|
|
||||||
}
|
|
||||||
ObjectView ObjectView::Parent() {
|
|
||||||
return { ptr, cls ? cls->parent : nullptr };
|
|
||||||
}
|
|
||||||
/*平凡对象的转化要支持吗
|
/*平凡对象的转化要支持吗
|
||||||
* 比如同大小的安全转化
|
* 比如同大小的安全转化
|
||||||
* 对象从小到大
|
* 对象从小到大
|
||||||
@ -185,4 +46,69 @@ namespace refl {
|
|||||||
num = 0;
|
num = 0;
|
||||||
data = nullptr;
|
data = nullptr;
|
||||||
}
|
}
|
||||||
|
template<typename T>
|
||||||
|
inline bool ObjectView::Get(const Name& name, T& t)
|
||||||
|
{
|
||||||
|
if (cache && cache->name == name) {
|
||||||
|
_cache_get: bool isChild = cache->type->IsChildOf<T>(true);
|
||||||
|
if (isChild) {
|
||||||
|
t = *(T*)(ptr + cache->data.offset);
|
||||||
|
}
|
||||||
|
return isChild;
|
||||||
|
}
|
||||||
|
auto field = cls->GetField(name, false);
|
||||||
|
if (field) {
|
||||||
|
cache = field;
|
||||||
|
goto _cache_get;
|
||||||
|
}
|
||||||
|
if (cls->parent) {
|
||||||
|
return Parent().Get(name, t);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
template<typename T>
|
||||||
|
inline bool ObjectView::Set(const Name& name, const T& t)
|
||||||
|
{
|
||||||
|
if (cache && cache->name == name) {
|
||||||
|
_cache_set: bool isChild = cache->type->IsChildOf<T>(true);
|
||||||
|
if (isChild) {
|
||||||
|
*(T*)(ptr + cache->data.offset) = t;
|
||||||
|
}
|
||||||
|
return isChild;
|
||||||
|
}
|
||||||
|
auto field = cls->GetField(name, false);
|
||||||
|
if (field) {
|
||||||
|
cache = field;
|
||||||
|
goto _cache_set;
|
||||||
|
}
|
||||||
|
if (cls->parent) {
|
||||||
|
return Parent().Set(name, t);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool ObjectView::Invoke(const Name& name,const std::vector<ArgsView>& ArgsList)
|
||||||
|
{
|
||||||
|
auto field = cls->GetField(name, true);
|
||||||
|
if (!field) {
|
||||||
|
if (cls->parent) {
|
||||||
|
return Parent().Invoke(name, ArgsList);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return field->Invoke(ArgsList);
|
||||||
|
}
|
||||||
|
bool ObjectView::Invoke(const Name& name, std::vector<ArgsView>& ArgsList)
|
||||||
|
{
|
||||||
|
auto field = cls->GetField(name, true);
|
||||||
|
if (!field) {
|
||||||
|
if (cls->parent) {
|
||||||
|
return Parent().Invoke(name, ArgsList);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return field->Invoke(ArgsList);
|
||||||
|
}
|
||||||
|
ObjectView ObjectView::Parent() {
|
||||||
|
return { ptr, cls ? cls->parent : nullptr };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
1
engine/3rdparty/zlib/include/refl/refl.h
vendored
1
engine/3rdparty/zlib/include/refl/refl.h
vendored
@ -1,5 +1,6 @@
|
|||||||
#include "detail/uclass.inl"
|
#include "detail/uclass.inl"
|
||||||
#include "detail/view.inl"
|
#include "detail/view.inl"
|
||||||
|
#include "detail/field.inl"
|
||||||
namespace refl {
|
namespace refl {
|
||||||
/* 成员变量需要定义默认值吗?那为什么不在initObjec里初始化?*/
|
/* 成员变量需要定义默认值吗?那为什么不在initObjec里初始化?*/
|
||||||
template<typename T, typename Obj>
|
template<typename T, typename Obj>
|
||||||
|
|||||||
92
engine/3rdparty/zlib/test/refl/vertex.h
vendored
92
engine/3rdparty/zlib/test/refl/vertex.h
vendored
@ -1,53 +1,47 @@
|
|||||||
#pragma once
|
#include <iostream>
|
||||||
#include <cstdint>
|
#include "refl/refl.h"
|
||||||
#include <tuple>
|
|
||||||
#include <vector>
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
#define sizeof_field(_struct, _field) sizeof(((_struct*)0)->_field)
|
using namespace refl;
|
||||||
// 顶点最多关联4个骨骼
|
struct vec3_parent {
|
||||||
#define MAX_NUM_BONES_PER_VERTEX 4
|
virtual void norm(int x1, int& x2) {
|
||||||
struct Vector2 {
|
x2 = x1 * x2;
|
||||||
float x;
|
//cout << x2 << "vec3_parent::norm" << endl;
|
||||||
float y;
|
}
|
||||||
};
|
};
|
||||||
struct Vector3 {
|
struct vec3 : public vec3_parent {
|
||||||
float x;
|
float x = 1;
|
||||||
float y;
|
float y = 2;
|
||||||
float z;
|
float z = 3;
|
||||||
|
string name{ "hellohellohellohellohellohello" };
|
||||||
|
void norm(int x1, int& x2)override {
|
||||||
|
//x2 = x1 * x2;
|
||||||
|
//cout << x2 << "vec3::norm" << endl;
|
||||||
|
}
|
||||||
|
virtual float norm1(int& x1) {
|
||||||
|
//x1 = x1 * x * y * z;
|
||||||
|
//x = x1;
|
||||||
|
//y = x1 - 1;
|
||||||
|
//z = x1 - 10;
|
||||||
|
//cout << x1 << "::norm1" << endl;
|
||||||
|
return x1;
|
||||||
|
}
|
||||||
|
static void norm2(int x1 = 10) {
|
||||||
|
//cout << x1 << "::norm2" << endl;
|
||||||
|
}
|
||||||
|
static void norm3(int x1 = 10) {
|
||||||
|
x1 = x1 * 10;
|
||||||
|
//cout << x1 << "::norm3" << endl;
|
||||||
|
}
|
||||||
|
using MyUClass = UClass_Custom;
|
||||||
|
static void BuildClass(MyUClass& cls) {
|
||||||
|
cls.parent = &TypeInfo<vec3_parent>::StaticClass;
|
||||||
|
cls.AttrNum = 3;
|
||||||
|
cls.FList = {
|
||||||
|
MakeMemberField(&vec3::x, "x"),
|
||||||
|
MakeMemberField(&vec3::y, "y"),
|
||||||
|
MakeMemberField(&vec3::z, "z"),
|
||||||
|
MakeMethodField(&vec3::norm, "norm", {8, 9}),
|
||||||
|
MakeMethodField(&vec3::norm1, "norm1",{(float)2.0})
|
||||||
};
|
};
|
||||||
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) {};
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
132
engine/3rdparty/zlib/test/refl_01.cpp
vendored
132
engine/3rdparty/zlib/test/refl_01.cpp
vendored
@ -1,96 +1,40 @@
|
|||||||
#include <iostream>
|
#include "refl/vertex.h"
|
||||||
#include <array>
|
#include <benchmark/benchmark.h>
|
||||||
#include "refl/refl.h"
|
void TestRefl1(benchmark::State& state) {
|
||||||
#include "vertex.h"
|
|
||||||
#include "tstring.h"
|
|
||||||
#include <functional>
|
|
||||||
using namespace std;
|
|
||||||
using namespace refl;
|
|
||||||
struct vec3_parent {
|
|
||||||
virtual void norm(int x1, int& x2) {
|
|
||||||
x2 = x1 * x2;
|
|
||||||
cout << x2 << "vec3_parent::norm" << endl;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
struct vec3 : public vec3_parent {
|
|
||||||
float x = 1;
|
|
||||||
float y = 2;
|
|
||||||
float z = 3;
|
|
||||||
string name{ "hellohellohellohellohellohello" };
|
|
||||||
void norm(int x1, int& x2)override {
|
|
||||||
x2 = x1 * x2;
|
|
||||||
cout << x2 << "vec3::norm" << endl;
|
|
||||||
}
|
|
||||||
virtual float norm1(float& x1) {
|
|
||||||
cout << x1 << "::norm1" << endl;
|
|
||||||
return x1;
|
|
||||||
}
|
|
||||||
static void norm2(int x1 = 10) {
|
|
||||||
cout << x1 << "::norm2" << endl;
|
|
||||||
}
|
|
||||||
static void norm3(int x1 = 10) {
|
|
||||||
x1 = x1 * 10;
|
|
||||||
cout << x1 << "::norm3" << endl;
|
|
||||||
}
|
|
||||||
using MyUClass = UClass_Custom;
|
|
||||||
static void BuildClass(MyUClass& cls) {
|
|
||||||
cls.parent = &TypeInfo<vec3_parent>::StaticClass;
|
|
||||||
cls.AttrNum = 3;
|
|
||||||
cls.FList = {
|
|
||||||
MakeMemberField(&vec3::x, "x"),
|
|
||||||
MakeMemberField(&vec3::y, "y"),
|
|
||||||
MakeMemberField(&vec3::z, "z"),
|
|
||||||
MakeMethodField(&vec3::norm, "norm", {8, 9}),
|
|
||||||
MakeMethodField(&vec3::norm1, "norm1",{(float)2.0})
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
int main() {
|
|
||||||
{
|
|
||||||
//T = > T*
|
|
||||||
int x = 1;
|
|
||||||
auto val = &x;
|
|
||||||
//T* = > T
|
|
||||||
//*val;
|
|
||||||
//x = 2;
|
|
||||||
*val = 2;
|
|
||||||
}
|
|
||||||
{
|
|
||||||
//T* = > T*
|
|
||||||
int x = 1, y = 2;
|
|
||||||
int* px = &x;
|
|
||||||
auto val = px;
|
|
||||||
//T* => T*
|
|
||||||
//val;
|
|
||||||
//px = &y;//做不到哈
|
|
||||||
val = &y;
|
|
||||||
|
|
||||||
}
|
|
||||||
{
|
|
||||||
//T* => T**
|
|
||||||
int x = 1, y = 2;
|
|
||||||
int* px = &x;
|
|
||||||
auto val = &px;
|
|
||||||
//T** = > T*;
|
|
||||||
//*val;
|
|
||||||
//px = &y;
|
|
||||||
*val = &y;
|
|
||||||
}
|
|
||||||
auto cls = &TypeInfo<vec3>::StaticClass;
|
auto cls = &TypeInfo<vec3>::StaticClass;
|
||||||
int x = 2, y = 3;
|
vec3 v;
|
||||||
int* q1;
|
auto ptr = (void*)&v;
|
||||||
void* q2 = &q1;
|
auto ov = cls->New(ptr);
|
||||||
*(int**)q2 = &x;
|
int x = 1, y = 2;
|
||||||
ArgsView a(&y);
|
for (auto _ : state) {
|
||||||
ArgsView b(x);
|
ov.Invoke("norm", { {},ptr, x, y});
|
||||||
ArgsView c(&q1);
|
|
||||||
auto ov = cls->New();
|
|
||||||
ov.Invoke("norm", x);
|
|
||||||
ov.Invoke("norm", x);
|
|
||||||
ov.Invoke("norm", x, y);
|
|
||||||
auto f = ov.Invoke<float>("norm1");
|
|
||||||
vec3* v = (vec3*)ov.ptr;
|
|
||||||
ov.Invoke("norm1", (float)y);
|
|
||||||
delete v;
|
|
||||||
cout << "hello world\n";
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
BENCHMARK(TestRefl1);
|
||||||
|
void TestRefl2(benchmark::State& state) {
|
||||||
|
auto cls = &TypeInfo<vec3>::StaticClass;
|
||||||
|
vec3 v;
|
||||||
|
auto ptr = (void*)&v;
|
||||||
|
auto ov = cls->New(ptr);
|
||||||
|
int x = 1, y = 2;
|
||||||
|
std::vector<ArgsView> ArgsList;
|
||||||
|
ArgsList.emplace_back();
|
||||||
|
ArgsList.emplace_back(ptr);
|
||||||
|
ArgsList.emplace_back(x);
|
||||||
|
ArgsList.emplace_back(y);
|
||||||
|
auto field = cls->GetField(cls, "norm", true);
|
||||||
|
for (auto _ : state) {
|
||||||
|
field->Invoke(ArgsList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BENCHMARK(TestRefl2);
|
||||||
|
void TestCPlusPlus(benchmark::State& state) {
|
||||||
|
vec3 v;
|
||||||
|
int x = 1, y = 2;
|
||||||
|
for (auto _ : state) {
|
||||||
|
v.norm(x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BENCHMARK(TestCPlusPlus);
|
||||||
|
|
||||||
|
BENCHMARK_MAIN();
|
||||||
|
|||||||
1
engine/3rdparty/zlib/xmake.lua
vendored
1
engine/3rdparty/zlib/xmake.lua
vendored
@ -33,6 +33,7 @@ target("zlib_test")
|
|||||||
target("refl_zlib")
|
target("refl_zlib")
|
||||||
set_kind("binary")
|
set_kind("binary")
|
||||||
add_deps("zlib")
|
add_deps("zlib")
|
||||||
|
add_packages("benchmark")
|
||||||
add_includedirs("test/refl")
|
add_includedirs("test/refl")
|
||||||
add_files("test/refl_01.cpp")
|
add_files("test/refl_01.cpp")
|
||||||
add_headerfiles("test/refl/*.h")
|
add_headerfiles("test/refl/*.h")
|
||||||
Loading…
Reference in New Issue
Block a user