99 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
		
		
			
		
	
	
			99 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| 
								 | 
							
								#include <iostream>
							 | 
						||
| 
								 | 
							
								#include <array>
							 | 
						||
| 
								 | 
							
								#include "refl/uclass.h"
							 | 
						||
| 
								 | 
							
								#include "vertex.h"
							 | 
						||
| 
								 | 
							
								#include "tstring.h"
							 | 
						||
| 
								 | 
							
								#include <functional>
							 | 
						||
| 
								 | 
							
								using namespace std;
							 | 
						||
| 
								 | 
							
								using namespace refl;
							 | 
						||
| 
								 | 
							
								struct vec3_parent {
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								};
							 | 
						||
| 
								 | 
							
								struct vec3 : public vec3_parent {
							 | 
						||
| 
								 | 
							
									using UClass = class vec3_UClass;
							 | 
						||
| 
								 | 
							
									float x = 1;
							 | 
						||
| 
								 | 
							
									float y = 2;
							 | 
						||
| 
								 | 
							
									float z = 3;
							 | 
						||
| 
								 | 
							
									string name{ "hellohellohellohellohellohello" };
							 | 
						||
| 
								 | 
							
									void norm(int x1, int& x2) {
							 | 
						||
| 
								 | 
							
										x2 = x1 * x * y * z * x2;
							 | 
						||
| 
								 | 
							
										cout << x2 << "::norm" << endl;
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
									virtual float norm1(int x1 = 10) {
							 | 
						||
| 
								 | 
							
										cout << x1 << "::norm1" << endl;
							 | 
						||
| 
								 | 
							
										return x * y *z * x1;
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
									static void norm2(int x1 = 10) {
							 | 
						||
| 
								 | 
							
										cout << x1 << "::norm2" << endl;
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
									void norm3(int x1 = 10) {
							 | 
						||
| 
								 | 
							
										x1 = x * y * z;
							 | 
						||
| 
								 | 
							
										cout << x1 << "::norm3" << endl;
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								};
							 | 
						||
| 
								 | 
							
								struct vec3_UClass : public UClass {
							 | 
						||
| 
								 | 
							
								public:
							 | 
						||
| 
								 | 
							
									array<FieldPtr,6> FList;
							 | 
						||
| 
								 | 
							
									using UClass::UClass;
							 | 
						||
| 
								 | 
							
									const FieldPtr* GetField(const Name& name)const override {
							 | 
						||
| 
								 | 
							
										for (auto& field : FList) {
							 | 
						||
| 
								 | 
							
											if (field.name == name) {
							 | 
						||
| 
								 | 
							
												return &field;
							 | 
						||
| 
								 | 
							
											}
							 | 
						||
| 
								 | 
							
										}
							 | 
						||
| 
								 | 
							
										return nullptr;
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
									void InitObject(void* ptr)const override {
							 | 
						||
| 
								 | 
							
										vec3 obj{};
							 | 
						||
| 
								 | 
							
										std::construct_at((vec3*)ptr, obj);
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
									static vec3_UClass BuildClass() {
							 | 
						||
| 
								 | 
							
										vec3_UClass cls(type_name<vec3>().View(), sizeof(vec3), &TypeInfo<vec3_parent>::StaticClass);
							 | 
						||
| 
								 | 
							
										//offsetof(vec3, x) 很坑,相当坑
							 | 
						||
| 
								 | 
							
										cls.FList[0] = cls.MakeMemberField<float, offsetof(vec3, x)>("x");
							 | 
						||
| 
								 | 
							
										cls.FList[1] = cls.MakeMemberField<float, offsetof(vec3, y)>("y");
							 | 
						||
| 
								 | 
							
										cls.FList[2] = cls.MakeMemberField<float, offsetof(vec3, z)>("z");
							 | 
						||
| 
								 | 
							
										cls.FList[3] = cls.MakeMethodField(&vec3::norm,  "norm");
							 | 
						||
| 
								 | 
							
										//cls.FList[4] = cls.MakeMethodField(&vec3::norm1, "norm1");
							 | 
						||
| 
								 | 
							
										//cls.FList[5] = cls.MakeMethodField(&vec3::norm2, "norm2");
							 | 
						||
| 
								 | 
							
										return cls;
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								};
							 | 
						||
| 
								 | 
							
								template<typename ...Args>
							 | 
						||
| 
								 | 
							
								void printt(void* ptr, std::vector<ArgsView>& ArgsList) {
							 | 
						||
| 
								 | 
							
									using MethodType = void (*)(Args...);
							 | 
						||
| 
								 | 
							
									MethodType fptr = (MethodType)ptr;
							 | 
						||
| 
								 | 
							
									{
							 | 
						||
| 
								 | 
							
										auto param = ArgsList.rbegin();
							 | 
						||
| 
								 | 
							
										fptr((Args)param++->val...);
							 | 
						||
| 
								 | 
							
										//fptr((Args)param++->val...);
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
									{
							 | 
						||
| 
								 | 
							
										auto param = ArgsList.begin();
							 | 
						||
| 
								 | 
							
										auto val1 = (++param)->val;
							 | 
						||
| 
								 | 
							
										auto val2 = (++param)->val;
							 | 
						||
| 
								 | 
							
										auto val3 = (++param)->val;
							 | 
						||
| 
								 | 
							
										fptr((void *)val1, (int)val2, (int*)val3);
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
									//fptr((++param)->val, (int)(++param)->val, (int&)(++param)->val);
							 | 
						||
| 
								 | 
							
									//fptr(std::forward<Args>((Args)(++param)->val)...);
							 | 
						||
| 
								 | 
							
									int x = 1;
							 | 
						||
| 
								 | 
							
									x = x + 1;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								int main() {
							 | 
						||
| 
								 | 
							
									auto cls = &TypeInfo<vec3>::StaticClass;
							 | 
						||
| 
								 | 
							
								 	vec3 v;
							 | 
						||
| 
								 | 
							
									int x = 1, y = 2;
							 | 
						||
| 
								 | 
							
									std::vector<ArgsView> ArgsList;
							 | 
						||
| 
								 | 
							
									ArgsList.emplace_back();
							 | 
						||
| 
								 | 
							
									ArgsList.emplace_back(&v);
							 | 
						||
| 
								 | 
							
									ArgsList.emplace_back(x);
							 | 
						||
| 
								 | 
							
									ArgsList.emplace_back(&y);
							 | 
						||
| 
								 | 
							
									auto ptr1 = &vec3::norm;
							 | 
						||
| 
								 | 
							
									using MethodType = void (*)(void*, int, int&);
							 | 
						||
| 
								 | 
							
									MethodType ptr2 = *(MethodType*)&ptr1;
							 | 
						||
| 
								 | 
							
									//ptr2(&v, x , y);
							 | 
						||
| 
								 | 
							
									printt<const void*, int , int*>(*(void**)&ptr1, ArgsList);
							 | 
						||
| 
								 | 
							
									//ptr2(x, y);
							 | 
						||
| 
								 | 
							
									//cout << "hello world\n";
							 | 
						||
| 
								 | 
							
								}
							 |