Add backwards relation to edges
Some checks are pending
analysis / Run Luau Analyze (push) Waiting to run
deploy-docs / build (push) Waiting to run
deploy-docs / Deploy (push) Blocked by required conditions
publish-npm / publish (push) Waiting to run
unit-testing / Run Luau Tests (push) Waiting to run

This commit is contained in:
Ukendio 2025-07-13 05:15:37 +02:00
parent c67dfcbd24
commit f6731069aa
2 changed files with 49 additions and 7 deletions

View file

@ -1052,14 +1052,15 @@ local function archetype_destroy(world: World, archetype: Archetype)
local component_index = world.component_index
local archetype_edges = world.archetype_edges
for id, edge in archetype_edges[archetype.id] do
archetype_edges[edge.id][id] = nil
local edges = archetype_edges[archetype.id]
for id, node in edges do
archetype_edges[node.id][id] = nil
edges[id] = nil
end
local archetype_id = archetype.id
world.archetypes[archetype_id] = nil :: any
world.archetype_index[archetype.type] = nil :: any
-- world.archetypes[archetype_id] = nil :: any
-- world.archetype_index[archetype.type] = nil :: any
local columns_map = archetype.columns_map
for id in columns_map do
@ -2330,6 +2331,8 @@ local function world_new()
else
if to.dead then
archetype_register(world, to)
edge[id] = to
archetype_edges[to.id][id] = src
to.dead = false
end
idr = component_index[id]
@ -2539,6 +2542,7 @@ local function world_new()
idr = component_index[id]
end
edge[id] = to
archetype_edges[to.id][id] = src
else
idr = component_index[id]
end

View file

@ -24,8 +24,46 @@ type Id<T=unknown> = jecs.Id<T>
local entity_visualiser = require("@tools/entity_visualiser")
local dwi = entity_visualiser.stringify
FOCUS()
TEST("", function()
TEST("repeated pairs", function()
local pair = jecs.pair
local world = jecs.world()
local rel = world:component() -- Does not error if this is just a tag
-- Does not happen if we delete manually instead of using this
world:add(rel, pair(jecs.OnDeleteTarget, jecs.Delete))
local t1 = world:entity()
local p1 = pair(rel, t1)
local e1 = world:entity()
world:set(e1, p1, true)
CHECK(world:get(e1, p1))
CHECK(world:each(p1)() == e1)
world:delete(t1)
local t2 = world:entity()
local p2 = pair(rel, t2)
local e2 = world:entity()
print("-----")
world:set(e2, p2, true)
CHECK(world:get(e2, p2))
CHECK(p1 == p2)
local count = 0
CHECK(world:has(e2, p2))
for _ in world:query(p2) do
count += 1
end
CHECK(count == 1)
CHECK(world:each(p2)() == e2) -- Fails
end)
TEST("repro", function()
local world = jecs.world()
local data = world:component()
local relation = world:component()