ShitEngine
基于 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 // ── P1-1: 运行时字段读写 ──────────────────────────
35 // 调用者自行保证缓冲区大小匹配 size 字段
36
38 void* GetFieldPtr(void* obj) const {
39 return static_cast<char*>(obj) + offset;
40 }
41
43 const void* GetFieldPtr(const void* obj) const {
44 return static_cast<const char*>(obj) + offset;
45 }
46
48 void GetValue(const void* obj, void* outBuffer) const {
49 std::memcpy(outBuffer, static_cast<const char*>(obj) + offset, size);
50 }
51
53 void SetValue(void* obj, const void* value) const {
54 std::memcpy(static_cast<char*>(obj) + offset, value, size);
55 }
56};
57
59struct EnumValue {
60 std::string name;
61 int64_t value;
62};
63
64struct TypeInfo {
65 std::string name;
66 size_t size = 0;
67 const TypeInfo* baseType = nullptr;
68 std::string baseTypeName;
69 std::vector<FieldInfo> fields;
70 std::vector<EnumValue> enumValues;
71
72 // 用于 TypeRegistry::Get<T>() 的模板查询
73 std::type_index typeIndex = typeid(nullptr);
74
75 // ── P1-2: 工厂创建能力 ────────────────────────────
76 // factory(void* memory) → void*
77 // memory != nullptr 时 placement new,否则 new T()
78 std::function<void*(void*)> factory;
79
81 void* Create(void* memory = nullptr) const {
82 if (!factory) return nullptr;
83 return factory(memory);
84 }
85
87 std::string source;
88};
89
90} // namespace Shit
定义 AudioPlayer.h:10
枚举常量
定义 TypeInfo.h:59
std::string name
枚举项名称(如 "None"、"Left"))
定义 TypeInfo.h:60
int64_t value
枚举项数值
定义 TypeInfo.h:61
定义 TypeInfo.h:27
void GetValue(const void *obj, void *outBuffer) const
将字段值拷贝到 outBuffer(调用者确保 outBuffer 至少 size 字节)
定义 TypeInfo.h:48
std::string typeName
定义 TypeInfo.h:31
const void * GetFieldPtr(const void *obj) const
获取 const 对象中字段的指针(只读)
定义 TypeInfo.h:43
void SetValue(void *obj, const void *value) const
将 value 内容写入到字段(调用者确保 value 指向至少 size 字节的有效数据)
定义 TypeInfo.h:53
void * GetFieldPtr(void *obj) const
获取可变对象中字段的指针(用于 in-place 修改)
定义 TypeInfo.h:38
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_META 生成,供编辑器属性面板用)
定义 TypeInfo.h:12
float max
定义 TypeInfo.h:14
float min
定义 TypeInfo.h:13
定义 TypeInfo.h:64
std::string source
注册来源(空 = 引擎内置,否则为插件名,用于卸载时批量清理)
定义 TypeInfo.h:87
std::type_index typeIndex
定义 TypeInfo.h:73
void * Create(void *memory=nullptr) const
创建类型实例。传入 nullptr 则堆分配(new),否则 placement new 到给定地址
定义 TypeInfo.h:81
std::vector< FieldInfo > fields
定义 TypeInfo.h:69
std::vector< EnumValue > enumValues
枚举常量列表(仅枚举类型使用)
定义 TypeInfo.h:70
size_t size
定义 TypeInfo.h:66
std::string baseTypeName
基类类型名(用于延迟解析,消除 SIOF)
定义 TypeInfo.h:68
std::string name
定义 TypeInfo.h:65
std::function< void *(void *)> factory
定义 TypeInfo.h:78
const TypeInfo * baseType
定义 TypeInfo.h:67