#pragma once #include "../gamedef.h" #if IS_EDITOR #include #include "../util/string.h" #include "../util/fnv.h" #define EPROP( _type, name, value, display ) \ _type name = value; \ EDITOR_PROP name##_prop{ &name, eprop_type<_type>(), display, this, sizeof(_type), 0 } #define EPROP_RO( _type, name, value, display ) \ _type name = value; \ EDITOR_PROP name##_prop{ &name, eprop_type<_type>(), display, this, sizeof(_type), 1 } #define EPROP_RANGED( _type, name, value, display, _min, _max ) \ _type name = value; \ EDITOR_PROP name##_prop{ \ &name, \ eprop_type<_type>(), \ display, \ this, \ _min, \ _max, \ sizeof(_type), \ 0 \ } #define EPROP_STEP( _type, name, value, display, step ) \ _type name = value; \ EDITOR_PROP name##_prop{ \ &name, \ eprop_type<_type>(), \ display, \ step, \ this, \ sizeof(_type), \ 0 \ } #define EPROP_RANGED_STEP( _type, name, value, display, min, max, step ) \ _type name = value; \ EDITOR_PROP name##_prop{ \ &name, \ eprop_type<_type>(), \ display, \ step, \ this, \ min, \ max, \ sizeof(_type), \ 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, EPROP_VERTEX, EPROP_VERTEX_LIST, EPROP_LAST }; struct EPROP_ENTRY { U64 offset; }; // editor map object struct EOBJECT { LIST eprops{}; }; template 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, U32 _size, U8 _readonly = 0 ) { type = _type; displayname = _displayname; min = -INFINITY; max = INFINITY; step = 0; readonly = _readonly; hash = fnv1a( _displayname ); size = _size; 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, F32 _step, struct EOBJECT* _parent, U32 _size, U8 _readonly = 0 ) { type = _type; displayname = _displayname; min = -INFINITY; max = INFINITY; step = _step; readonly = _readonly; hash = fnv1a( _displayname ); size = _size; 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, U32 _size, U8 _readonly = 0 ) { type = _type; displayname = _displayname; min = _min; max = _max; step = 0; readonly = _readonly; hash = fnv1a( _displayname ); size = _size; 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, F32 _step, struct EOBJECT* _parent, F32 _min, F32 _max, U32 _size, U8 _readonly = 0 ) { type = _type; displayname = _displayname; min = _min; max = _max; step = _step; readonly = _readonly; hash = fnv1a( _displayname ); size = _size; 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 }; F32 step; U8 readonly; FNV1A hash; U32 size; template struct __eprop_type { static const U8 type = EPROP_INVALID; }; template <> struct __eprop_type { static const U8 type = EPROP_U8; }; template <> struct __eprop_type { static const U8 type = EPROP_U16; }; template <> struct __eprop_type { static const U8 type = EPROP_U32; }; template <> struct __eprop_type { static const U8 type = EPROP_U64; }; template <> struct __eprop_type { static const U8 type = EPROP_I8; }; template <> struct __eprop_type { static const U8 type = EPROP_I16; }; template <> struct __eprop_type { static const U8 type = EPROP_I32; }; template <> struct __eprop_type { static const U8 type = EPROP_I64; }; template <> struct __eprop_type { static const U8 type = EPROP_F32; }; template <> struct __eprop_type { static const U8 type = EPROP_F64; }; template <> struct __eprop_type { static const U8 type = EPROP_STRING; }; template <> struct __eprop_type { static const U8 type = EPROP_CLR; }; template <> struct __eprop_type { static const U8 type = EPROP_VEC2; }; template <> struct __eprop_type { static const U8 type = EPROP_VEC3; }; template <> struct __eprop_type { static const U8 type = EPROP_VEC4; }; template <> struct __eprop_type { static const U8 type = EPROP_MAPPROP; }; template <> struct __eprop_type { static const U8 type = EPROP_TEXTURE; }; template <__eobject_base T> struct __eprop_type { static const U8 type = EPROP_OBJ; }; template struct __eprop_type> { static const U8 type = EPROP_LIST; }; template <> struct __eprop_type> { static const U8 type = EPROP_TEXTURE_LIST; }; template <> struct __eprop_type { static const U8 type = EPROP_VERTEX; }; template <> struct __eprop_type> { static const U8 type = EPROP_VERTEX_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); } inline EDITOR_PROP* eprop_from_name( EOBJECT* obj, STR name ) { FNV1A fnv = fnv1a( name ); for( auto& it : obj->eprops ) { EDITOR_PROP* prop = eprop_from_ref( obj, it ); if( fnv == prop->hash ) return prop; } return 0; } template const U8 eprop_type() { return EDITOR_PROP::__eprop_type::type; } #else struct EOBJECT {}; #define EPROP( _type, name, value, display ) \ _type name = value; #define EPROP_RO( _type, name, value, display ) \ _type name = value; #define EPROP_RANGED( _type, name, value, display, _min, _max ) \ _type name = value; #define EPROP_STEP( _type, name, value, display, step ) \ _type name = value; #define EPROP_RANGED_STEP( _type, name, value, display, min, max, step ) \ _type name = value; #endif