mirror of
https://github.com/Ukendio/jecs.git
synced 2025-09-23 08:39:16 +00:00
Compare commits
1 commit
3ee7dbc8cb
...
fb8f8bddc1
Author | SHA1 | Date | |
---|---|---|---|
|
fb8f8bddc1 |
3 changed files with 24 additions and 80 deletions
|
@ -160,10 +160,6 @@ local function monitors_new<T...>(
|
|||
end
|
||||
|
||||
local function removed(entity: jecs.Entity, component: jecs.Id)
|
||||
local r = jecs.record(world, entity)
|
||||
if not archetypes[r.archetype.id] then
|
||||
return
|
||||
end
|
||||
local EcsOnRemove = jecs.OnRemove :: jecs.Id
|
||||
if callback ~= nil then
|
||||
callback(entity, EcsOnRemove)
|
||||
|
|
88
jecs.luau
88
jecs.luau
|
@ -1088,6 +1088,18 @@ local function archetype_traverse_add(
|
|||
return to
|
||||
end
|
||||
|
||||
local function world_component(world: world): i53
|
||||
local id = (world.max_component_id :: number) + 1
|
||||
if id > HI_COMPONENT_ID then
|
||||
-- IDs are partitioned into ranges because component IDs are not nominal,
|
||||
-- so it needs to error when IDs intersect into the entity range.
|
||||
error("Too many components, consider using world:entity() instead to create components.")
|
||||
end
|
||||
world.max_component_id = id
|
||||
|
||||
return id
|
||||
end
|
||||
|
||||
local function archetype_fast_delete_last(columns: { Column }, column_count: number)
|
||||
for i, column in columns do
|
||||
if column ~= NULL_ARRAY then
|
||||
|
@ -1325,9 +1337,6 @@ local function query_iter_init(query: QueryInner): () -> (number, ...any)
|
|||
|
||||
entities = archetype.entities
|
||||
i = #entities
|
||||
if i == 0 then
|
||||
continue
|
||||
end
|
||||
entity = entities[i]
|
||||
columns_map = archetype.columns_map
|
||||
a = columns_map[A]
|
||||
|
@ -1350,9 +1359,6 @@ local function query_iter_init(query: QueryInner): () -> (number, ...any)
|
|||
|
||||
entities = archetype.entities
|
||||
i = #entities
|
||||
if i == 0 then
|
||||
continue
|
||||
end
|
||||
entity = entities[i]
|
||||
columns_map = archetype.columns_map
|
||||
a = columns_map[A]
|
||||
|
@ -1376,9 +1382,6 @@ local function query_iter_init(query: QueryInner): () -> (number, ...any)
|
|||
|
||||
entities = archetype.entities
|
||||
i = #entities
|
||||
if i == 0 then
|
||||
continue
|
||||
end
|
||||
entity = entities[i]
|
||||
columns_map = archetype.columns_map
|
||||
a = columns_map[A]
|
||||
|
@ -1403,9 +1406,6 @@ local function query_iter_init(query: QueryInner): () -> (number, ...any)
|
|||
|
||||
entities = archetype.entities
|
||||
i = #entities
|
||||
if i == 0 then
|
||||
continue
|
||||
end
|
||||
entity = entities[i]
|
||||
columns_map = archetype.columns_map
|
||||
a = columns_map[A]
|
||||
|
@ -1431,9 +1431,6 @@ local function query_iter_init(query: QueryInner): () -> (number, ...any)
|
|||
|
||||
entities = archetype.entities
|
||||
i = #entities
|
||||
if i == 0 then
|
||||
continue
|
||||
end
|
||||
entity = entities[i]
|
||||
columns_map = archetype.columns_map
|
||||
a = columns_map[A]
|
||||
|
@ -1460,9 +1457,6 @@ local function query_iter_init(query: QueryInner): () -> (number, ...any)
|
|||
|
||||
entities = archetype.entities
|
||||
i = #entities
|
||||
if i == 0 then
|
||||
continue
|
||||
end
|
||||
entity = entities[i]
|
||||
columns_map = archetype.columns_map
|
||||
a = columns_map[A]
|
||||
|
@ -1490,9 +1484,6 @@ local function query_iter_init(query: QueryInner): () -> (number, ...any)
|
|||
|
||||
entities = archetype.entities
|
||||
i = #entities
|
||||
if i == 0 then
|
||||
continue
|
||||
end
|
||||
entity = entities[i]
|
||||
columns_map = archetype.columns_map
|
||||
a = columns_map[A]
|
||||
|
@ -1521,9 +1512,6 @@ local function query_iter_init(query: QueryInner): () -> (number, ...any)
|
|||
|
||||
entities = archetype.entities
|
||||
i = #entities
|
||||
if i == 0 then
|
||||
continue
|
||||
end
|
||||
entity = entities[i]
|
||||
columns_map = archetype.columns_map
|
||||
a = columns_map[A]
|
||||
|
@ -1555,9 +1543,6 @@ local function query_iter_init(query: QueryInner): () -> (number, ...any)
|
|||
|
||||
entities = archetype.entities
|
||||
i = #entities
|
||||
if i == 0 then
|
||||
continue
|
||||
end
|
||||
entity = entities[i]
|
||||
columns_map = archetype.columns_map
|
||||
a = columns_map[A]
|
||||
|
@ -1725,9 +1710,6 @@ local function query_cached(query: QueryInner)
|
|||
|
||||
entities = archetype.entities
|
||||
i = #entities
|
||||
if i == 0 then
|
||||
continue
|
||||
end
|
||||
entity = entities[i]
|
||||
columns_map = archetype.columns_map
|
||||
a = columns_map[A]
|
||||
|
@ -1750,9 +1732,6 @@ local function query_cached(query: QueryInner)
|
|||
|
||||
entities = archetype.entities
|
||||
i = #entities
|
||||
if i == 0 then
|
||||
continue
|
||||
end
|
||||
entity = entities[i]
|
||||
columns_map = archetype.columns_map
|
||||
a = columns_map[A]
|
||||
|
@ -1776,9 +1755,6 @@ local function query_cached(query: QueryInner)
|
|||
|
||||
entities = archetype.entities
|
||||
i = #entities
|
||||
if i == 0 then
|
||||
continue
|
||||
end
|
||||
entity = entities[i]
|
||||
columns_map = archetype.columns_map
|
||||
a = columns_map[A]
|
||||
|
@ -1803,9 +1779,6 @@ local function query_cached(query: QueryInner)
|
|||
|
||||
entities = archetype.entities
|
||||
i = #entities
|
||||
if i == 0 then
|
||||
continue
|
||||
end
|
||||
entity = entities[i]
|
||||
columns_map = archetype.columns_map
|
||||
a = columns_map[A]
|
||||
|
@ -1890,10 +1863,6 @@ local function query_cached(query: QueryInner)
|
|||
|
||||
entities = archetype.entities
|
||||
i = #entities
|
||||
if i == 0 then
|
||||
continue
|
||||
end
|
||||
entity = entities[i]
|
||||
columns_map = archetype.columns_map
|
||||
a = columns_map[A]
|
||||
b = columns_map[B]
|
||||
|
@ -1921,9 +1890,6 @@ local function query_cached(query: QueryInner)
|
|||
|
||||
entities = archetype.entities
|
||||
i = #entities
|
||||
if i == 0 then
|
||||
continue
|
||||
end
|
||||
entity = entities[i]
|
||||
columns_map = archetype.columns_map
|
||||
a = columns_map[A]
|
||||
|
@ -1955,9 +1921,6 @@ local function query_cached(query: QueryInner)
|
|||
|
||||
entities = archetype.entities
|
||||
i = #entities
|
||||
if i == 0 then
|
||||
continue
|
||||
end
|
||||
entity = entities[i]
|
||||
columns_map = archetype.columns_map
|
||||
a = columns_map[A]
|
||||
|
@ -2197,10 +2160,6 @@ local function world_new()
|
|||
removed = {} :: Signal
|
||||
}
|
||||
|
||||
-- We need to cache the moment the world is registered, that way
|
||||
-- `world:component` will not pollute the global registration of components.
|
||||
local max_component_id = ecs_max_component_id
|
||||
|
||||
local world = {
|
||||
archetype_edges = archetype_edges,
|
||||
|
||||
|
@ -3178,19 +3137,6 @@ local function world_new()
|
|||
world.archetype_index = new_archetype_map
|
||||
end
|
||||
|
||||
local function world_component(world: world): i53
|
||||
max_component_id += 1
|
||||
if max_component_id > HI_COMPONENT_ID then
|
||||
-- IDs are partitioned into ranges because component IDs are not nominal,
|
||||
-- so it needs to error when IDs intersect into the entity range.
|
||||
error("Too many components, consider using world:entity() instead to create components.")
|
||||
end
|
||||
world.max_component_id = max_component_id
|
||||
inner_world_add(world, max_component_id, EcsComponent)
|
||||
|
||||
return max_component_id
|
||||
end
|
||||
|
||||
world.entity = inner_world_entity
|
||||
world.query = world_query :: any
|
||||
world.remove = inner_world_remove
|
||||
|
@ -3210,12 +3156,14 @@ local function world_new()
|
|||
world.children = world_children
|
||||
world.range = world_range
|
||||
|
||||
for i = 1, EcsRest do
|
||||
entity_index_new_id(entity_index)
|
||||
for i = 1, HI_COMPONENT_ID do
|
||||
local e = entity_index_new_id(entity_index)
|
||||
inner_world_add(world, e, EcsComponent)
|
||||
end
|
||||
|
||||
for i = 1, max_component_id do
|
||||
inner_world_add(world, i, EcsComponent)
|
||||
for i = HI_COMPONENT_ID + 1, EcsRest do
|
||||
-- Initialize built-in components
|
||||
entity_index_new_id(entity_index)
|
||||
end
|
||||
|
||||
inner_world_add(world, EcsName, EcsComponent)
|
||||
|
|
|
@ -335,11 +335,11 @@ TEST("bulk", function()
|
|||
do CASE "Should bulk add with hooks moving archetypes without previous"
|
||||
local world = jecs.world()
|
||||
local c1, c2, c3 = world:component(), world:component(), world:component()
|
||||
|
||||
|
||||
world:added(c1, function(e)
|
||||
world:set(e, c3, "hello")
|
||||
end)
|
||||
|
||||
|
||||
local e = world:entity()
|
||||
jecs.bulk_insert(world, e, {c1,c2}, {true, 123})
|
||||
CHECK(world:get(e, c1) == true)
|
||||
|
@ -350,11 +350,11 @@ TEST("bulk", function()
|
|||
do CASE "Should bulk add with hooks moving archetypes with previous"
|
||||
local world = jecs.world()
|
||||
local c1, c2, c3 = world:component(), world:component(), world:component()
|
||||
|
||||
|
||||
world:added(c1, function(e)
|
||||
world:set(e, c3, "hello")
|
||||
end)
|
||||
|
||||
|
||||
local e = world:entity()
|
||||
world:add(e, world:entity())
|
||||
jecs.bulk_insert(world, e, {c1,c2}, {true, 123})
|
||||
|
@ -550,9 +550,9 @@ TEST("world:add()", function()
|
|||
end)
|
||||
|
||||
TEST("world:children()", function()
|
||||
local world = jecs.world()
|
||||
local C = jecs.component()
|
||||
local T = jecs.tag()
|
||||
local world = jecs.world()
|
||||
|
||||
local e1 = world:entity()
|
||||
world:set(e1, C, true)
|
||||
|
@ -2510,7 +2510,7 @@ TEST("#repro2", function()
|
|||
local entity = world:entity()
|
||||
world:set(entity, pair(Lifetime, Particle), 1)
|
||||
world:set(entity, pair(Lifetime, Beam), 2)
|
||||
world:set(entity, pair(world:component(), world:component()), 6) -- noise
|
||||
world:set(entity, pair(4 :: any, 5 :: any), 6) -- noise
|
||||
|
||||
CHECK(world:get(entity, pair(Lifetime, Particle)) == 1)
|
||||
CHECK(world:get(entity, pair(Lifetime, Beam)) == 2)
|
||||
|
|
Loading…
Reference in a new issue