From 372f23024163e0fab57a847ddda41f06857efd7e Mon Sep 17 00:00:00 2001 From: aura Date: Mon, 27 Jul 2026 11:55:57 +0200 Subject: undo/redo props - WIP --- src/editor/properties.h | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'src/editor/properties.h') diff --git a/src/editor/properties.h b/src/editor/properties.h index 810c075..d4fc3bb 100644 --- a/src/editor/properties.h +++ b/src/editor/properties.h @@ -6,6 +6,7 @@ #include #include "../util/string.h" #include "../util/fnv.h" +#include "../util/profiler.h" #define EPROP( _type, name, value, display ) \ _type name = value; \ @@ -90,6 +91,7 @@ struct EOBJECT { LIST eprops{}; }; + template concept __eobject_base = __is_base_of(EOBJECT, T); @@ -112,6 +114,7 @@ struct EDITOR_PROP { _parent->eprops.push( { offset } ); + parentoff = pdata - parent; offset = _this - pdata; dataoff = offset; } @@ -133,6 +136,7 @@ struct EDITOR_PROP { _parent->eprops.push( { offset } ); + parentoff = pdata - parent; offset = _this - pdata; dataoff = offset; } @@ -154,6 +158,7 @@ struct EDITOR_PROP { _parent->eprops.push( { offset } ); + parentoff = pdata - parent; offset = _this - pdata; dataoff = offset; } @@ -175,11 +180,13 @@ struct EDITOR_PROP { _parent->eprops.push( { offset } ); + parentoff = pdata - parent; offset = _this - pdata; dataoff = offset; } U64 dataoff; + U64 parentoff; U8 type; STR displayname; F64 min{ -INFINITY }; @@ -220,22 +227,40 @@ inline EDITOR_PROP* eprop_from_ref( EOBJECT* obj, EPROP_ENTRY e ) { return (EDITOR_PROP*)( (U64)obj + e.offset ); } +inline EDITOR_PROP* eprop_from_ptr( EOBJECT* obj, void* ptr ) { + if( (U64)ptr < (U64)obj ) { + trace( "eprop_from_ptr() : error : invalid pointer access, obj = %llx, ptr = %llx\n", (U64)obj, (U64)ptr ); + return 0; + } + + U64 off = ( (U64)ptr - (U64)obj ); + for( auto& it : obj->eprops ) { + EDITOR_PROP* p = eprop_from_ref( obj, it ); + if( off == p->parentoff ) + return p; + } + + return 0; +} + 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 ); - +inline EDITOR_PROP* eprop_from_hash( EOBJECT* obj, FNV1A hash ) { for( auto& it : obj->eprops ) { EDITOR_PROP* prop = eprop_from_ref( obj, it ); - if( fnv == prop->hash ) + if( hash == prop->hash ) return prop; } - return 0; } +inline EDITOR_PROP* eprop_from_name( EOBJECT* obj, STR name ) { + FNV1A fnv = fnv1a( name ); + return eprop_from_hash( obj, fnv ); +} + template const U8 eprop_type() { return EDITOR_PROP::__eprop_type::type; -- cgit v1.2.3