ShitEngine 1.4.2
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
载入中...
搜索中...
未找到
TypeInfo.h
浏览该文件的文档.
1#pragma once
2
3#include <string>
4#include <vector>
5#include <typeindex>
6#include <functional>
7#include <cstring>
8
9namespace Shit {
10
12struct RangeMeta {
13 float min = 0.0f;
14 float max = 0.0f;
15};
16
17struct FieldMeta {
18 std::string displayName;
19 std::string tooltip;
21 float step = 0.0f;
22 std::string category;
23 bool readOnly = false;
24 std::string unit;
25};
26
27struct FieldInfo {
28 std::string name;
29 size_t offset = 0;
30 size_t size = 0;
31 std::string typeName;
32 std::vector<FieldMeta> meta;
33
34 // ── P20: 组件引用字段(ComponentRef<T>)──
35 // refType 非空时本字段是"组件引用":字段内存放目标组件的持久 UUID(8 字节),
36 // 编辑器渲染为拖拽引用控件,序列化按 uint64 直读直写。
37 std::string refType;
38
40 bool isReference() const { return !refType.empty(); }
41
42 // ── P1-1: 运行时字段读写 ──────────────────────────
43 // 调用者自行保证缓冲区大小匹配 size 字段
44
46 void* GetFieldPtr(void* obj) const {
47 return static_cast<char*>(obj) + offset;
48 }
49
51 const void* GetFieldPtr(const void* obj) const {
52 return static_cast<const char*>(obj) + offset;
53 }
54
56 void GetValue(const void* obj, void* outBuffer) const {
57 std::memcpy(outBuffer, static_cast<const char*>(obj) + offset, size);
58 }
59
61 void SetValue(void* obj, const void* value) const {
62 std::memcpy(static_cast<char*>(obj) + offset, value, size);
63 }
64};
65
67struct EnumValue {
68 std::string name;
69 int64_t value;
70};
71
73struct MethodInfo {
74 std::string name;
75 std::string returnType;
76 std::vector<std::string> paramTypes;
79 std::function<void*(void*, const void**)> invoker;
80 std::vector<FieldMeta> meta;
81};
82
85 std::string name;
86 std::string typeName;
87 std::string getterName;
88 std::string setterName;
90 std::function<void*(void*)> getter;
92 std::function<void(void*, const void*)> setter;
93 std::vector<FieldMeta> meta;
94};
95
96struct TypeInfo {
97 std::string name;
98 size_t size = 0;
99 const TypeInfo* baseType = nullptr;
100 std::string baseTypeName;
101 std::vector<FieldInfo> fields;
102 std::vector<EnumValue> enumValues;
103 std::vector<MethodInfo> methods;
104 std::vector<PropertyInfo> properties;
105
106 // 用于 TypeRegistry::Get<T>() 的模板查询
107 std::type_index typeIndex = typeid(nullptr);
108
109 // ── P1-2: 工厂创建能力 ────────────────────────────
110 // factory(void* memory) → void*
111 // memory != nullptr 时 placement new,否则 new T()
112 std::function<void*(void*)> factory;
113
115 void* Create(void* memory = nullptr) const {
116 if (!factory) return nullptr;
117 return factory(memory);
118 }
119
121 std::string source;
122};
123
124} // namespace Shit
定义 AnimationClip.h:12
枚举常量
定义 TypeInfo.h:67
std::string name
枚举项名称(如 "None"、"Left"))
定义 TypeInfo.h:68
int64_t value
枚举项数值
定义 TypeInfo.h:69
定义 TypeInfo.h:27
void GetValue(const void *obj, void *outBuffer) const
将字段值拷贝到 outBuffer(调用者确保 outBuffer 至少 size 字节)
定义 TypeInfo.h:56
std::string typeName
定义 TypeInfo.h:31
bool isReference() const
是否为组件引用字段(ComponentRef<T>)
定义 TypeInfo.h:40
const void * GetFieldPtr(const void *obj) const
获取 const 对象中字段的指针(只读)
定义 TypeInfo.h:51
std::string refType
引用目标类型名(归一化,无命名空间前缀;空 = 普通字段)
定义 TypeInfo.h:37
void SetValue(void *obj, const void *value) const
将 value 内容写入到字段(调用者确保 value 指向至少 size 字节的有效数据)
定义 TypeInfo.h:61
void * GetFieldPtr(void *obj) const
获取可变对象中字段的指针(用于 in-place 修改)
定义 TypeInfo.h:46
size_t size
定义 TypeInfo.h:30
std::string name
定义 TypeInfo.h:28
size_t offset
定义 TypeInfo.h:29
std::vector< FieldMeta > meta
字段元数据(编辑器属性面板用)
定义 TypeInfo.h:32
定义 TypeInfo.h:17
std::string unit
显示单位(如 "px"、"m/s")
定义 TypeInfo.h:24
bool readOnly
编辑器是否只读
定义 TypeInfo.h:23
std::string tooltip
悬停提示
定义 TypeInfo.h:19
float step
步长(0 表示默认)
定义 TypeInfo.h:21
RangeMeta range
数值范围(min==max 表示不限制)
定义 TypeInfo.h:20
std::string displayName
属性面板显示名(空 = 用字段名)
定义 TypeInfo.h:18
std::string category
属性分组
定义 TypeInfo.h:22
方法信息(由 SHIT_METHOD 生成)
定义 TypeInfo.h:73
std::string name
方法名
定义 TypeInfo.h:74
std::string returnType
返回类型名
定义 TypeInfo.h:75
std::vector< std::string > paramTypes
参数类型名列表
定义 TypeInfo.h:76
std::vector< FieldMeta > meta
定义 TypeInfo.h:80
std::function< void *(void *, const void **)> invoker
调用器:(obj, args) -> returnValue obj = 对象指针,args = 参数指针数组,返回值通过 void* 返回
定义 TypeInfo.h:79
属性信息(由 SHIT_PROPERTY 生成,getter/setter 对)
定义 TypeInfo.h:84
std::string typeName
属性类型名
定义 TypeInfo.h:86
std::string getterName
getter 方法名
定义 TypeInfo.h:87
std::string name
属性名
定义 TypeInfo.h:85
std::string setterName
setter 方法名(空 = 只读)
定义 TypeInfo.h:88
std::function< void(void *, const void *)> setter
setter 调用器:(obj, value) 写入值
定义 TypeInfo.h:92
std::function< void *(void *)> getter
getter 调用器:(obj) -> 指向值的指针(静态/线程局部存储)
定义 TypeInfo.h:90
std::vector< FieldMeta > meta
定义 TypeInfo.h:93
字段元数据(由 SHIT_META 生成,供编辑器属性面板用)
定义 TypeInfo.h:12
float max
定义 TypeInfo.h:14
float min
定义 TypeInfo.h:13
定义 TypeInfo.h:96
std::string source
注册来源(空 = 引擎内置,否则为插件名,用于卸载时批量清理)
定义 TypeInfo.h:121
std::type_index typeIndex
定义 TypeInfo.h:107
void * Create(void *memory=nullptr) const
创建类型实例。传入 nullptr 则堆分配(new),否则 placement new 到给定地址
定义 TypeInfo.h:115
std::vector< FieldInfo > fields
定义 TypeInfo.h:101
std::vector< MethodInfo > methods
方法列表
定义 TypeInfo.h:103
std::vector< EnumValue > enumValues
枚举常量列表(仅枚举类型使用)
定义 TypeInfo.h:102
size_t size
定义 TypeInfo.h:98
std::string baseTypeName
基类类型名(用于延迟解析,消除 SIOF)
定义 TypeInfo.h:100
std::string name
定义 TypeInfo.h:97
std::vector< PropertyInfo > properties
属性列表
定义 TypeInfo.h:104
std::function< void *(void *)> factory
定义 TypeInfo.h:112
const TypeInfo * baseType
定义 TypeInfo.h:99