1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
#pragma once
#include "../gamedef.h"
#if IS_EDITOR
#include <math.h>
#include "../util/string.h"
#define EPROP( _type, name, value, display ) \
_type name = value; \
EDITOR_PROP name##_prop{ &name, eprop_type<_type>(), display, this, 0 };
#define EPROP_RO( _type, name, value, display ) \
_type name = value; \
EDITOR_PROP name##_prop{ .pdata = &name, .type = eprop_type<_type>(), .displayname = display, .parent = this, .readonly = 1 };
#define EPROP_RANGED( _type, name, value, display, _min, _max ) \
_type name{ value }; \
EDITOR_PROP{ \
&name, \
eprop_type<_type>(), \
display, \
this, \
_min, \
_max, \
0 \
}
enum EditorPropType_t {
EPROP_INVALID = 0,
EPROP_U8 = 1,
EPROP_U16,
EPROP_U32,
EPROP_U64,
EPROP_I8,
EPROP_I16,
EPROP_I32,
EPROP_I64,
EPROP_F32,
EPROP_F64,
EPROP_VEC2,
EPROP_VEC3,
EPROP_VEC4,
EPROP_CLR,
EPROP_MAPPROP,
EPROP_STRING,
EPROP_OBJ,
EPROP_LIST,
EPROP_TEXTURE,
EPROP_TEXTURE_LIST,
};
struct EPROP_ENTRY {
U64 offset;
};
// editor map object
struct EOBJECT {
LIST<EPROP_ENTRY> eprops{};
};
template <typename T>
concept __eobject_base = __is_base_of(EOBJECT, T);
// editor object property
struct EDITOR_PROP {
EDITOR_PROP( void* _pdata, U8 _type, STR _displayname, struct EOBJECT* _parent, U8 _readonly = 0 ) {
type = _type;
displayname = _displayname;
min = -INFINITY;
max = INFINITY;
readonly = _readonly;
U64 _this = (U64)this;
U64 pdata = (U64)_pdata;
U64 parent = (U64)_parent;
U64 offset = _this - parent;
_parent->eprops.push( { offset } );
offset = _this - pdata;
dataoff = offset;
}
EDITOR_PROP( void* _pdata, U8 _type, STR _displayname, struct EOBJECT* _parent, F32 _min, F32 _max, U8 _readonly = 0 ) {
type = _type;
displayname = _displayname;
min = _min;
max = _max;
readonly = _readonly;
U64 _this = (U64)this;
U64 pdata = (U64)_pdata;
U64 parent = (U64)_parent;
U64 offset = _this - parent;
_parent->eprops.push( { offset } );
offset = _this - pdata;
dataoff = offset;
}
U64 dataoff;
U8 type;
STR displayname;
F64 min{ -INFINITY };
F64 max{ INFINITY };
U8 readonly;
template <typename T> struct __eprop_type {
static const U8 type = EPROP_INVALID;
};
template <> struct __eprop_type<U8> { static const U8 type = EPROP_U8; };
template <> struct __eprop_type<U16> { static const U8 type = EPROP_U16; };
template <> struct __eprop_type<U32> { static const U8 type = EPROP_U32; };
template <> struct __eprop_type<U64> { static const U8 type = EPROP_U64; };
template <> struct __eprop_type<I8> { static const U8 type = EPROP_I8; };
template <> struct __eprop_type<I16> { static const U8 type = EPROP_I16; };
template <> struct __eprop_type<I32> { static const U8 type = EPROP_I32; };
template <> struct __eprop_type<I64> { static const U8 type = EPROP_I64; };
template <> struct __eprop_type<F32> { static const U8 type = EPROP_F32; };
template <> struct __eprop_type<F64> { static const U8 type = EPROP_F64; };
template <> struct __eprop_type<STR> { static const U8 type = EPROP_STRING; };
template <> struct __eprop_type<struct CLR> { static const U8 type = EPROP_CLR; };
template <> struct __eprop_type<struct VEC2> { static const U8 type = EPROP_VEC2; };
template <> struct __eprop_type<struct VEC3> { static const U8 type = EPROP_VEC3; };
template <> struct __eprop_type<struct VEC4> { static const U8 type = EPROP_VEC4; };
template <> struct __eprop_type<struct MAP_PROPREF> { static const U8 type = EPROP_MAPPROP; };
template <> struct __eprop_type<struct GL_TEX2D*> { static const U8 type = EPROP_TEXTURE; };
template <__eobject_base T> struct __eprop_type<T> { static const U8 type = EPROP_OBJ; };
template <typename LT> struct __eprop_type<LIST<LT>> { static const U8 type = EPROP_LIST; };
template <> struct __eprop_type<LIST<struct MAP_TEXTURE_ENTRY*>> { static const U8 type = EPROP_TEXTURE_LIST; };
};
inline EDITOR_PROP* eprop_from_ref( EOBJECT* obj, EPROP_ENTRY e ) {
return (EDITOR_PROP*)( (U64)obj + e.offset );
}
inline void* eprop_ptr( EDITOR_PROP* prop ) {
return (void*)( (U64)prop - prop->dataoff);
}
template <typename T>
const U8 eprop_type() {
return EDITOR_PROP::__eprop_type<T>::type;
}
#else
struct EOBJECT {};
#define EPROP( type, name, value, displayname ) \
type name{ value };
#endif
|