From d40bcd0c7246733a94ce93ca02177be5fea6dcf1 Mon Sep 17 00:00:00 2001 From: Ukendio Date: Fri, 4 Jul 2025 01:44:15 +0200 Subject: [PATCH] Fix benchmark of remove --- CHANGELOG.md | 14 ++++++++++++++ benches/visual/remove.bench.luau | 9 +++++---- jecs.luau | 18 ++++++++++++++++-- test/tests.luau | 4 ---- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b880f62..6962031 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,20 @@ ## Unreleased +### Added +- `jecs.Exclusive` trait for making exclusive relationships. + +### Changed +- `jecs.Child` to be an exclusive relationship, which means you can only have one `ChildOf` pair on an entity. + +## 0.7.2 +### Added +- `jecs.entity_index_try_get_fast` back as to not break the observer addon. + +### Fixed +- A linting problem with the types for `quer:with` and `query:without`. + + ## 0.7.0 ### Added diff --git a/benches/visual/remove.bench.luau b/benches/visual/remove.bench.luau index b62a64b..72b94fa 100755 --- a/benches/visual/remove.bench.luau +++ b/benches/visual/remove.bench.luau @@ -35,16 +35,17 @@ return { Mirror = function() local m = mcs:entity() for i = 1, 100 do - mcs:add(m, pair(E4, E4)) - mcs:add(m, pair(E4, E4)) + mcs:add(m, pair(E2, E3)) + mcs:remove(m, pair(E2, E3)) + mcs:add(m, pair(E2, E4)) end end, Jecs = function() local j = ecs:entity() for i = 1, 100 do - ecs:add(j, pair(C4, C4)) - ecs:add(j, pair(C4, C4)) + ecs:add(j, pair(C2, C3)) + ecs:add(j, pair(C2, C4)) end end, }, diff --git a/jecs.luau b/jecs.luau index d26384b..ba8cf3a 100755 --- a/jecs.luau +++ b/jecs.luau @@ -311,9 +311,9 @@ end local function entity_index_try_get_any( entity_index: EntityIndex, - entity: number + entity: Entity ): Record? - local r = entity_index.sparse_array[ECS_ENTITY_T_LO(entity)] + local r = entity_index.sparse_array[ECS_ENTITY_T_LO(entity::number)] if not r or r.dense == 0 then return nil @@ -336,6 +336,20 @@ local function entity_index_try_get(entity_index: EntityIndex, entity: Entity): return r end +local function entity_index_try_get_fast(entity_index: EntityIndex, entity: Entity): Record? + local r = entity_index_try_get_any(entity_index, entity) + if r then + local r_dense = r.dense + -- if r_dense > entity_index.alive_count then + -- return nil + -- end + if entity_index.dense_array[r_dense] ~= entity then + return nil + end + end + return r +end + local function entity_index_is_alive(entity_index: EntityIndex, entity: Entity): boolean return entity_index_try_get(entity_index, entity) ~= nil end diff --git a/test/tests.luau b/test/tests.luau index 005d785..3f9ceb9 100755 --- a/test/tests.luau +++ b/test/tests.luau @@ -24,10 +24,6 @@ type Id = jecs.Id local entity_visualiser = require("@tools/entity_visualiser") local dwi = entity_visualiser.stringify -TEST("exclusive", function() - -- print(jecs.entity_index_try_get(world.entity_index, e).archetype.type) -end) - TEST("bulk", function() local world = jecs.world() local A = world:component()