Merge pull request 'Sync to upstream Jecs 0.4.0' (#2) from auto/update-jecs into main

Reviewed-on: #2
This commit is contained in:
marked 2024-12-03 19:04:52 +01:00
commit e693b4242b
2 changed files with 30 additions and 18 deletions

View file

@ -91,8 +91,8 @@ local EcsRemove = HI_COMPONENT_ID + 10
local EcsName = HI_COMPONENT_ID + 11
local EcsRest = HI_COMPONENT_ID + 12
local ECS_PAIR_FLAG = 0x8
local ECS_ID_FLAGS_MASK = 0x10
local ECS_PAIR_FLAG = 0x8
local ECS_ID_FLAGS_MASK = 0x10
local ECS_ENTITY_MASK = bit32.lshift(1, 24)
local ECS_GENERATION_MASK = bit32.lshift(1, 16)
@ -198,6 +198,16 @@ local function entity_index_try_get(entity_index: EntityIndex, entity: number):
return r
end
local function entity_index_try_get_fast(entity_index: EntityIndex, entity: number): Record?
local r = entity_index.sparse_array[ECS_ENTITY_T_LO(entity)]
if r then
if entity_index.dense_array[r.dense] ~= entity then
return nil
end
end
return r
end
local function entity_index_get_alive(index: EntityIndex, e: i24): i53
local r = entity_index_try_get_any(index, e)
if r then
@ -338,7 +348,7 @@ do
end
function world_get(world: World, entity: i53, a: i53, b: i53?, c: i53?, d: i53?, e: i53?): ...any
local record = entity_index_try_get(world.entity_index, entity)
local record = entity_index_try_get_fast(world.entity_index, entity)
if not record then
return nil
end
@ -369,7 +379,7 @@ do
end
local function world_get_one_inline(world: World, entity: i53, id: i53): any
local record = entity_index_try_get(world.entity_index, entity)
local record = entity_index_try_get_fast(world.entity_index, entity)
if not record then
return nil
end
@ -387,7 +397,7 @@ local function world_get_one_inline(world: World, entity: i53, id: i53): any
end
local function world_has_one_inline(world: World, entity: number, id: i53): boolean
local record = entity_index_try_get(world.entity_index, entity)
local record = entity_index_try_get_fast(world.entity_index, entity)
if not record then
return false
end
@ -403,7 +413,7 @@ local function world_has_one_inline(world: World, entity: number, id: i53): bool
end
local function world_has(world: World, entity: number, ...: i53): boolean
local record = entity_index_try_get(world.entity_index, entity)
local record = entity_index_try_get_fast(world.entity_index, entity)
if not record then
return false
end
@ -426,7 +436,7 @@ end
local function world_target(world: World, entity: i53, relation: i24, index: number?): i24?
local nth = index or 0
local record = entity_index_try_get(world.entity_index, entity)
local record = entity_index_try_get_fast(world.entity_index, entity)
if not record then
return nil
end
@ -472,7 +482,10 @@ local function id_record_ensure(world: World, id: number): IdRecord
if not idr then
local flags = ECS_ID_MASK
local relation = ECS_ENTITY_T_HI(id)
local relation = id
if ECS_IS_PAIR(id) then
relation = ecs_pair_first(world, id)
end
local cleanup_policy = world_target(world, relation, EcsOnDelete, 0)
local cleanup_policy_target = world_target(world, relation, EcsOnDeleteTarget, 0)
@ -735,7 +748,7 @@ end
local function world_add(world: World, entity: i53, id: i53): ()
local entity_index = world.entity_index
local record = entity_index_try_get(entity_index, entity)
local record = entity_index_try_get_fast(entity_index, entity)
if not record then
return
end
@ -763,7 +776,7 @@ end
local function world_set(world: World, entity: i53, id: i53, data: unknown): ()
local entity_index = world.entity_index
local record = entity_index_try_get(entity_index, entity)
local record = entity_index_try_get_fast(entity_index, entity)
if not record then
return
end
@ -836,7 +849,7 @@ end
local function world_remove(world: World, entity: i53, id: i53)
local entity_index = world.entity_index
local record = entity_index_try_get(entity_index, entity)
local record = entity_index_try_get_fast(entity_index, entity)
if not record then
return
end
@ -1598,8 +1611,11 @@ if _G.__JECS_DEBUG then
end
end
local function ID_IS_TAG(world, id)
return not world_has_one_inline(world, ECS_ENTITY_T_HI(id), EcsComponent)
local function ID_IS_TAG(world: World, id)
if ECS_IS_PAIR(id) then
id = ecs_pair_first(world, id)
end
return not world_has_one_inline(world, id, EcsComponent)
end
World.query = function(world: World, ...)
@ -1610,14 +1626,12 @@ if _G.__JECS_DEBUG then
World.set = function(world: World, entity: i53, id: i53, value: any): ()
local is_tag = ID_IS_TAG(world, id)
if is_tag and value == nil then
world_add(world, entity, id)
local _1 = get_name(world, entity)
local _2 = get_name(world, id)
local why = "cannot set component value to nil"
throw(why)
return
elseif value ~= nil and is_tag then
world_add(world, entity, id)
local _1 = get_name(world, entity)
local _2 = get_name(world, id)
local why = `cannot set a component value because {_2} is a tag`
@ -1634,7 +1648,6 @@ if _G.__JECS_DEBUG then
local _1 = get_name(world, entity)
local _2 = get_name(world, id)
throw("You provided a value when none was expected. " .. `Did you mean to use "world:add({_1}, {_2})"`)
return
end
world_add(world, entity, id)
@ -1886,6 +1899,5 @@ return {
entity_index_try_get = entity_index_try_get,
entity_index_try_get_any = entity_index_try_get_any,
entity_index_is_alive = entity_index_is_alive,
entity_index_remove = entity_index_remove,
entity_index_new_id = entity_index_new_id,
}

View file

@ -10,7 +10,7 @@ includes = [
license = "MIT"
name = "mark_marks/jecs_pesde"
repository = "https://git.devmarked.win/marked/jecs-pesde"
version = "0.4.0-rc.0"
version = "0.4.0"
[indices]
default = "https://github.com/daimond113/pesde-index"