Skip to content

Commit b8de33e

Browse files
committed
Update flecs, fix issue with nested objects in inspector
1 parent b7e26af commit b8de33e

File tree

5 files changed

+136
-13
lines changed

5 files changed

+136
-13
lines changed

deps/flecs.c

Lines changed: 91 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49886,12 +49886,27 @@ int flecs_json_ser_enum(
4988649886
const void *base,
4988749887
ecs_strbuf_t *str)
4988849888
{
49889-
int32_t value = *(const int32_t*)base;
49889+
ecs_map_key_t value;
49890+
ecs_meta_op_kind_t kind = op->underlying_kind;
49891+
49892+
if (kind == EcsOpU8 || kind == EcsOpI8) {
49893+
value = *(const uint8_t*)base;
49894+
} else if (kind == EcsOpU16 || kind == EcsOpI16) {
49895+
value = *(const uint16_t*)base;
49896+
} else if (kind == EcsOpU32 || kind == EcsOpI32) {
49897+
value = *(const uint32_t*)base;
49898+
} else if (kind == EcsOpUPtr || kind == EcsOpIPtr) {
49899+
value = *(const uintptr_t*)base;
49900+
} else if (kind == EcsOpU64 || kind == EcsOpI64) {
49901+
value = *(const uint64_t*)base;
49902+
} else {
49903+
ecs_abort(ECS_INTERNAL_ERROR, "invalid underlying type");
49904+
}
4989049905

4989149906
/* Enumeration constants are stored in a map that is keyed on the
4989249907
* enumeration value. */
4989349908
ecs_enum_constant_t *constant = ecs_map_get_deref(op->is.constants,
49894-
ecs_enum_constant_t, (ecs_map_key_t)value);
49909+
ecs_enum_constant_t, value);
4989549910
if (!constant) {
4989649911
/* If the value is not found, it is not a valid enumeration constant */
4989749912
char *name = ecs_get_path(world, op->type);
@@ -55335,11 +55350,62 @@ int flecs_meta_serialize_enum(
5533555350
op->type_info = ecs_get_type_info(world, type);
5533655351
ecs_assert(op->type_info != NULL, ECS_INTERNAL_ERROR, NULL);
5533755352

55338-
const EcsConstants *enum_type = ecs_get(world, type, EcsConstants);
55339-
ecs_assert(enum_type != NULL, ECS_INVALID_PARAMETER, NULL);
55340-
op->is.constants = enum_type->constants;
55353+
const EcsConstants *constants = ecs_get(world, type, EcsConstants);
55354+
ecs_assert(constants != NULL, ECS_INVALID_PARAMETER, NULL);
55355+
op->is.constants = constants->constants;
5534155356
ecs_assert(op->is.constants != NULL, ECS_INTERNAL_ERROR, NULL);
5534255357

55358+
const EcsEnum *enum_type = ecs_get(world, type, EcsEnum);
55359+
ecs_assert(enum_type != NULL, ECS_INVALID_PARAMETER, NULL);
55360+
ecs_entity_t underlying = enum_type->underlying_type;
55361+
ecs_assert(underlying != 0, ECS_INTERNAL_ERROR, NULL);
55362+
55363+
const EcsPrimitive *prim_type = ecs_get(world, underlying, EcsPrimitive);
55364+
ecs_assert(prim_type != NULL, ECS_INTERNAL_ERROR, NULL);
55365+
55366+
switch(prim_type->kind) {
55367+
case EcsU8:
55368+
op->underlying_kind = EcsOpU8;
55369+
break;
55370+
case EcsU16:
55371+
op->underlying_kind = EcsOpU16;
55372+
break;
55373+
case EcsU32:
55374+
op->underlying_kind = EcsOpU32;
55375+
break;
55376+
case EcsUPtr:
55377+
op->underlying_kind = EcsOpUPtr;
55378+
break;
55379+
case EcsU64:
55380+
op->underlying_kind = EcsOpU64;
55381+
break;
55382+
case EcsI8:
55383+
op->underlying_kind = EcsOpI8;
55384+
break;
55385+
case EcsI16:
55386+
op->underlying_kind = EcsOpI16;
55387+
break;
55388+
case EcsI32:
55389+
op->underlying_kind = EcsOpI32;
55390+
break;
55391+
case EcsIPtr:
55392+
op->underlying_kind = EcsOpIPtr;
55393+
break;
55394+
case EcsI64:
55395+
op->underlying_kind = EcsOpI64;
55396+
break;
55397+
case EcsBool:
55398+
case EcsChar:
55399+
case EcsByte:
55400+
case EcsF32:
55401+
case EcsF64:
55402+
case EcsString:
55403+
case EcsEntity:
55404+
case EcsId:
55405+
ecs_abort(ECS_INTERNAL_ERROR,
55406+
"invalid primitive type kind for underlying enum type");
55407+
}
55408+
5534355409
return 0;
5534455410
}
5534555411

@@ -62284,6 +62350,7 @@ void FlecsScriptImport(
6228462350
* @brief Serialize values to string.
6228562351
*/
6228662352

62353+
#include <inttypes.h>
6228762354

6228862355
#ifdef FLECS_SCRIPT
6228962356

@@ -62317,15 +62384,31 @@ int flecs_expr_ser_enum(
6231762384
const void *base,
6231862385
ecs_strbuf_t *str)
6231962386
{
62320-
int32_t val = *(const int32_t*)base;
62387+
ecs_map_key_t value;
62388+
ecs_meta_op_kind_t kind = op->underlying_kind;
62389+
62390+
if (kind == EcsOpU8 || kind == EcsOpI8) {
62391+
value = *(const uint8_t*)base;
62392+
} else if (kind == EcsOpU16 || kind == EcsOpI16) {
62393+
value = *(const uint16_t*)base;
62394+
} else if (kind == EcsOpU32 || kind == EcsOpI32) {
62395+
value = *(const uint32_t*)base;
62396+
} else if (kind == EcsOpUPtr || kind == EcsOpIPtr) {
62397+
value = *(const uintptr_t*)base;
62398+
} else if (kind == EcsOpU64 || kind == EcsOpI64) {
62399+
value = *(const uint64_t*)base;
62400+
} else {
62401+
ecs_abort(ECS_INTERNAL_ERROR, "invalid underlying type");
62402+
}
6232162403

6232262404
/* Enumeration constants are stored in a map that is keyed on the
6232362405
* enumeration value. */
6232462406
ecs_enum_constant_t *c = ecs_map_get_deref(op->is.constants,
62325-
ecs_enum_constant_t, (ecs_map_key_t)val);
62407+
ecs_enum_constant_t, value);
6232662408
if (!c) {
6232762409
char *path = ecs_get_path(world, op->type);
62328-
ecs_err("value %d is not valid for enum type '%s'", val, path);
62410+
ecs_err("value %" PRIu64 " is not valid for enum type '%s'",
62411+
value, path);
6232962412
ecs_os_free(path);
6233062413
goto error;
6233162414
}

deps/flecs.h

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18860,8 +18860,10 @@ struct enum_type {
1886018860
has_contiguous = true;
1886118861
contiguous_until = 0;
1886218862

18863+
#if FLECS_CPP_ENUM_REFLECTION_SUPPORT
1886318864
enum_reflection<E, reflection_init>::
1886418865
template each_enum< static_cast<U>(enum_last<E>::value) >(*this);
18866+
#endif
1886518867
}
1886618868

1886718869
static enum_type<E>& get() {
@@ -18900,7 +18902,6 @@ struct enum_type {
1890018902

1890118903
int min;
1890218904
int max;
18903-
bool has_contiguous;
1890418905

1890518906
// If enum constants start not-sparse, contiguous_until will be the index of
1890618907
// the first sparse value, or end of the constants array
@@ -18912,8 +18913,16 @@ struct enum_type {
1891218913
template each_enum< static_cast<U>(enum_last<E>::value) >();
1891318914

1891418915
// Constants array is sized to the number of found-constants, or 1
18915-
// to avoid 0-sized array
18916+
// to avoid 0-sized array.
18917+
#ifdef FLECS_CPP_ENUM_REFLECTION
1891618918
enum_constant<U> constants[constants_size? constants_size: 1] = {};
18919+
bool has_contiguous;
18920+
#else
18921+
// If we're not using enum reflection, we cannot statically determine the
18922+
// upper bound of the enum, so use 128.
18923+
enum_constant<U> constants[128] = {};
18924+
bool has_contiguous = true; // Assume contiguous ids
18925+
#endif
1891718926
};
1891818927

1891918928
template <typename E, if_t< is_enum<E>::value > = 0>
@@ -18971,6 +18980,7 @@ struct enum_data {
1897118980
if (impl_.max < 0) {
1897218981
return -1;
1897318982
}
18983+
1897418984
// Check if value is in contiguous lookup section
1897518985
if (impl_.has_contiguous && value < impl_.contiguous_until && value >= 0) {
1897618986
return static_cast<int>(value);
@@ -19011,6 +19021,30 @@ struct enum_data {
1901119021
flecs::entity entity(U value) const;
1901219022
flecs::entity entity(E value) const;
1901319023

19024+
/**
19025+
* @brief Manually register constant for enum.
19026+
*
19027+
* If automatic enum reflection is not supported, provide method for
19028+
* manually registering constant.
19029+
*/
19030+
#ifdef FLECS_CPP_NO_ENUM_REFLECTION
19031+
void register_constant(flecs::world_t *world, U v, flecs::entity_t e) {
19032+
if (v < 128) {
19033+
if (!impl_.constants[v].index) {
19034+
impl_.constants[v].index = flecs_component_ids_index_get();
19035+
}
19036+
19037+
flecs_component_ids_set(world, impl_.constants[v].index, e);
19038+
19039+
impl_.max ++;
19040+
19041+
if (impl_.contiguous_until <= v) {
19042+
impl_.contiguous_until = v + 1;
19043+
}
19044+
}
19045+
}
19046+
#endif
19047+
1901419048
flecs::world_t *world_;
1901519049
_::enum_type<E>& impl_;
1901619050
};
@@ -29951,6 +29985,12 @@ component<T>& constant(const char *name, T value) {
2995129985
*ptr = static_cast<U>(value);
2995229986
ecs_modified_id(world_, eid, pair);
2995329987

29988+
// If we're not using automatic enum reflection, manually set static data
29989+
#ifdef FLECS_CPP_NO_ENUM_REFLECTION
29990+
auto et = enum_type<T>(world_);
29991+
et.register_constant(world_, static_cast<U>(value), eid);
29992+
#endif
29993+
2995429994
return *this;
2995529995
}
2995629996

etc/flecs_explorer.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

etc/flecs_explorer.wasm

2.43 KB
Binary file not shown.

etc/js/components/widgets/inspector/entity-inspector-kv.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<template>
2-
<div class="key noselect" @click="toggle">
2+
<div class="key noselect" @click.stop="toggle">
33
<template v-if="typeof value === 'object' && value !== null">
44
<expand-button
55
:expand="expand">
66
</expand-button>
77
</template>
88
{{ keyname }}
99
</div>
10-
<div class="value noselect" @click="toggle">
10+
<div class="value noselect" @click.stop="toggle">
1111
<template v-if="typeof value === 'object'">
1212
<entity-inspector-preview
1313
:value="value"

0 commit comments

Comments
 (0)