@@ -1437,19 +1437,24 @@ local function world_delete(world: ecs_world_t, entity: i53)
14371437 end
14381438
14391439 local dense_array = entity_index .dense_array
1440- local index_of_deleted_entity = record .dense
1441- local index_of_last_alive_entity = entity_index .alive_count
1442- entity_index .alive_count = index_of_last_alive_entity - 1
1440+ local dense = record .dense
1441+ local i_swap = entity_index .alive_count
1442+ entity_index .alive_count = i_swap - 1
14431443
1444- local last_alive_entity = dense_array [index_of_last_alive_entity ]
1445- local r_swap = entity_index_try_get_any (entity_index , last_alive_entity ) :: ecs_record_t
1446- r_swap .dense = index_of_deleted_entity
1444+ local e_swap = dense_array [i_swap ]
1445+ local r_swap = entity_index_try_get_any (entity_index , e_swap ) :: ecs_record_t
1446+
1447+ r_swap .dense = dense
14471448 record .archetype = nil :: any
14481449 record .row = nil :: any
1449- record .dense = index_of_last_alive_entity
1450+ record .dense = i_swap
1451+
1452+ dense_array [dense ] = e_swap
1453+ dense_array [i_swap ] = ECS_GENERATION_INC (entity )
1454+ end
14501455
1451- dense_array [ index_of_deleted_entity ] = last_alive_entity
1452- dense_array [ index_of_last_alive_entity ] = ECS_GENERATION_INC ( entity )
1456+ local function world_exists ( world , ecs_world_t , entity ): boolean
1457+ return entity_index_try_get_any ( world . entity_index , entity ) ~= nil
14531458end
14541459
14551460local function world_contains (world : ecs_world_t , entity ): boolean
@@ -2443,6 +2448,7 @@ World.has = world_has
24432448World .target = world_target
24442449World .parent = world_parent
24452450World .contains = world_contains
2451+ World .exists = world_exists
24462452World .cleanup = world_cleanup
24472453World .each = world_each
24482454World .children = world_children
@@ -2610,6 +2616,9 @@ export type World = {
26102616 --- Checks if the world contains the given entity
26112617 contains : (self : World , entity : Entity ) -> boolean ,
26122618
2619+ --- Checks if the entity exists
2620+ exists : (self : World , entity : Entity ) -> boolean ,
2621+
26132622 each : <T >(self : World , id : Id <T >) -> () -> Entity ,
26142623
26152624 children : <T >(self : World , id : Id <T >) -> () -> Entity ,
0 commit comments