mirror of
https://github.com/Ukendio/jecs.git
synced 2025-08-04 19:29:18 +00:00
Compare commits
No commits in common. "78fe5338cf911ade648ebc0bf59aff0d40428aac" and "d99088ea1eadeccbd89058cc5934e2c7f4d76b7a" have entirely different histories.
78fe5338cf
...
d99088ea1e
4 changed files with 37 additions and 85 deletions
96
jecs.luau
96
jecs.luau
|
@ -2320,61 +2320,38 @@ local function world_new()
|
||||||
local to: Archetype
|
local to: Archetype
|
||||||
local idr: ComponentRecord
|
local idr: ComponentRecord
|
||||||
if ECS_IS_PAIR(id::number) then
|
if ECS_IS_PAIR(id::number) then
|
||||||
local first = ECS_PAIR_FIRST(id::number)
|
|
||||||
local wc = ECS_PAIR(first, EcsWildcard)
|
|
||||||
idr = component_index[wc]
|
|
||||||
|
|
||||||
local edge = archetype_edges[src.id]
|
local edge = archetype_edges[src.id]
|
||||||
to = edge[id]
|
to = edge[id]
|
||||||
if to == nil then
|
if not to then
|
||||||
if idr and (bit32.btest(idr.flags) == true) then
|
local first = ECS_PAIR_FIRST(id::number)
|
||||||
|
local wc = ECS_PAIR(first, EcsWildcard)
|
||||||
|
idr = component_index[wc]
|
||||||
|
if idr and bit32.btest(idr.flags, ECS_ID_IS_EXCLUSIVE) then
|
||||||
local cr = idr.records[src.id]
|
local cr = idr.records[src.id]
|
||||||
if cr then
|
if cr then
|
||||||
local on_remove = idr.on_remove
|
local on_remove = idr.on_remove
|
||||||
local id_types = src.types
|
local id_types = src.types
|
||||||
if on_remove then
|
if on_remove then
|
||||||
on_remove(entity, id_types[cr])
|
on_remove(entity, id_types[cr])
|
||||||
|
|
||||||
src = record.archetype
|
src = record.archetype
|
||||||
id_types = src.types
|
id_types = src.types
|
||||||
cr = idr.records[src.id]
|
cr = idr.records[src.id]
|
||||||
end
|
end
|
||||||
|
|
||||||
local dst = table.clone(id_types)
|
local dst = table.clone(id_types)
|
||||||
dst[cr] = id
|
dst[cr] = id
|
||||||
to = archetype_ensure(world, dst)
|
to = archetype_ensure(world, dst)
|
||||||
|
else
|
||||||
|
to = find_archetype_with(world, id, src)
|
||||||
|
idr = component_index[id]
|
||||||
end
|
end
|
||||||
end
|
else
|
||||||
|
|
||||||
if not to then
|
|
||||||
to = find_archetype_with(world, id, src)
|
to = find_archetype_with(world, id, src)
|
||||||
if not idr then
|
idr = component_index[id]
|
||||||
idr = component_index[wc]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
edge[id] = to
|
edge[id] = to
|
||||||
archetype_edges[(to :: Archetype).id][id] = src
|
archetype_edges[to.id][id] = src
|
||||||
else
|
else
|
||||||
if bit32.btest(idr.flags, ECS_ID_IS_EXCLUSIVE) then
|
idr = component_index[id]
|
||||||
local cr = idr.records[src.id]
|
|
||||||
if cr then
|
|
||||||
local on_remove = idr.on_remove
|
|
||||||
local id_types = src.types
|
|
||||||
if on_remove then
|
|
||||||
on_remove(entity, id_types[cr])
|
|
||||||
src = record.archetype
|
|
||||||
id_types = src.types
|
|
||||||
cr = idr.records[src.id]
|
|
||||||
end
|
|
||||||
local dst = table.clone(id_types)
|
|
||||||
dst[cr] = id
|
|
||||||
to = archetype_ensure(world, dst)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if not to then
|
|
||||||
to = find_archetype_with(world, id, src)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local edges = archetype_edges
|
local edges = archetype_edges
|
||||||
|
@ -2424,63 +2401,39 @@ local function world_new()
|
||||||
end
|
end
|
||||||
local to: Archetype
|
local to: Archetype
|
||||||
local idr: ComponentRecord
|
local idr: ComponentRecord
|
||||||
|
|
||||||
if ECS_IS_PAIR(id::number) then
|
if ECS_IS_PAIR(id::number) then
|
||||||
local first = ECS_PAIR_FIRST(id::number)
|
|
||||||
local wc = ECS_PAIR(first, EcsWildcard)
|
|
||||||
idr = component_index[wc]
|
|
||||||
|
|
||||||
local edge = archetype_edges[src.id]
|
local edge = archetype_edges[src.id]
|
||||||
to = edge[id]
|
to = edge[id]
|
||||||
if to == nil then
|
if not to then
|
||||||
if idr and (bit32.btest(idr.flags) == true) then
|
local first = ECS_PAIR_FIRST(id::number)
|
||||||
|
local wc = ECS_PAIR(first, EcsWildcard)
|
||||||
|
idr = component_index[wc]
|
||||||
|
if idr and bit32.btest(idr.flags, ECS_ID_IS_EXCLUSIVE) then
|
||||||
local cr = idr.records[src.id]
|
local cr = idr.records[src.id]
|
||||||
if cr then
|
if cr then
|
||||||
local on_remove = idr.on_remove
|
local on_remove = idr.on_remove
|
||||||
local id_types = src.types
|
local id_types = src.types
|
||||||
if on_remove then
|
if on_remove then
|
||||||
on_remove(entity, id_types[cr])
|
on_remove(entity, id_types[cr])
|
||||||
|
|
||||||
src = record.archetype
|
src = record.archetype
|
||||||
id_types = src.types
|
id_types = src.types
|
||||||
cr = idr.records[src.id]
|
cr = idr.records[src.id]
|
||||||
end
|
end
|
||||||
|
|
||||||
local dst = table.clone(id_types)
|
local dst = table.clone(id_types)
|
||||||
dst[cr] = id
|
dst[cr] = id
|
||||||
to = archetype_ensure(world, dst)
|
to = archetype_ensure(world, dst)
|
||||||
|
else
|
||||||
|
to = find_archetype_with(world, id, src)
|
||||||
|
idr = component_index[id]
|
||||||
end
|
end
|
||||||
end
|
else
|
||||||
|
|
||||||
if not to then
|
|
||||||
to = find_archetype_with(world, id, src)
|
to = find_archetype_with(world, id, src)
|
||||||
if not idr then
|
idr = component_index[id]
|
||||||
idr = component_index[wc]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
edge[id] = to
|
edge[id] = to
|
||||||
archetype_edges[(to :: Archetype).id][id] = src
|
archetype_edges[to.id][id] = src
|
||||||
else
|
else
|
||||||
if bit32.btest(idr.flags, ECS_ID_IS_EXCLUSIVE) then
|
idr = component_index[id]
|
||||||
local cr = idr.records[src.id]
|
|
||||||
if cr then
|
|
||||||
local on_remove = idr.on_remove
|
|
||||||
local id_types = src.types
|
|
||||||
if on_remove then
|
|
||||||
on_remove(entity, id_types[cr])
|
|
||||||
src = record.archetype
|
|
||||||
id_types = src.types
|
|
||||||
cr = idr.records[src.id]
|
|
||||||
end
|
|
||||||
local dst = table.clone(id_types)
|
|
||||||
dst[cr] = id
|
|
||||||
to = archetype_ensure(world, dst)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if not to then
|
|
||||||
to = find_archetype_with(world, id, src)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local edges = archetype_edges
|
local edges = archetype_edges
|
||||||
|
@ -3151,7 +3104,6 @@ return {
|
||||||
ECS_GENERATION_INC = ECS_GENERATION_INC,
|
ECS_GENERATION_INC = ECS_GENERATION_INC,
|
||||||
ECS_GENERATION = ECS_GENERATION,
|
ECS_GENERATION = ECS_GENERATION,
|
||||||
ECS_ID_IS_WILDCARD = ECS_ID_IS_WILDCARD,
|
ECS_ID_IS_WILDCARD = ECS_ID_IS_WILDCARD,
|
||||||
ECS_ID_IS_EXCLUSIVE = ECS_ID_IS_EXCLUSIVE,
|
|
||||||
ECS_ID_DELETE = ECS_ID_DELETE,
|
ECS_ID_DELETE = ECS_ID_DELETE,
|
||||||
ECS_META_RESET = ECS_META_RESET,
|
ECS_META_RESET = ECS_META_RESET,
|
||||||
ECS_COMBINE = ECS_COMBINE,
|
ECS_COMBINE = ECS_COMBINE,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@rbxts/jecs",
|
"name": "@rbxts/jecs",
|
||||||
"version": "0.9.0-rc.3",
|
"version": "0.9.0-rc.2",
|
||||||
"description": "Stupidly fast Entity Component System",
|
"description": "Stupidly fast Entity Component System",
|
||||||
"main": "jecs.luau",
|
"main": "jecs.luau",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
@ -346,12 +346,23 @@ TEST("world:add()", function()
|
||||||
world:add(A, jecs.Exclusive)
|
world:add(A, jecs.Exclusive)
|
||||||
local on_remove_call = false
|
local on_remove_call = false
|
||||||
world:set(A, jecs.OnRemove, function(e, id)
|
world:set(A, jecs.OnRemove, function(e, id)
|
||||||
|
CHECK(e == e_ptr)
|
||||||
|
CHECK(id == jecs.pair(A, B))
|
||||||
on_remove_call = true
|
on_remove_call = true
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local on_add_call_count = 0
|
local on_add_call_count = 0
|
||||||
world:set(A, jecs.OnAdd, function(e, id)
|
world:set(A, jecs.OnAdd, function(e, id)
|
||||||
on_add_call_count += 1
|
on_add_call_count += 1
|
||||||
|
if on_add_call_count == 1 then
|
||||||
|
CHECK(e == e_ptr)
|
||||||
|
CHECK(id == jecs.pair(A, B))
|
||||||
|
elseif on_add_call_count == 2 then
|
||||||
|
CHECK(e == e_ptr)
|
||||||
|
CHECK(id == jecs.pair(A, C))
|
||||||
|
else
|
||||||
|
CHECK(false)
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
@ -366,17 +377,6 @@ TEST("world:add()", function()
|
||||||
CHECK(world:has(e, pair(A, B)) == false)
|
CHECK(world:has(e, pair(A, B)) == false)
|
||||||
CHECK(world:has(e, pair(A, C)) == true)
|
CHECK(world:has(e, pair(A, C)) == true)
|
||||||
|
|
||||||
-- We have to ensure that it actually invokes hooks everytime it
|
|
||||||
-- traverses the archetype
|
|
||||||
e = world:entity()
|
|
||||||
world:add(e, pair(A, B))
|
|
||||||
CHECK(on_add_call_count == 3)
|
|
||||||
world:add(e, pair(A, C))
|
|
||||||
CHECK(on_add_call_count == 4)
|
|
||||||
CHECK(on_remove_call)
|
|
||||||
|
|
||||||
CHECK(world:has(e, pair(A, B)) == false)
|
|
||||||
CHECK(world:has(e, pair(A, C)) == true)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
do CASE "idempotent"
|
do CASE "idempotent"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "ukendio/jecs"
|
name = "ukendio/jecs"
|
||||||
version = "0.9.0-rc.3"
|
version = "0.9.0-rc.2"
|
||||||
registry = "https://github.com/UpliftGames/wally-index"
|
registry = "https://github.com/UpliftGames/wally-index"
|
||||||
realm = "shared"
|
realm = "shared"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
Loading…
Reference in a new issue