ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
Toggle main menu visibility
载入中...
搜索中...
未找到
TypeInfo.h
浏览该文件的文档.
1
#pragma once
2
3
#include <string>
4
#include <vector>
5
#include <typeindex>
6
#include <functional>
7
#include <cstring>
8
9
namespace
Shit
{
10
12
struct
RangeMeta
{
13
float
min
= 0.0f;
14
float
max
= 0.0f;
15
};
16
17
struct
FieldMeta
{
18
std::string
displayName
;
19
std::string
tooltip
;
20
RangeMeta
range
;
21
float
step
= 0.0f;
22
std::string
category
;
23
bool
readOnly
=
false
;
24
std::string
unit
;
25
};
26
27
struct
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
59
struct
EnumValue
{
60
std::string
name
;
61
int64_t
value
;
62
};
63
64
struct
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
Shit
定义
AudioPlayer.h:10
Shit::EnumValue
枚举常量
定义
TypeInfo.h:59
Shit::EnumValue::name
std::string name
枚举项名称(如 "None"、"Left"))
定义
TypeInfo.h:60
Shit::EnumValue::value
int64_t value
枚举项数值
定义
TypeInfo.h:61
Shit::FieldInfo
定义
TypeInfo.h:27
Shit::FieldInfo::GetValue
void GetValue(const void *obj, void *outBuffer) const
将字段值拷贝到 outBuffer(调用者确保 outBuffer 至少 size 字节)
定义
TypeInfo.h:48
Shit::FieldInfo::typeName
std::string typeName
定义
TypeInfo.h:31
Shit::FieldInfo::GetFieldPtr
const void * GetFieldPtr(const void *obj) const
获取 const 对象中字段的指针(只读)
定义
TypeInfo.h:43
Shit::FieldInfo::SetValue
void SetValue(void *obj, const void *value) const
将 value 内容写入到字段(调用者确保 value 指向至少 size 字节的有效数据)
定义
TypeInfo.h:53
Shit::FieldInfo::GetFieldPtr
void * GetFieldPtr(void *obj) const
获取可变对象中字段的指针(用于 in-place 修改)
定义
TypeInfo.h:38
Shit::FieldInfo::size
size_t size
定义
TypeInfo.h:30
Shit::FieldInfo::name
std::string name
定义
TypeInfo.h:28
Shit::FieldInfo::offset
size_t offset
定义
TypeInfo.h:29
Shit::FieldInfo::meta
std::vector< FieldMeta > meta
字段元数据(编辑器属性面板用)
定义
TypeInfo.h:32
Shit::FieldMeta
定义
TypeInfo.h:17
Shit::FieldMeta::unit
std::string unit
显示单位(如 "px"、"m/s")
定义
TypeInfo.h:24
Shit::FieldMeta::readOnly
bool readOnly
编辑器是否只读
定义
TypeInfo.h:23
Shit::FieldMeta::tooltip
std::string tooltip
悬停提示
定义
TypeInfo.h:19
Shit::FieldMeta::step
float step
步长(0 表示默认)
定义
TypeInfo.h:21
Shit::FieldMeta::range
RangeMeta range
数值范围(min==max 表示不限制)
定义
TypeInfo.h:20
Shit::FieldMeta::displayName
std::string displayName
属性面板显示名(空 = 用字段名)
定义
TypeInfo.h:18
Shit::FieldMeta::category
std::string category
属性分组
定义
TypeInfo.h:22
Shit::RangeMeta
字段元数据(由 SHIT_META 生成,供编辑器属性面板用)
定义
TypeInfo.h:12
Shit::RangeMeta::max
float max
定义
TypeInfo.h:14
Shit::RangeMeta::min
float min
定义
TypeInfo.h:13
Shit::TypeInfo
定义
TypeInfo.h:64
Shit::TypeInfo::source
std::string source
注册来源(空 = 引擎内置,否则为插件名,用于卸载时批量清理)
定义
TypeInfo.h:87
Shit::TypeInfo::typeIndex
std::type_index typeIndex
定义
TypeInfo.h:73
Shit::TypeInfo::Create
void * Create(void *memory=nullptr) const
创建类型实例。传入 nullptr 则堆分配(new),否则 placement new 到给定地址
定义
TypeInfo.h:81
Shit::TypeInfo::fields
std::vector< FieldInfo > fields
定义
TypeInfo.h:69
Shit::TypeInfo::enumValues
std::vector< EnumValue > enumValues
枚举常量列表(仅枚举类型使用)
定义
TypeInfo.h:70
Shit::TypeInfo::size
size_t size
定义
TypeInfo.h:66
Shit::TypeInfo::baseTypeName
std::string baseTypeName
基类类型名(用于延迟解析,消除 SIOF)
定义
TypeInfo.h:68
Shit::TypeInfo::name
std::string name
定义
TypeInfo.h:65
Shit::TypeInfo::factory
std::function< void *(void *)> factory
定义
TypeInfo.h:78
Shit::TypeInfo::baseType
const TypeInfo * baseType
定义
TypeInfo.h:67
include
ShitEngine
Reflection
TypeInfo.h
制作者
1.17.0