Skip to content

Commit 68b4f1f

Browse files
committed
#680 replace storage_type with separate count and ids members
1 parent 7bbecdf commit 68b4f1f

File tree

8 files changed

+33332
-33398
lines changed

8 files changed

+33332
-33398
lines changed

flecs.c

Lines changed: 33012 additions & 33036 deletions
Large diffs are not rendered by default.

flecs.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6981,15 +6981,6 @@ FLECS_API
69816981
ecs_table_t* ecs_table_get_storage_table(
69826982
const ecs_table_t *table);
69836983

6984-
/** Get number of storages for table.
6985-
*
6986-
* @param table The table.
6987-
* @return The number of storages (components) in table.
6988-
*/
6989-
FLECS_API
6990-
int32_t ecs_table_storage_count(
6991-
const ecs_table_t *table);
6992-
69936984
/** Convert index in table type to index in table storage type. */
69946985
int32_t ecs_table_type_to_storage_index(
69956986
const ecs_table_t *table,

include/flecs.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4224,15 +4224,6 @@ FLECS_API
42244224
ecs_table_t* ecs_table_get_storage_table(
42254225
const ecs_table_t *table);
42264226

4227-
/** Get number of storages for table.
4228-
*
4229-
* @param table The table.
4230-
* @return The number of storages (components) in table.
4231-
*/
4232-
FLECS_API
4233-
int32_t ecs_table_storage_count(
4234-
const ecs_table_t *table);
4235-
42364227
/** Convert index in table type to index in table storage type. */
42374228
int32_t ecs_table_type_to_storage_index(
42384229
const ecs_table_t *table,

src/addons/snapshot.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ ecs_data_t* duplicate_data(
3131
}
3232

3333
ecs_data_t *result = ecs_os_calloc(ECS_SIZEOF(ecs_data_t));
34-
ecs_type_t storage_type = table->storage_type;
35-
int32_t i, column_count = ecs_vector_count(storage_type);
34+
int32_t i, column_count = table->storage_count;
3635
result->columns = ecs_os_memdup_n(
3736
main_data->columns, ecs_column_t, column_count);
3837

src/entity.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ void* get_component_w_index(
3131
int32_t column_index,
3232
int32_t row)
3333
{
34-
ecs_check(column_index < ecs_table_storage_count(table),
35-
ECS_NOT_A_COMPONENT, NULL);
34+
ecs_check(column_index < table->storage_count, ECS_NOT_A_COMPONENT, NULL);
3635

3736
ecs_type_info_t *ti = &table->type_info[column_index];
3837
ecs_column_t *column = &table->storage.columns[column_index];
@@ -1305,9 +1304,8 @@ void flecs_notify_on_set(
13051304

13061305
ecs_ids_t local_ids;
13071306
if (!ids) {
1308-
ecs_type_t storage_type = table->storage_type;
1309-
local_ids.array = ecs_vector_first(storage_type, ecs_id_t);
1310-
local_ids.count = ecs_vector_count(storage_type);
1307+
local_ids.array = table->storage_ids;
1308+
local_ids.count = table->storage_count;
13111309
ids = &local_ids;
13121310
}
13131311

@@ -2332,7 +2330,7 @@ void ecs_clear(
23322330
if (table) {
23332331
ecs_table_diff_t diff = {
23342332
.removed = flecs_type_to_ids(table->type),
2335-
.un_set = flecs_type_to_ids(table->storage_type)
2333+
.un_set = { table->storage_ids, table->storage_count, 0 }
23362334
};
23372335

23382336
delete_entity(world, table, &table->storage, info.row, &diff);
@@ -2752,7 +2750,7 @@ void ecs_delete(
27522750
if (table_id && flecs_sparse_is_alive(&world->store.tables, table_id)) {
27532751
ecs_table_diff_t diff = {
27542752
.removed = flecs_type_to_ids(table->type),
2755-
.un_set = flecs_type_to_ids(table->storage_type)
2753+
.un_set = { table->storage_ids, table->storage_count, 0 }
27562754
};
27572755

27582756
delete_entity(world, table, info.data, info.row, &diff);

src/private_types.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ typedef struct ecs_table_event_t {
8888
/* If the nubmer of fields gets out of hand, this can be turned into a union
8989
* but since events are very temporary objects, this works for now and makes
9090
* initializing an event a bit simpler. */
91-
} ecs_table_event_t;
91+
} ecs_table_event_t;
9292

9393
/** A component column. */
9494
struct ecs_column_t {
@@ -122,8 +122,7 @@ struct ecs_data_t {
122122
#define EcsTableHasChildOf 8u /* Does the table type ChildOf relation */
123123
#define EcsTableHasPairs 16u /* Does the table type have pairs */
124124
#define EcsTableHasModule 32u /* Does the table have module data */
125-
#define EcsTableHasXor 64u /* Does the table type has XOR */
126-
#define EcsTableIsDisabled 128u /* Does the table type has EcsDisabled */
125+
#define EcsTableIsDisabled 128u /* Does the table type has EcsDisabled */
127126
#define EcsTableHasCtors 256u
128127
#define EcsTableHasDtors 512u
129128
#define EcsTableHasCopy 1024u
@@ -188,31 +187,31 @@ struct ecs_table_t {
188187
uint64_t id; /* Table id in sparse set */
189188
ecs_type_t type; /* Identifies table type in type_index */
190189
ecs_flags32_t flags; /* Flags for testing table properties */
190+
int32_t storage_count; /* Number of (non-zero sized) components */
191191

192192
struct ecs_table_record_t *records; /* Array with table records */
193-
int32_t record_count;
194-
195193
ecs_table_t *storage_table; /* Table w/type without tags */
196-
ecs_type_t storage_type; /* Storage table type (prevents indirection) */
194+
ecs_id_t *storage_ids; /* Storage ids (prevent indirection) */
197195
int32_t *storage_map; /* Map type <-> storage type
198196
* - 0..count(T): type -> storage_type
199197
* - count(T)..count(S): storage_type -> type
200198
*/
201199

202200
ecs_graph_node_t node; /* Graph node */
203201
ecs_data_t storage; /* Component storage */
204-
ecs_type_info_t *type_info; /* Cached pointers to type info */
202+
ecs_type_info_t *type_info; /* Cached pointers to type info */
205203

206204
int32_t *dirty_state; /* Keep track of changes in columns */
207-
int32_t alloc_count; /* Increases when columns are reallocd */
208-
205+
209206
int16_t sw_column_count;
210207
int16_t sw_column_offset;
211208
int16_t bs_column_count;
212209
int16_t bs_column_offset;
213210

211+
int32_t alloc_count; /* Increases when columns are reallocd */
214212
int32_t lock;
215213
int32_t refcount;
214+
int32_t record_count;
216215
};
217216

218217
/** Must appear as first member in payload of table cache */

0 commit comments

Comments
 (0)