Skip to content

Commit

Permalink
Fix inconsistent naming of desc size constants
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed May 8, 2023
1 parent 159f0db commit 726c934
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 58 deletions.
18 changes: 9 additions & 9 deletions flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
Expand Down
36 changes: 18 additions & 18 deletions flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

/** @} */

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -25986,14 +25986,14 @@ struct filter_builder_i : term_builder_i<Base> {
"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);
Expand Down
37 changes: 19 additions & 18 deletions include/flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

/** @} */

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions include/flecs/addons/cpp/mixins/filter/builder_i.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ struct filter_builder_i : term_builder_i<Base> {
"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);
Expand Down
6 changes: 3 additions & 3 deletions src/entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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))
{
Expand Down
2 changes: 1 addition & 1 deletion src/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/iter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/observer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/table.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion test/api/src/Type.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ++) {
Expand Down

0 comments on commit 726c934

Please sign in to comment.