mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-24 17:10:03 +00:00
Optimize world:has and improve type annotations
This commit is contained in:
parent
4c958071e0
commit
447bb76bb8
4 changed files with 17 additions and 10 deletions
2
.luaurc
2
.luaurc
|
@ -4,7 +4,7 @@
|
||||||
"testkit": "tools/testkit",
|
"testkit": "tools/testkit",
|
||||||
"mirror": "mirror",
|
"mirror": "mirror",
|
||||||
"tools": "tools",
|
"tools": "tools",
|
||||||
"addons": "addons",
|
"addons": "addons"
|
||||||
},
|
},
|
||||||
"languageMode": "strict"
|
"languageMode": "strict"
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,8 @@ The format is based on [Keep a Changelog][kac], and this project adheres to
|
||||||
- This should allow a more lenient window for modifying data
|
- This should allow a more lenient window for modifying data
|
||||||
- Changed `OnRemove` to lazily lookup which archetype the entity will move to
|
- Changed `OnRemove` to lazily lookup which archetype the entity will move to
|
||||||
- Can now have interior structural changes within `OnRemove` hooks
|
- Can now have interior structural changes within `OnRemove` hooks
|
||||||
|
- Optimized `world:has` for both single component and multiple component presence.
|
||||||
|
- This comes at the cost that it cannot check the component presence for more than 4 components at a time. If this is important, consider calling to this function multiple times.
|
||||||
|
|
||||||
## [0.5.0] - 2024-12-26
|
## [0.5.0] - 2024-12-26
|
||||||
|
|
||||||
|
|
16
jecs.luau
16
jecs.luau
|
@ -466,7 +466,9 @@ local function world_has_one_inline(world: ecs_world_t, entity: i53, id: i53): b
|
||||||
return records[id] ~= nil
|
return records[id] ~= nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local function world_has(world: ecs_world_t, entity: i53, ...: i53): boolean
|
local function world_has(world: ecs_world_t, entity: i53,
|
||||||
|
a: i53, b: i53?, c: i53?, d: i53?, e: i53?): boolean
|
||||||
|
|
||||||
local record = entity_index_try_get_fast(world.entity_index, entity)
|
local record = entity_index_try_get_fast(world.entity_index, entity)
|
||||||
if not record then
|
if not record then
|
||||||
return false
|
return false
|
||||||
|
@ -479,13 +481,11 @@ local function world_has(world: ecs_world_t, entity: i53, ...: i53): boolean
|
||||||
|
|
||||||
local records = archetype.records
|
local records = archetype.records
|
||||||
|
|
||||||
for i = 1, select("#", ...) do
|
return records[a] ~= nil and
|
||||||
if not records[select(i, ...)] then
|
(b == nil or records[b] ~= nil) and
|
||||||
return false
|
(c == nil or records[c] ~= nil) and
|
||||||
end
|
(d == nil or records[d] ~= nil) and
|
||||||
end
|
(e == nil or error("args exceeded"))
|
||||||
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function world_target(world: ecs_world_t, entity: i53, relation: i24, index: number?): i24?
|
local function world_target(world: ecs_world_t, entity: i53, relation: i24, index: number?): i24?
|
||||||
|
|
|
@ -32,7 +32,12 @@ local function pad()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function lifetime_tracker_add(world: jecs.World, opt)
|
type PatchedWorld = jecs.World & {
|
||||||
|
print_entity_index: (world: PatchedWorld) -> (),
|
||||||
|
print_snapshot: (world: PatchedWorld) -> (),
|
||||||
|
}
|
||||||
|
|
||||||
|
local function lifetime_tracker_add(world: jecs.World, opt): PatchedWorld
|
||||||
local entity_index = world.entity_index
|
local entity_index = world.entity_index
|
||||||
local dense_array = entity_index.dense_array
|
local dense_array = entity_index.dense_array
|
||||||
local component_index = world.component_index
|
local component_index = world.component_index
|
||||||
|
|
Loading…
Reference in a new issue