From d42d218a3685c030a7370d30f2de5495ea526d99 Mon Sep 17 00:00:00 2001 From: aura Date: Fri, 13 Mar 2026 05:03:12 +0100 Subject: wip on props --- src/editor/properties.h | 88 +++++++++++++++++++++++++++++++++++++++++++++++++ src/game.h | 3 +- src/game/world/map.h | 25 ++++++-------- src/gamedef.h | 4 +++ src/util/allocator.h | 12 ++++++- 5 files changed, 114 insertions(+), 18 deletions(-) create mode 100644 src/editor/properties.h create mode 100644 src/gamedef.h diff --git a/src/editor/properties.h b/src/editor/properties.h new file mode 100644 index 0000000..f3d55b5 --- /dev/null +++ b/src/editor/properties.h @@ -0,0 +1,88 @@ +#pragma once + +#include "../gamedef.h" + +#if IS_EDITOR +#include +#include "../util/string.h" + +#define EPROP( _type, name, value, display ) \ + _type name = value; \ + EDITOR_PROP name##_prop{ .pdata = &name, .type = eprop_type<_type>(), .displayname = display, .parent = this }; + +#define EPROP_RANGED( _type, name, value, display, _min, _max ) \ + _type name{ value }; \ + EDITOR_PROP{ \ + .pdata = &name, \ + .type = eprop_type<_type>(), \ + .displayname = display, \ + .parent = this, \ + .min = _min, \ + .max = _max \ + } + +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_STRING, + EPROP_OBJ, + EPROP_LIST, + EPROP_TEXTURE_LIST, +}; + +// editor map object +struct EOBJECT { + LIST eprops{}; +}; + +// editor object property +struct EDITOR_PROP { + void* pdata; + U8 type; + STR displayname; + F64 min{ -INFINITY }; + F64 max{ INFINITY }; + struct EOBJECT* parent; + + + 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_OBJ; }; + template struct __eprop_type> { static const U8 type = EPROP_LIST; }; + template <> struct __eprop_type> { static const U8 type = EPROP_TEXTURE_LIST; }; +}; + +template +const U8 eprop_type() { + if constexpr( __is_base_of( EOBJECT, T ) ) + return EPROP_OBJ; + + return EDITOR_PROP::__eprop_type::type; +} +#else +struct EOBJECT {}; + +#define EPROP( type, name, value, displayname ) \ + type name{ value }; +#endif diff --git a/src/game.h b/src/game.h index 862234b..a615e18 100644 --- a/src/game.h +++ b/src/game.h @@ -1,8 +1,7 @@ #pragma once // disable new_delete_type_mismatch asan warning -#define IS_EDITOR 1 - +#include "gamedef.h" #include "game/assets.h" #include "render/gl.h" #include "render/gl_2d.h" diff --git a/src/game/world/map.h b/src/game/world/map.h index f3f56f8..2b8a7a5 100644 --- a/src/game/world/map.h +++ b/src/game/world/map.h @@ -4,19 +4,21 @@ #include "../../util/vector.h" #include "../../util/color.h" #include "../../util/fnv.h" +#include "../../editor/properties.h" #include enum MapPropId_t { MAPPROP_SKYBOX = -1, + MAPPROP_CLIPBRUSH = -2, }; -struct SURF_PROPS { +struct SURF_PROPS : public EOBJECT { struct GL_TEX2D* tex; CLR clr; }; -struct MAP_VERTEX { +struct MAP_VERTEX : public EOBJECT { VEC3 pos; VEC3 normal; VEC2 uv; @@ -28,14 +30,7 @@ enum MapPolygonType_t { MPT_CEILING }; -struct MAP_POLYGON { - MAP_POLYGON& operator=( const MAP_POLYGON& other ) { - memcpy( this, &other, sizeof(*this) ); - vertices = other.vertices; - - return *this; - } - +struct MAP_POLYGON : public EOBJECT { LIST vertices; VEC3 mins; @@ -44,7 +39,7 @@ struct MAP_POLYGON { I32 propid; }; -struct MAP_WALL { +struct MAP_WALL : public EOBJECT { VEC3 start; VEC3 end; @@ -60,7 +55,7 @@ struct MAP_TEXTURE_ENTRY { FNV1A hash; }; -struct MAP_SPRITE { +struct MAP_SPRITE : public EOBJECT { VEC3 pos; VEC2 size; CLR clr; @@ -73,13 +68,13 @@ struct MAP_ENTITY { LIST props; }; -struct MAP_SKYBOX { +struct MAP_SKYBOX : public EOBJECT { SURF_PROPS props; MAP_WALL walls[4]; MAP_POLYGON polygons[2]; }; -struct WORLD_MAP { +struct WORLD_MAP : public EOBJECT { LIST walls; LIST polygons; LIST sprites; @@ -98,7 +93,7 @@ struct WORLD_MAP { struct BSP* bsp{}; - LIST textures; + EPROP( LIST, textures, {}, "textures" ); }; extern WORLD_MAP* map_from_file( struct GAME_DATA* game, const char* filename ); diff --git a/src/gamedef.h b/src/gamedef.h new file mode 100644 index 0000000..05c1a18 --- /dev/null +++ b/src/gamedef.h @@ -0,0 +1,4 @@ +#pragma once + +#define IS_EDITOR 1 +#define VERSION "0.0.1dev"__DATE__ diff --git a/src/util/allocator.h b/src/util/allocator.h index 8b159da..0cb8fa2 100644 --- a/src/util/allocator.h +++ b/src/util/allocator.h @@ -83,7 +83,10 @@ struct LIST { capacity = _size; } + LIST( const LIST& other ) { + if( this == &other ) return; + if( !other.capacity || !other.size ) { capacity = 1; size = 0; @@ -108,8 +111,13 @@ struct LIST { if( this == &other ) return *this; - if( data && data != other.data ) + if( data && data != other.data ) { + if constexpr( !__is_trivially_destructible(T) ) { + for( U32 i = 0; i < size; i++ ) + data[i].~T(); + } free( data ); + } data = 0; @@ -142,6 +150,8 @@ struct LIST { } if( data ) free( data ); + size = 0; + data = 0; } T at( U32 index ) { -- cgit v1.2.3