-
Notifications
You must be signed in to change notification settings - Fork 66
fix world_delete #293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix world_delete #293
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3497,10 +3497,14 @@ local function world_new(DEBUG: boolean?) | |
| end | ||
| if idr_t then | ||
| local archetype_ids = idr_t.records | ||
| local to_remove = {} | ||
|
|
||
| for archetype_id in archetype_ids do | ||
| local idr_t_archetype = archetypes[archetype_id] | ||
| local idr_t_types = idr_t_archetype.types | ||
| local entities = idr_t_archetype.entities | ||
| local should_delete = false | ||
| local remove_count = 0 | ||
|
|
||
| for _, id in idr_t_types do | ||
| if not ECS_IS_PAIR(id) then | ||
|
|
@@ -3515,27 +3519,56 @@ local function world_new(DEBUG: boolean?) | |
| local flags = id_record.flags | ||
| local flags_delete_mask = bit32.btest(flags, ECS_ID_DELETE) | ||
| if flags_delete_mask then | ||
| for i = #entities, 1, -1 do | ||
| local child = entities[i] | ||
| world_delete(world, child) | ||
| end | ||
| should_delete = true | ||
| break | ||
| else | ||
| local on_remove = id_record.on_remove | ||
| to_remove[id] = id_record | ||
| remove_count += 1 | ||
| end | ||
| end | ||
|
|
||
| local to = archetype_traverse_remove(world, id, idr_t_archetype) | ||
| for i = #entities, 1, -1 do | ||
| if should_delete then | ||
| for i = #entities, 1, -1 do | ||
| local child = entities[i] | ||
| world_delete(world, child) | ||
| end | ||
| else | ||
| if remove_count == 1 then | ||
| local id, id_record = next(to_remove) | ||
| local to = archetype_traverse_remove(world, id :: i53, idr_t_archetype) | ||
| local on_remove = (id_record :: componentrecord).on_remove | ||
| for i = #entities, 1, -1 do | ||
|
||
| local child = entities[i] | ||
| if on_remove then | ||
| on_remove(child, id) | ||
| on_remove(child, id :: i53) | ||
|
||
| end | ||
|
|
||
| local r = entity_index_try_get_unsafe(child) :: record | ||
| inner_entity_move(child, r, to) | ||
| end | ||
| end | ||
| end | ||
| elseif remove_count > 1 then | ||
| local dst_types = table.clone(idr_t_types) | ||
| for id, record in to_remove do | ||
| table.remove(dst_types, table.find(dst_types, id)) | ||
|
|
||
| local on_remove = record.on_remove | ||
|
||
| if on_remove then | ||
| for _, child in entities do | ||
| on_remove(child, id :: i53) | ||
|
||
| end | ||
| end | ||
| end | ||
|
|
||
| local to = archetype_ensure(world, dst_types) | ||
| for i = #entities, 1, -1 do | ||
| local child = entities[i] | ||
| local r = entity_index_try_get_unsafe(child) :: record | ||
| inner_entity_move(child, r, to) | ||
| end | ||
| end | ||
| end | ||
|
||
|
|
||
| table.clear(to_remove) | ||
| archetype_destroy(world, idr_t_archetype) | ||
| end | ||
| end | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type this as
{ [i53]: componentrecord}