diff --git a/flecs.c b/flecs.c index 7a6f61759..46db11b2f 100644 --- a/flecs.c +++ b/flecs.c @@ -2855,9 +2855,9 @@ void flecs_table_init_storage_table( ecs_id_t *ids = type.array; ecs_table_record_t *records = table->records; - ecs_id_t array[ECS_ID_CACHE_SIZE]; + ecs_id_t array[FLECS_ID_DESC_MAX]; ecs_type_t storage_ids = { .array = array }; - if (count > ECS_ID_CACHE_SIZE) { + if (count > FLECS_ID_DESC_MAX) { storage_ids.array = flecs_walloc_n(world, ecs_id_t, count); } @@ -7070,7 +7070,7 @@ int flecs_traverse_add( int32_t i = 0; ecs_id_t id; const ecs_id_t *ids = desc->add; - while ((i < ECS_ID_CACHE_SIZE) && (id = ids[i ++])) { + while ((i < FLECS_ID_DESC_MAX) && (id = ids[i ++])) { bool should_add = true; if (ECS_HAS_ID_FLAG(id, PAIR) && ECS_PAIR_FIRST(id) == EcsChildOf) { scope = ECS_PAIR_SECOND(id); @@ -7178,7 +7178,7 @@ void flecs_deferred_add_remove( int32_t i = 0; ecs_id_t id; const ecs_id_t *ids = desc->add; - while ((i < ECS_ID_CACHE_SIZE) && (id = ids[i ++])) { + while ((i < FLECS_ID_DESC_MAX) && (id = ids[i ++])) { bool defer = true; if (ECS_HAS_ID_FLAG(id, PAIR) && ECS_PAIR_FIRST(id) == EcsChildOf) { scope = ECS_PAIR_SECOND(id); @@ -7293,7 +7293,7 @@ ecs_entity_t ecs_entity_init( const ecs_id_t *ids = desc->add; ecs_id_t id; int32_t i = 0; - while ((i < ECS_ID_CACHE_SIZE) && (id = ids[i ++])) { + while ((i < FLECS_ID_DESC_MAX) && (id = ids[i ++])) { if (ECS_HAS_ID_FLAG(id, PAIR) && (ECS_PAIR_FIRST(id) == EcsChildOf)) { @@ -49363,7 +49363,7 @@ ecs_filter_t* ecs_filter_init( if (!terms) { ecs_check(term_count == 0, ECS_INVALID_PARAMETER, NULL); terms = desc->terms; - for (i = 0; i < ECS_TERM_DESC_CACHE_SIZE; i ++) { + for (i = 0; i < FLECS_TERM_DESC_MAX; i ++) { if (!ecs_term_is_initialized(&terms[i])) { break; } @@ -52155,7 +52155,7 @@ ecs_entity_t ecs_observer_init( * since they require pre/post checking of the filter to test if the * entity is entering/leaving the monitor. */ int i; - for (i = 0; i < ECS_OBSERVER_DESC_EVENT_COUNT_MAX; i ++) { + for (i = 0; i < FLECS_EVENT_DESC_MAX; i ++) { ecs_entity_t event = desc->events[i]; if (!event) { break; @@ -57753,7 +57753,7 @@ void ecs_iter_set_var( { ecs_check(it != NULL, ECS_INVALID_PARAMETER, NULL); ecs_check(var_id >= 0, ECS_INVALID_PARAMETER, NULL); - ecs_check(var_id < ECS_VARIABLE_COUNT_MAX, ECS_INVALID_PARAMETER, NULL); + ecs_check(var_id < FLECS_VARIABLE_COUNT_MAX, ECS_INVALID_PARAMETER, NULL); ecs_check(var_id < it->variable_count, ECS_INVALID_PARAMETER, NULL); ecs_check(entity != 0, ECS_INVALID_PARAMETER, NULL); /* Can't set variable while iterating */ @@ -57796,7 +57796,7 @@ void ecs_iter_set_var_as_range( { ecs_check(it != NULL, ECS_INVALID_PARAMETER, NULL); ecs_check(var_id >= 0, ECS_INVALID_PARAMETER, NULL); - ecs_check(var_id < ECS_VARIABLE_COUNT_MAX, ECS_INVALID_PARAMETER, NULL); + ecs_check(var_id < FLECS_VARIABLE_COUNT_MAX, ECS_INVALID_PARAMETER, NULL); ecs_check(var_id < it->variable_count, ECS_INVALID_PARAMETER, NULL); ecs_check(range != 0, ECS_INVALID_PARAMETER, NULL); ecs_check(range->table != NULL, ECS_INVALID_PARAMETER, NULL); diff --git a/flecs.h b/flecs.h index eb6e111a0..e240c4275 100644 --- a/flecs.h +++ b/flecs.h @@ -225,23 +225,23 @@ * as memory will be freed more often, at the cost of decreased performance. */ // #define FLECS_USE_OS_ALLOC -/** \def ECS_ID_CACHE_SIZE +/** \def FLECS_ID_DESC_MAX * Maximum number of components to add/remove in a single operation */ -#ifndef ECS_ID_CACHE_SIZE -#define ECS_ID_CACHE_SIZE (32) +#ifndef FLECS_ID_DESC_MAX +#define FLECS_ID_DESC_MAX (32) #endif -/** \def ECS_TERM_DESC_CACHE_SIZE +/** \def FLECS_TERM_DESC_MAX * Maximum number of terms in desc (larger, as these are temp objects) */ -#define ECS_TERM_DESC_CACHE_SIZE (16) +#define FLECS_TERM_DESC_MAX (16) -/** \def ECS_OBSERVER_DESC_EVENT_COUNT_MAX +/** \def FLECS_EVENT_DESC_MAX * Maximum number of events to set in static array of observer descriptor */ -#define ECS_OBSERVER_DESC_EVENT_COUNT_MAX (8) +#define FLECS_EVENT_DESC_MAX (8) -/** \def ECS_VARIABLE_COUNT_MAX +/** \def FLECS_VARIABLE_COUNT_MAX * Maximum number of query variables per query */ -#define ECS_VARIABLE_COUNT_MAX (64) +#define FLECS_VARIABLE_COUNT_MAX (64) /** @} */ @@ -2753,7 +2753,7 @@ struct ecs_observer_t { ecs_filter_t filter; /**< Query for observer */ /* Observer events */ - ecs_entity_t events[ECS_OBSERVER_DESC_EVENT_COUNT_MAX]; + ecs_entity_t events[FLECS_EVENT_DESC_MAX]; int32_t event_count; ecs_iter_action_t callback; /**< See ecs_observer_desc_t::callback */ @@ -3435,7 +3435,7 @@ typedef struct ecs_entity_desc_t { * no id is specified. */ /** Array of ids to add to the new or existing entity. */ - ecs_id_t add[ECS_ID_CACHE_SIZE]; + ecs_id_t add[FLECS_ID_DESC_MAX]; /** String expression with components to add */ const char *add_expr; @@ -3455,7 +3455,7 @@ typedef struct ecs_bulk_desc_t { int32_t count; /**< Number of entities to create/populate */ - ecs_id_t ids[ECS_ID_CACHE_SIZE]; /**< Ids to create the entities with */ + ecs_id_t ids[FLECS_ID_DESC_MAX]; /**< Ids to create the entities with */ void **data; /**< Array with component data to insert. Each element in * the array must correspond with an element in the ids @@ -3493,8 +3493,8 @@ typedef struct ecs_filter_desc_t { int32_t _canary; /** Terms of the filter. If a filter has more terms than - * ECS_TERM_DESC_CACHE_SIZE use terms_buffer */ - ecs_term_t terms[ECS_TERM_DESC_CACHE_SIZE]; + * FLECS_TERM_DESC_MAX use terms_buffer */ + ecs_term_t terms[FLECS_TERM_DESC_MAX]; /** For filters with lots of terms an outside array can be provided. */ ecs_term_t *terms_buffer; @@ -3593,7 +3593,7 @@ typedef struct ecs_observer_desc_t { ecs_filter_desc_t filter; /** Events to observe (OnAdd, OnRemove, OnSet, UnSet) */ - ecs_entity_t events[ECS_OBSERVER_DESC_EVENT_COUNT_MAX]; + ecs_entity_t events[FLECS_EVENT_DESC_MAX]; /** When observer is created, generate events from existing data. For example, * EcsOnAdd Position would match all existing instances of Position. @@ -25986,14 +25986,14 @@ struct filter_builder_i : term_builder_i { "filter_builder::term() called without initializing term"); } - if (m_term_index >= ECS_TERM_DESC_CACHE_SIZE) { - if (m_term_index == ECS_TERM_DESC_CACHE_SIZE) { + if (m_term_index >= FLECS_TERM_DESC_MAX) { + if (m_term_index == FLECS_TERM_DESC_MAX) { m_desc->terms_buffer = ecs_os_calloc_n( ecs_term_t, m_term_index + 1); ecs_os_memcpy_n(m_desc->terms_buffer, m_desc->terms, ecs_term_t, m_term_index); ecs_os_memset_n(m_desc->terms, 0, - ecs_term_t, ECS_TERM_DESC_CACHE_SIZE); + ecs_term_t, FLECS_TERM_DESC_MAX); } else { m_desc->terms_buffer = ecs_os_realloc_n(m_desc->terms_buffer, ecs_term_t, m_term_index + 1); diff --git a/include/flecs.h b/include/flecs.h index 1513c6c54..6523e228b 100644 --- a/include/flecs.h +++ b/include/flecs.h @@ -175,6 +175,7 @@ #define FLECS_HI_COMPONENT_ID (16) #define FLECS_HI_ID_RECORD_ID (16) #define FLECS_SPARSE_PAGE_BITS (6) +#define FLECS_ENTITY_PAGE_BITS (6) #define FLECS_USE_OS_ALLOC #endif @@ -223,23 +224,23 @@ * as memory will be freed more often, at the cost of decreased performance. */ // #define FLECS_USE_OS_ALLOC -/** \def ECS_ID_CACHE_SIZE - * Maximum number of components to add/remove in a single operation */ -#ifndef ECS_ID_CACHE_SIZE -#define ECS_ID_CACHE_SIZE (32) +/** \def FLECS_ID_DESC_MAX + * Maximum number of ids to add ecs_entity_desc_t / ecs_bulk_desc_t */ +#ifndef FLECS_ID_DESC_MAX +#define FLECS_ID_DESC_MAX (32) #endif -/** \def ECS_TERM_DESC_CACHE_SIZE - * Maximum number of terms in desc (larger, as these are temp objects) */ -#define ECS_TERM_DESC_CACHE_SIZE (16) +/** \def FLECS_TERM_DESC_MAX + * Maximum number of terms in ecs_filter_desc_t */ +#define FLECS_TERM_DESC_MAX (16) -/** \def ECS_OBSERVER_DESC_EVENT_COUNT_MAX - * Maximum number of events to set in static array of observer descriptor */ -#define ECS_OBSERVER_DESC_EVENT_COUNT_MAX (8) +/** \def FLECS_EVENT_DESC_MAX + * Maximum number of events in ecs_observer_desc_t */ +#define FLECS_EVENT_DESC_MAX (8) -/** \def ECS_VARIABLE_COUNT_MAX +/** \def FLECS_VARIABLE_COUNT_MAX * Maximum number of query variables per query */ -#define ECS_VARIABLE_COUNT_MAX (64) +#define FLECS_VARIABLE_COUNT_MAX (64) /** @} */ @@ -649,7 +650,7 @@ struct ecs_observer_t { ecs_filter_t filter; /**< Query for observer */ /* Observer events */ - ecs_entity_t events[ECS_OBSERVER_DESC_EVENT_COUNT_MAX]; + ecs_entity_t events[FLECS_EVENT_DESC_MAX]; int32_t event_count; ecs_iter_action_t callback; /**< See ecs_observer_desc_t::callback */ @@ -782,7 +783,7 @@ typedef struct ecs_entity_desc_t { * no id is specified. */ /** Array of ids to add to the new or existing entity. */ - ecs_id_t add[ECS_ID_CACHE_SIZE]; + ecs_id_t add[FLECS_ID_DESC_MAX]; /** String expression with components to add */ const char *add_expr; @@ -802,7 +803,7 @@ typedef struct ecs_bulk_desc_t { int32_t count; /**< Number of entities to create/populate */ - ecs_id_t ids[ECS_ID_CACHE_SIZE]; /**< Ids to create the entities with */ + ecs_id_t ids[FLECS_ID_DESC_MAX]; /**< Ids to create the entities with */ void **data; /**< Array with component data to insert. Each element in * the array must correspond with an element in the ids @@ -840,8 +841,8 @@ typedef struct ecs_filter_desc_t { int32_t _canary; /** Terms of the filter. If a filter has more terms than - * ECS_TERM_DESC_CACHE_SIZE use terms_buffer */ - ecs_term_t terms[ECS_TERM_DESC_CACHE_SIZE]; + * FLECS_TERM_DESC_MAX use terms_buffer */ + ecs_term_t terms[FLECS_TERM_DESC_MAX]; /** For filters with lots of terms an outside array can be provided. */ ecs_term_t *terms_buffer; @@ -940,7 +941,7 @@ typedef struct ecs_observer_desc_t { ecs_filter_desc_t filter; /** Events to observe (OnAdd, OnRemove, OnSet, UnSet) */ - ecs_entity_t events[ECS_OBSERVER_DESC_EVENT_COUNT_MAX]; + ecs_entity_t events[FLECS_EVENT_DESC_MAX]; /** When observer is created, generate events from existing data. For example, * EcsOnAdd Position would match all existing instances of Position. diff --git a/include/flecs/addons/cpp/mixins/filter/builder_i.hpp b/include/flecs/addons/cpp/mixins/filter/builder_i.hpp index 55d98d3ce..385d30833 100644 --- a/include/flecs/addons/cpp/mixins/filter/builder_i.hpp +++ b/include/flecs/addons/cpp/mixins/filter/builder_i.hpp @@ -124,14 +124,14 @@ struct filter_builder_i : term_builder_i { "filter_builder::term() called without initializing term"); } - if (m_term_index >= ECS_TERM_DESC_CACHE_SIZE) { - if (m_term_index == ECS_TERM_DESC_CACHE_SIZE) { + if (m_term_index >= FLECS_TERM_DESC_MAX) { + if (m_term_index == FLECS_TERM_DESC_MAX) { m_desc->terms_buffer = ecs_os_calloc_n( ecs_term_t, m_term_index + 1); ecs_os_memcpy_n(m_desc->terms_buffer, m_desc->terms, ecs_term_t, m_term_index); ecs_os_memset_n(m_desc->terms, 0, - ecs_term_t, ECS_TERM_DESC_CACHE_SIZE); + ecs_term_t, FLECS_TERM_DESC_MAX); } else { m_desc->terms_buffer = ecs_os_realloc_n(m_desc->terms_buffer, ecs_term_t, m_term_index + 1); diff --git a/src/entity.c b/src/entity.c index a68fe9ce8..387cfee5a 100644 --- a/src/entity.c +++ b/src/entity.c @@ -1452,7 +1452,7 @@ int flecs_traverse_add( int32_t i = 0; ecs_id_t id; const ecs_id_t *ids = desc->add; - while ((i < ECS_ID_CACHE_SIZE) && (id = ids[i ++])) { + while ((i < FLECS_ID_DESC_MAX) && (id = ids[i ++])) { bool should_add = true; if (ECS_HAS_ID_FLAG(id, PAIR) && ECS_PAIR_FIRST(id) == EcsChildOf) { scope = ECS_PAIR_SECOND(id); @@ -1560,7 +1560,7 @@ void flecs_deferred_add_remove( int32_t i = 0; ecs_id_t id; const ecs_id_t *ids = desc->add; - while ((i < ECS_ID_CACHE_SIZE) && (id = ids[i ++])) { + while ((i < FLECS_ID_DESC_MAX) && (id = ids[i ++])) { bool defer = true; if (ECS_HAS_ID_FLAG(id, PAIR) && ECS_PAIR_FIRST(id) == EcsChildOf) { scope = ECS_PAIR_SECOND(id); @@ -1675,7 +1675,7 @@ ecs_entity_t ecs_entity_init( const ecs_id_t *ids = desc->add; ecs_id_t id; int32_t i = 0; - while ((i < ECS_ID_CACHE_SIZE) && (id = ids[i ++])) { + while ((i < FLECS_ID_DESC_MAX) && (id = ids[i ++])) { if (ECS_HAS_ID_FLAG(id, PAIR) && (ECS_PAIR_FIRST(id) == EcsChildOf)) { diff --git a/src/filter.c b/src/filter.c index e3639dd4c..10c85fba0 100644 --- a/src/filter.c +++ b/src/filter.c @@ -1389,7 +1389,7 @@ ecs_filter_t* ecs_filter_init( if (!terms) { ecs_check(term_count == 0, ECS_INVALID_PARAMETER, NULL); terms = desc->terms; - for (i = 0; i < ECS_TERM_DESC_CACHE_SIZE; i ++) { + for (i = 0; i < FLECS_TERM_DESC_MAX; i ++) { if (!ecs_term_is_initialized(&terms[i])) { break; } diff --git a/src/iter.c b/src/iter.c index c3a2a4422..1b4e4a4f2 100644 --- a/src/iter.c +++ b/src/iter.c @@ -767,7 +767,7 @@ void ecs_iter_set_var( { ecs_check(it != NULL, ECS_INVALID_PARAMETER, NULL); ecs_check(var_id >= 0, ECS_INVALID_PARAMETER, NULL); - ecs_check(var_id < ECS_VARIABLE_COUNT_MAX, ECS_INVALID_PARAMETER, NULL); + ecs_check(var_id < FLECS_VARIABLE_COUNT_MAX, ECS_INVALID_PARAMETER, NULL); ecs_check(var_id < it->variable_count, ECS_INVALID_PARAMETER, NULL); ecs_check(entity != 0, ECS_INVALID_PARAMETER, NULL); /* Can't set variable while iterating */ @@ -810,7 +810,7 @@ void ecs_iter_set_var_as_range( { ecs_check(it != NULL, ECS_INVALID_PARAMETER, NULL); ecs_check(var_id >= 0, ECS_INVALID_PARAMETER, NULL); - ecs_check(var_id < ECS_VARIABLE_COUNT_MAX, ECS_INVALID_PARAMETER, NULL); + ecs_check(var_id < FLECS_VARIABLE_COUNT_MAX, ECS_INVALID_PARAMETER, NULL); ecs_check(var_id < it->variable_count, ECS_INVALID_PARAMETER, NULL); ecs_check(range != 0, ECS_INVALID_PARAMETER, NULL); ecs_check(range->table != NULL, ECS_INVALID_PARAMETER, NULL); diff --git a/src/observer.c b/src/observer.c index 599115a93..afeeb298a 100644 --- a/src/observer.c +++ b/src/observer.c @@ -855,7 +855,7 @@ ecs_entity_t ecs_observer_init( * since they require pre/post checking of the filter to test if the * entity is entering/leaving the monitor. */ int i; - for (i = 0; i < ECS_OBSERVER_DESC_EVENT_COUNT_MAX; i ++) { + for (i = 0; i < FLECS_EVENT_DESC_MAX; i ++) { ecs_entity_t event = desc->events[i]; if (!event) { break; diff --git a/src/table.c b/src/table.c index be4c8a456..140121900 100644 --- a/src/table.c +++ b/src/table.c @@ -241,9 +241,9 @@ void flecs_table_init_storage_table( ecs_id_t *ids = type.array; ecs_table_record_t *records = table->records; - ecs_id_t array[ECS_ID_CACHE_SIZE]; + ecs_id_t array[FLECS_ID_DESC_MAX]; ecs_type_t storage_ids = { .array = array }; - if (count > ECS_ID_CACHE_SIZE) { + if (count > FLECS_ID_DESC_MAX) { storage_ids.array = flecs_walloc_n(world, ecs_id_t, count); } diff --git a/test/api/src/Type.c b/test/api/src/Type.c index a7685910b..f797e9f1e 100644 --- a/test/api/src/Type.c +++ b/test/api/src/Type.c @@ -371,7 +371,7 @@ void Type_large_type_expr() { void Type_large_type_expr_limit() { ecs_world_t *world = ecs_mini(); - test_assert(ECS_ID_CACHE_SIZE == 32); + test_assert(FLECS_ID_DESC_MAX == 32); int i; for (i = 0; i < 32; i ++) {