Skip to content

Commit 01cb970

Browse files
committed
#680 rename table::c_info to type_info
1 parent 3dd6083 commit 01cb970

File tree

4 files changed

+53
-52
lines changed

4 files changed

+53
-52
lines changed

flecs.c

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ struct ecs_table_t {
475475

476476
ecs_graph_node_t node; /* Graph node */
477477
ecs_data_t storage; /* Component storage */
478-
ecs_type_info_t **c_info; /* Cached pointers to component info */
478+
ecs_type_info_t **type_info; /* Cached pointers to type info */
479479

480480
int32_t *dirty_state; /* Keep track of changes in columns */
481481
int32_t alloc_count; /* Increases when columns are reallocd */
@@ -2159,8 +2159,8 @@ void check_table_sanity(ecs_table_t *table) {
21592159
for (i = 0; i < storage_count; i ++) {
21602160
ecs_type_info_t *ti = NULL;
21612161
ecs_column_t *column = &table->storage.columns[i];
2162-
if (table->c_info) {
2163-
ti = table->c_info[i];
2162+
if (table->type_info) {
2163+
ti = table->type_info[i];
21642164
}
21652165
if (ti) {
21662166
ecs_assert(ti->size == column->size, ECS_INTERNAL_ERROR, NULL);
@@ -2389,7 +2389,7 @@ void init_type_info(
23892389
ecs_id_t *ids = ecs_vector_first(type, ecs_id_t);
23902390
int32_t i, count = ecs_vector_count(type);
23912391

2392-
table->c_info = ecs_os_calloc_n(ecs_type_info_t*, count);
2392+
table->type_info = ecs_os_calloc_n(ecs_type_info_t*, count);
23932393

23942394
for (i = 0; i < count; i ++) {
23952395
ecs_id_t id = ids[i];
@@ -2400,7 +2400,7 @@ void init_type_info(
24002400
table->flags |= get_component_action_flags(ti);
24012401
}
24022402

2403-
table->c_info[i] = (ecs_type_info_t*)ti;
2403+
table->type_info[i] = (ecs_type_info_t*)ti;
24042404
}
24052405
}
24062406

@@ -2659,7 +2659,7 @@ void dtor_all_components(
26592659
/* Run on_remove callbacks in bulk for improved performance */
26602660
for (c = 0; c < column_count; c++) {
26612661
ecs_column_t *column = &data->columns[c];
2662-
ecs_type_info_t *cdata = table->c_info[c];
2662+
ecs_type_info_t *cdata = table->type_info[c];
26632663
if (!cdata) {
26642664
continue;
26652665
}
@@ -2680,7 +2680,7 @@ void dtor_all_components(
26802680
for (i = row; i < end; i ++) {
26812681
for (c = 0; c < column_count; c++) {
26822682
ecs_column_t *column = &data->columns[c];
2683-
dtor_component(world, table, table->c_info[c], column,
2683+
dtor_component(world, table, table->type_info[c], column,
26842684
entities, ids[c], i, 1, false);
26852685
}
26862686

@@ -2911,8 +2911,8 @@ void flecs_table_free(
29112911
ecs_os_free(table->dirty_state);
29122912
ecs_os_free(table->storage_map);
29132913

2914-
if (table->c_info) {
2915-
ecs_os_free(table->c_info);
2914+
if (table->type_info) {
2915+
ecs_os_free(table->type_info);
29162916
}
29172917

29182918
flecs_table_records_unregister(world, table);
@@ -3254,7 +3254,7 @@ int32_t grow_data(
32543254
ecs_os_memset(r, 0, ECS_SIZEOF(ecs_record_t*) * to_add);
32553255

32563256
/* Add elements to each column array */
3257-
ecs_type_info_t **c_info_array = table->c_info;
3257+
ecs_type_info_t **c_info_array = table->type_info;
32583258
ecs_entity_t *entities = ecs_vector_first(data->entities, ecs_entity_t);
32593259
for (i = 0; i < column_count; i ++) {
32603260
ecs_column_t *column = &columns[i];
@@ -3365,7 +3365,7 @@ int32_t flecs_table_append(
33653365
ecs_sw_column_t *sw_columns = table->storage.sw_columns;
33663366
ecs_bs_column_t *bs_columns = table->storage.bs_columns;
33673367

3368-
ecs_type_info_t **c_info_array = table->c_info;
3368+
ecs_type_info_t **c_info_array = table->type_info;
33693369
ecs_entity_t *entities = ecs_vector_first(
33703370
data->entities, ecs_entity_t);
33713371

@@ -3506,7 +3506,7 @@ void flecs_table_delete(
35063506
}
35073507

35083508
/* Destruct component data */
3509-
ecs_type_info_t **c_info_array = table->c_info;
3509+
ecs_type_info_t **c_info_array = table->type_info;
35103510
ecs_column_t *columns = data->columns;
35113511
int32_t column_count = ecs_vector_count(table->storage_type);
35123512
int32_t i;
@@ -3720,7 +3720,7 @@ void flecs_table_move(
37203720
ecs_assert(dst != NULL, ECS_INTERNAL_ERROR, NULL);
37213721
ecs_assert(src != NULL, ECS_INTERNAL_ERROR, NULL);
37223722

3723-
ecs_type_info_t *ti = new_table->c_info[i_new];
3723+
ecs_type_info_t *ti = new_table->type_info[i_new];
37243724
if (same_entity) {
37253725
ecs_move_t callback;
37263726
if (ti && (callback = ti->lifecycle.ctor_move_dtor)) {
@@ -3740,11 +3740,11 @@ void flecs_table_move(
37403740
} else {
37413741
if (new_component < old_component) {
37423742
if (construct) {
3743-
ctor_component(world, new_table->c_info[i_new],
3743+
ctor_component(world, new_table->type_info[i_new],
37443744
&new_columns[i_new], &dst_entity, new_index, 1);
37453745
}
37463746
} else {
3747-
dtor_component(world, old_table, old_table->c_info[i_old],
3747+
dtor_component(world, old_table, old_table->type_info[i_old],
37483748
&old_columns[i_old], &src_entity, old_component,
37493749
old_index, 1, true);
37503750
}
@@ -3756,13 +3756,13 @@ void flecs_table_move(
37563756

37573757
if (construct) {
37583758
for (; (i_new < new_column_count); i_new ++) {
3759-
ctor_component(world, new_table->c_info[i_new],
3759+
ctor_component(world, new_table->type_info[i_new],
37603760
&new_columns[i_new], &dst_entity, new_index, 1);
37613761
}
37623762
}
37633763

37643764
for (; (i_old < old_column_count); i_old ++) {
3765-
dtor_component(world, old_table, old_table->c_info[i_old],
3765+
dtor_component(world, old_table, old_table->type_info[i_old],
37663766
&old_columns[i_old], &src_entity, old_components[i_old],
37673767
old_index, 1, true);
37683768
}
@@ -3975,7 +3975,7 @@ void merge_column(
39753975
ecs_vector_t *src)
39763976
{
39773977
ecs_entity_t *entities = ecs_vector_first(data->entities, ecs_entity_t);
3978-
ecs_type_info_t *ti = table->c_info[column_id];
3978+
ecs_type_info_t *ti = table->type_info[column_id];
39793979
ecs_column_t *column = &data->columns[column_id];
39803980
ecs_vector_t *dst = column->data;
39813981
int16_t size = column->size;
@@ -4087,7 +4087,7 @@ void merge_table_data(
40874087
old_count + new_count);
40884088

40894089
/* Construct new values */
4090-
ecs_type_info_t *c_info = new_table->c_info[i_new];
4090+
ecs_type_info_t *c_info = new_table->type_info[i_new];
40914091
if (c_info) {
40924092
ctor_component(world, c_info, column,
40934093
entities, 0, old_count + new_count);
@@ -4098,7 +4098,7 @@ void merge_table_data(
40984098
ecs_column_t *column = &old_columns[i_old];
40994099

41004100
/* Destruct old values */
4101-
ecs_type_info_t *c_info = old_table->c_info[i_old];
4101+
ecs_type_info_t *c_info = old_table->type_info[i_old];
41024102
if (c_info) {
41034103
dtor_component(world, old_table, c_info, column,
41044104
entities, 0, 0, old_count, false);
@@ -4128,7 +4128,7 @@ void merge_table_data(
41284128
old_count + new_count);
41294129

41304130
/* Construct new values */
4131-
ecs_type_info_t *c_info = new_table->c_info[i_new];
4131+
ecs_type_info_t *c_info = new_table->type_info[i_new];
41324132
if (c_info) {
41334133
ctor_component(world, c_info, column,
41344134
entities, 0, old_count + new_count);
@@ -4140,7 +4140,7 @@ void merge_table_data(
41404140
ecs_column_t *column = &old_columns[i_old];
41414141

41424142
/* Destruct old values */
4143-
ecs_type_info_t *c_info = old_table->c_info[i_old];
4143+
ecs_type_info_t *c_info = old_table->type_info[i_old];
41444144
if (c_info) {
41454145
dtor_component(world, old_table, c_info, column, entities, 0,
41464146
0, old_count, false);
@@ -23065,6 +23065,13 @@ int init_type(
2306523065
EcsMetaType *meta_type = ecs_get_mut(world, type, EcsMetaType, &is_added);
2306623066
if (is_added) {
2306723067
meta_type->existing = ecs_has(world, type, EcsComponent);
23068+
23069+
/* Ensure that component has a default constructor, to prevent crashing
23070+
* serializers on uninitialized values. */
23071+
ecs_type_info_t *ti = flecs_ensure_type_info(world, type);
23072+
if (!ti->lifecycle.ctor) {
23073+
ti->lifecycle.ctor = ecs_default_ctor;
23074+
}
2306823075
} else {
2306923076
if (meta_type->kind != kind) {
2307023077
ecs_err("type '%s' reregistered with different kind",
@@ -35610,12 +35617,6 @@ ecs_type_info_t* flecs_ensure_type_info(
3561035617
ti_mut = flecs_sparse_ensure(
3561135618
world->type_info, ecs_type_info_t, component);
3561235619
ecs_assert(ti_mut != NULL, ECS_INTERNAL_ERROR, NULL);
35613-
35614-
/* Assign default ctor but don't set lifecycle_set to true. This will
35615-
* cause components to be initialized to 0 by default unless overridden
35616-
* by the application, while still allowing the application to override
35617-
* the ctor callback */
35618-
ti_mut->lifecycle.ctor = ecs_default_ctor;
3561935620
} else {
3562035621
ti_mut = (ecs_type_info_t*)ti;
3562135622
}
@@ -43603,7 +43604,7 @@ void init_table(
4360343604
ecs_world_t *world,
4360443605
ecs_table_t *table)
4360543606
{
43606-
table->c_info = NULL;
43607+
table->type_info = NULL;
4360743608
table->flags = 0;
4360843609
table->dirty_state = NULL;
4360943610
table->alloc_count = 0;

src/private_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ struct ecs_table_t {
203203

204204
ecs_graph_node_t node; /* Graph node */
205205
ecs_data_t storage; /* Component storage */
206-
ecs_type_info_t **c_info; /* Cached pointers to component info */
206+
ecs_type_info_t **type_info; /* Cached pointers to type info */
207207

208208
int32_t *dirty_state; /* Keep track of changes in columns */
209209
int32_t alloc_count; /* Increases when columns are reallocd */

src/table.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ void check_table_sanity(ecs_table_t *table) {
4949
for (i = 0; i < storage_count; i ++) {
5050
ecs_type_info_t *ti = NULL;
5151
ecs_column_t *column = &table->storage.columns[i];
52-
if (table->c_info) {
53-
ti = table->c_info[i];
52+
if (table->type_info) {
53+
ti = table->type_info[i];
5454
}
5555
if (ti) {
5656
ecs_assert(ti->size == column->size, ECS_INTERNAL_ERROR, NULL);
@@ -279,7 +279,7 @@ void init_type_info(
279279
ecs_id_t *ids = ecs_vector_first(type, ecs_id_t);
280280
int32_t i, count = ecs_vector_count(type);
281281

282-
table->c_info = ecs_os_calloc_n(ecs_type_info_t*, count);
282+
table->type_info = ecs_os_calloc_n(ecs_type_info_t*, count);
283283

284284
for (i = 0; i < count; i ++) {
285285
ecs_id_t id = ids[i];
@@ -290,7 +290,7 @@ void init_type_info(
290290
table->flags |= get_component_action_flags(ti);
291291
}
292292

293-
table->c_info[i] = (ecs_type_info_t*)ti;
293+
table->type_info[i] = (ecs_type_info_t*)ti;
294294
}
295295
}
296296

@@ -549,7 +549,7 @@ void dtor_all_components(
549549
/* Run on_remove callbacks in bulk for improved performance */
550550
for (c = 0; c < column_count; c++) {
551551
ecs_column_t *column = &data->columns[c];
552-
ecs_type_info_t *cdata = table->c_info[c];
552+
ecs_type_info_t *cdata = table->type_info[c];
553553
if (!cdata) {
554554
continue;
555555
}
@@ -570,7 +570,7 @@ void dtor_all_components(
570570
for (i = row; i < end; i ++) {
571571
for (c = 0; c < column_count; c++) {
572572
ecs_column_t *column = &data->columns[c];
573-
dtor_component(world, table, table->c_info[c], column,
573+
dtor_component(world, table, table->type_info[c], column,
574574
entities, ids[c], i, 1, false);
575575
}
576576

@@ -801,8 +801,8 @@ void flecs_table_free(
801801
ecs_os_free(table->dirty_state);
802802
ecs_os_free(table->storage_map);
803803

804-
if (table->c_info) {
805-
ecs_os_free(table->c_info);
804+
if (table->type_info) {
805+
ecs_os_free(table->type_info);
806806
}
807807

808808
flecs_table_records_unregister(world, table);
@@ -1144,7 +1144,7 @@ int32_t grow_data(
11441144
ecs_os_memset(r, 0, ECS_SIZEOF(ecs_record_t*) * to_add);
11451145

11461146
/* Add elements to each column array */
1147-
ecs_type_info_t **c_info_array = table->c_info;
1147+
ecs_type_info_t **c_info_array = table->type_info;
11481148
ecs_entity_t *entities = ecs_vector_first(data->entities, ecs_entity_t);
11491149
for (i = 0; i < column_count; i ++) {
11501150
ecs_column_t *column = &columns[i];
@@ -1255,7 +1255,7 @@ int32_t flecs_table_append(
12551255
ecs_sw_column_t *sw_columns = table->storage.sw_columns;
12561256
ecs_bs_column_t *bs_columns = table->storage.bs_columns;
12571257

1258-
ecs_type_info_t **c_info_array = table->c_info;
1258+
ecs_type_info_t **c_info_array = table->type_info;
12591259
ecs_entity_t *entities = ecs_vector_first(
12601260
data->entities, ecs_entity_t);
12611261

@@ -1396,7 +1396,7 @@ void flecs_table_delete(
13961396
}
13971397

13981398
/* Destruct component data */
1399-
ecs_type_info_t **c_info_array = table->c_info;
1399+
ecs_type_info_t **c_info_array = table->type_info;
14001400
ecs_column_t *columns = data->columns;
14011401
int32_t column_count = ecs_vector_count(table->storage_type);
14021402
int32_t i;
@@ -1610,7 +1610,7 @@ void flecs_table_move(
16101610
ecs_assert(dst != NULL, ECS_INTERNAL_ERROR, NULL);
16111611
ecs_assert(src != NULL, ECS_INTERNAL_ERROR, NULL);
16121612

1613-
ecs_type_info_t *ti = new_table->c_info[i_new];
1613+
ecs_type_info_t *ti = new_table->type_info[i_new];
16141614
if (same_entity) {
16151615
ecs_move_t callback;
16161616
if (ti && (callback = ti->lifecycle.ctor_move_dtor)) {
@@ -1630,11 +1630,11 @@ void flecs_table_move(
16301630
} else {
16311631
if (new_component < old_component) {
16321632
if (construct) {
1633-
ctor_component(world, new_table->c_info[i_new],
1633+
ctor_component(world, new_table->type_info[i_new],
16341634
&new_columns[i_new], &dst_entity, new_index, 1);
16351635
}
16361636
} else {
1637-
dtor_component(world, old_table, old_table->c_info[i_old],
1637+
dtor_component(world, old_table, old_table->type_info[i_old],
16381638
&old_columns[i_old], &src_entity, old_component,
16391639
old_index, 1, true);
16401640
}
@@ -1646,13 +1646,13 @@ void flecs_table_move(
16461646

16471647
if (construct) {
16481648
for (; (i_new < new_column_count); i_new ++) {
1649-
ctor_component(world, new_table->c_info[i_new],
1649+
ctor_component(world, new_table->type_info[i_new],
16501650
&new_columns[i_new], &dst_entity, new_index, 1);
16511651
}
16521652
}
16531653

16541654
for (; (i_old < old_column_count); i_old ++) {
1655-
dtor_component(world, old_table, old_table->c_info[i_old],
1655+
dtor_component(world, old_table, old_table->type_info[i_old],
16561656
&old_columns[i_old], &src_entity, old_components[i_old],
16571657
old_index, 1, true);
16581658
}
@@ -1865,7 +1865,7 @@ void merge_column(
18651865
ecs_vector_t *src)
18661866
{
18671867
ecs_entity_t *entities = ecs_vector_first(data->entities, ecs_entity_t);
1868-
ecs_type_info_t *ti = table->c_info[column_id];
1868+
ecs_type_info_t *ti = table->type_info[column_id];
18691869
ecs_column_t *column = &data->columns[column_id];
18701870
ecs_vector_t *dst = column->data;
18711871
int16_t size = column->size;
@@ -1977,7 +1977,7 @@ void merge_table_data(
19771977
old_count + new_count);
19781978

19791979
/* Construct new values */
1980-
ecs_type_info_t *c_info = new_table->c_info[i_new];
1980+
ecs_type_info_t *c_info = new_table->type_info[i_new];
19811981
if (c_info) {
19821982
ctor_component(world, c_info, column,
19831983
entities, 0, old_count + new_count);
@@ -1988,7 +1988,7 @@ void merge_table_data(
19881988
ecs_column_t *column = &old_columns[i_old];
19891989

19901990
/* Destruct old values */
1991-
ecs_type_info_t *c_info = old_table->c_info[i_old];
1991+
ecs_type_info_t *c_info = old_table->type_info[i_old];
19921992
if (c_info) {
19931993
dtor_component(world, old_table, c_info, column,
19941994
entities, 0, 0, old_count, false);
@@ -2018,7 +2018,7 @@ void merge_table_data(
20182018
old_count + new_count);
20192019

20202020
/* Construct new values */
2021-
ecs_type_info_t *c_info = new_table->c_info[i_new];
2021+
ecs_type_info_t *c_info = new_table->type_info[i_new];
20222022
if (c_info) {
20232023
ctor_component(world, c_info, column,
20242024
entities, 0, old_count + new_count);
@@ -2030,7 +2030,7 @@ void merge_table_data(
20302030
ecs_column_t *column = &old_columns[i_old];
20312031

20322032
/* Destruct old values */
2033-
ecs_type_info_t *c_info = old_table->c_info[i_old];
2033+
ecs_type_info_t *c_info = old_table->type_info[i_old];
20342034
if (c_info) {
20352035
dtor_component(world, old_table, c_info, column, entities, 0,
20362036
0, old_count, false);

0 commit comments

Comments
 (0)