Skip to content

Commit

Permalink
Split table data from table implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Sep 21, 2023
1 parent b1b4346 commit b68729f
Show file tree
Hide file tree
Showing 12 changed files with 2,304 additions and 1,806 deletions.
1,938 changes: 1,091 additions & 847 deletions flecs.c

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -3116,7 +3116,7 @@ extern "C" {
typedef struct ecs_stage_t ecs_stage_t;

/** Table data */
typedef struct ecs_data_t ecs_data_t;
typedef struct ecs_table_data_t ecs_table_data_t;

/* Switch list */
typedef struct ecs_switch_t ecs_switch_t;
Expand Down
2 changes: 1 addition & 1 deletion include/flecs/private/api_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extern "C" {
typedef struct ecs_stage_t ecs_stage_t;

/** Table data */
typedef struct ecs_data_t ecs_data_t;
typedef struct ecs_table_data_t ecs_table_data_t;

/* Switch list */
typedef struct ecs_switch_t ecs_switch_t;
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ ecs_table_t* flecs_bootstrap_component_table(
};

ecs_table_t *result = flecs_table_find_or_create(world, &array);
ecs_data_t *data = flecs_table_data(result);
ecs_table_data_t *data = flecs_table_data(result);

/* Preallocate enough memory for initial components */
ecs_allocator_t *a = &world->allocator;
Expand Down
14 changes: 7 additions & 7 deletions src/entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ void flecs_instantiate_children(
}

ecs_type_t type = child_table->type;
ecs_data_t *child_data = flecs_table_data(child_table);
ecs_table_data_t *child_data = flecs_table_data(child_table);

ecs_entity_t slot_of = 0;
ecs_entity_t *ids = type.array;
Expand Down Expand Up @@ -765,7 +765,7 @@ const ecs_entity_t* flecs_bulk_new(
component_array.count = type.count;
}

ecs_data_t *data = flecs_table_data(table);
ecs_table_data_t *data = flecs_table_data(table);
int32_t row = flecs_table_appendn(world, table, count, entities);

/* Update entity index. */
Expand Down Expand Up @@ -988,7 +988,7 @@ void flecs_notify_on_set(
bool owned)
{
ecs_assert(ids != NULL, ECS_INTERNAL_ERROR, NULL);
ecs_data_t *data = flecs_table_data(table);
ecs_table_data_t *data = flecs_table_data(table);

ecs_entity_t *entities = &flecs_table_entities_array(table)[row];
ecs_assert(entities != NULL, ECS_INTERNAL_ERROR, NULL);
Expand Down Expand Up @@ -3149,11 +3149,11 @@ void ecs_enable_id(
}

ecs_assert(table->_ != NULL, ECS_INTERNAL_ERROR, NULL);
index -= flecs_table_data(table)->bs_offset;
index -= table->_->bs_offset;
ecs_assert(index >= 0, ECS_INTERNAL_ERROR, NULL);

/* Data cannot be NULl, since entity is stored in the table */
ecs_bitset_t *bs = &flecs_table_data(table)->bs_columns[index];
ecs_bitset_t *bs = &flecs_table_data(table)->bitsets[index].data;
ecs_assert(bs != NULL, ECS_INTERNAL_ERROR, NULL);

flecs_bitset_set(bs, ECS_RECORD_TO_ROW(r->row), enable);
Expand Down Expand Up @@ -3189,9 +3189,9 @@ bool ecs_is_enabled_id(
}

ecs_assert(table->_ != NULL, ECS_INTERNAL_ERROR, NULL);
index -= flecs_table_data(table)->bs_offset;
index -= table->_->bs_offset;
ecs_assert(index >= 0, ECS_INTERNAL_ERROR, NULL);
ecs_bitset_t *bs = &flecs_table_data(table)->bs_columns[index];
ecs_bitset_t *bs = &flecs_table_data(table)->bitsets[index].data;

return flecs_bitset_get(bs, ECS_RECORD_TO_ROW(r->row));
error:
Expand Down
6 changes: 3 additions & 3 deletions src/entity_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ int flecs_entity_filter_bitset_next(

int32_t i, count = ecs_vec_count(&iter->entity_filter->bs_terms);
flecs_bitset_term_t *terms = ecs_vec_first(&iter->entity_filter->bs_terms);
int32_t bs_offset = flecs_table_data(table)->bs_offset;
int32_t bs_offset = table->_->bs_offset;
int32_t first = iter->bs_offset;
int32_t last = 0;

Expand All @@ -77,7 +77,7 @@ int flecs_entity_filter_bitset_next(
if (!bs) {
int32_t index = column->column_index;
ecs_assert((index - bs_offset >= 0), ECS_INTERNAL_ERROR, NULL);
bs = &flecs_table_data(table)->bs_columns[index - bs_offset];
bs = &flecs_table_data(table)->bitsets[index - bs_offset].data;
terms[i].bs_column = bs;
}

Expand Down Expand Up @@ -228,7 +228,7 @@ int32_t flecs_get_flattened_target(
}

if (table->flags & EcsTableHasTarget) {
int32_t col = table->column_map[flecs_table_data(table)->ft_offset];
int32_t col = table->column_map[table->_->ft_offset];
ecs_assert(col != -1, ECS_INTERNAL_ERROR, NULL);
EcsTarget *next = flecs_table_column(table, col)->data.array;
next = ECS_ELEM_T(next, EcsTarget, ECS_RECORD_TO_ROW(r->row));
Expand Down
2 changes: 1 addition & 1 deletion src/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1957,7 +1957,7 @@ bool flecs_term_match_table(

if ((column == -1) && (src->flags & EcsUp) && (table->flags & EcsTableHasTarget)) {
ecs_assert(table->_ != NULL, ECS_INTERNAL_ERROR, NULL);
ecs_id_t rel = ECS_PAIR_SECOND(table->type.array[flecs_table_data(table)->ft_offset]);
ecs_id_t rel = ECS_PAIR_SECOND(table->type.array[table->_->ft_offset]);
if (rel == (uint32_t)src->trav) {
result = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/observable.c
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ void flecs_emit(
const ecs_event_record_t *er_onset = flecs_event_record_get_if(observable, EcsOnSet);
const ecs_event_record_t *er_unset = flecs_event_record_get_if(observable, EcsUnSet);

ecs_data_t *storage = NULL;
ecs_table_data_t *storage = NULL;
ecs_column_t *columns = NULL;
if (count) {
storage = table->data;
Expand Down
Loading

0 comments on commit b68729f

Please sign in to comment.