@@ -141,8 +141,8 @@ local __minor_chunks = {} ---@type table<evolved.fragment, evolved.assoc_list<ev
141141local __query_chunks = {} --- @type table<evolved.query , evolved.assoc_list<evolved.chunk>>
142142local __major_queries = {} --- @type table<evolved.fragment , evolved.assoc_list<evolved.query>>
143143
144- local __entity_chunks = {} --- @type table<integer , evolved.chunk>
145- local __entity_places = {} --- @type table< integer, integer>
144+ local __entity_chunks = {} --- @type ( evolved.chunk | false ) []
145+ local __entity_places = {} --- @type integer[]
146146
147147local __sorted_includes = {} --- @type table<evolved.query , evolved.assoc_list<evolved.fragment>>
148148local __sorted_excludes = {} --- @type table<evolved.query , evolved.assoc_list<evolved.fragment>>
@@ -674,6 +674,9 @@ local function __acquire_id()
674674 local acquired_id = acquired_primary + shifted_secondary
675675 freelist_ids [acquired_primary ] = acquired_id
676676
677+ __entity_chunks [acquired_primary ] = false
678+ __entity_places [acquired_primary ] = 0
679+
677680 return acquired_id --[[ @as evolved.id]]
678681 end
679682end
875878---
876879---
877880
878- local __table_dup
879-
880- --- @generic K , V
881- --- @param table table<K , V>
882- --- @return table<K , V>
883- --- @nodiscard
884- function __table_dup (table )
885- local dup_table = {}
886-
887- for k , v in __lua_next , table do
888- dup_table [k ] = v
889- end
890-
891- return dup_table
892- end
893-
894- ---
895- ---
896- ---
897- ---
898- ---
899-
900881--- @class (exact ) evolved.assoc_list <K >: {
901882--- __item_set: { [K]: integer },
902883--- __item_list: K[],
@@ -3364,8 +3345,8 @@ function __clear_entity_one(entity)
33643345 if chunk then
33653346 __detach_entity (chunk , place )
33663347
3367- entity_chunks [entity_primary ] = nil
3368- entity_places [entity_primary ] = nil
3348+ entity_chunks [entity_primary ] = false
3349+ entity_places [entity_primary ] = 0
33693350
33703351 __structural_changes = __structural_changes + 1
33713352 end
@@ -3431,8 +3412,8 @@ function __destroy_entity_one(entity)
34313412 if chunk then
34323413 __detach_entity (chunk , place )
34333414
3434- entity_chunks [entity_primary ] = nil
3435- entity_places [entity_primary ] = nil
3415+ entity_chunks [entity_primary ] = false
3416+ entity_places [entity_primary ] = 0
34363417
34373418 __structural_changes = __structural_changes + 1
34383419 end
@@ -4144,8 +4125,8 @@ function __chunk_remove(old_chunk, ...)
41444125 for old_place = 1 , old_entity_count do
41454126 local entity = old_entity_list [old_place ]
41464127 local entity_primary = entity % 2 ^ 20
4147- entity_chunks [entity_primary ] = nil
4148- entity_places [entity_primary ] = nil
4128+ entity_chunks [entity_primary ] = false
4129+ entity_places [entity_primary ] = 0
41494130 end
41504131
41514132 __detach_all_entities (old_chunk )
@@ -4207,8 +4188,8 @@ function __chunk_clear(chunk)
42074188 for place = 1 , chunk_entity_count do
42084189 local entity = chunk_entity_list [place ]
42094190 local entity_primary = entity % 2 ^ 20
4210- entity_chunks [entity_primary ] = nil
4211- entity_places [entity_primary ] = nil
4191+ entity_chunks [entity_primary ] = false
4192+ entity_places [entity_primary ] = 0
42124193 end
42134194
42144195 __detach_all_entities (chunk )
@@ -5255,11 +5236,11 @@ function __evolved_set(entity, fragment, component)
52555236 local old_chunk = entity_chunks [entity_primary ]
52565237 local old_place = entity_places [entity_primary ]
52575238
5258- local new_chunk = __chunk_with_fragment (old_chunk , fragment )
5239+ local new_chunk = __chunk_with_fragment (old_chunk or nil , fragment )
52595240
52605241 __evolved_defer ()
52615242
5262- if old_chunk == new_chunk then
5243+ if old_chunk and old_chunk == new_chunk then
52635244 local old_component_indices = old_chunk .__component_indices
52645245 local old_component_storages = old_chunk .__component_storages
52655246
@@ -5479,16 +5460,11 @@ function __evolved_remove(entity, ...)
54795460 local old_chunk = entity_chunks [entity_primary ]
54805461 local old_place = entity_places [entity_primary ]
54815462
5482- local new_chunk = __chunk_without_fragments (old_chunk , ... )
5483-
5484- if old_chunk == new_chunk then
5485- -- nothing to remove
5486- return
5487- end
5463+ local new_chunk = __chunk_without_fragments (old_chunk or nil , ... )
54885464
54895465 __evolved_defer ()
54905466
5491- do
5467+ if old_chunk and old_chunk ~= new_chunk then
54925468 local old_fragment_list = old_chunk .__fragment_list
54935469 local old_fragment_count = old_chunk .__fragment_count
54945470 local old_component_indices = old_chunk .__component_indices
@@ -5550,8 +5526,8 @@ function __evolved_remove(entity, ...)
55505526 do
55515527 __detach_entity (old_chunk , old_place )
55525528
5553- entity_chunks [entity_primary ] = new_chunk
5554- entity_places [entity_primary ] = new_chunk and new_chunk .__entity_count
5529+ entity_chunks [entity_primary ] = new_chunk or false
5530+ entity_places [entity_primary ] = new_chunk and new_chunk .__entity_count or 0
55555531
55565532 __structural_changes = __structural_changes + 1
55575533 end
@@ -6267,8 +6243,8 @@ function __evolved_collect_garbage(no_shrink)
62676243 end
62686244
62696245 do
6270- __entity_chunks = __table_dup (__entity_chunks )
6271- __entity_places = __table_dup (__entity_places )
6246+ __entity_chunks = __list_dup (__entity_chunks , __acquired_count )
6247+ __entity_places = __list_dup (__entity_places , __acquired_count )
62726248 end
62736249
62746250 do
0 commit comments