Sync to upstream Jecs 0.4.0
This commit is contained in:
parent
20467b301b
commit
102ecc7139
2 changed files with 30 additions and 18 deletions
46
init.luau
46
init.luau
|
@ -91,8 +91,8 @@ local EcsRemove = HI_COMPONENT_ID + 10
|
||||||
local EcsName = HI_COMPONENT_ID + 11
|
local EcsName = HI_COMPONENT_ID + 11
|
||||||
local EcsRest = HI_COMPONENT_ID + 12
|
local EcsRest = HI_COMPONENT_ID + 12
|
||||||
|
|
||||||
local ECS_PAIR_FLAG = 0x8
|
local ECS_PAIR_FLAG = 0x8
|
||||||
local ECS_ID_FLAGS_MASK = 0x10
|
local ECS_ID_FLAGS_MASK = 0x10
|
||||||
local ECS_ENTITY_MASK = bit32.lshift(1, 24)
|
local ECS_ENTITY_MASK = bit32.lshift(1, 24)
|
||||||
local ECS_GENERATION_MASK = bit32.lshift(1, 16)
|
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
|
return r
|
||||||
end
|
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 function entity_index_get_alive(index: EntityIndex, e: i24): i53
|
||||||
local r = entity_index_try_get_any(index, e)
|
local r = entity_index_try_get_any(index, e)
|
||||||
if r then
|
if r then
|
||||||
|
@ -338,7 +348,7 @@ do
|
||||||
end
|
end
|
||||||
|
|
||||||
function world_get(world: World, entity: i53, a: i53, b: i53?, c: i53?, d: i53?, e: i53?): ...any
|
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
|
if not record then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
@ -369,7 +379,7 @@ do
|
||||||
end
|
end
|
||||||
|
|
||||||
local function world_get_one_inline(world: World, entity: i53, id: i53): any
|
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
|
if not record then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
@ -387,7 +397,7 @@ local function world_get_one_inline(world: World, entity: i53, id: i53): any
|
||||||
end
|
end
|
||||||
|
|
||||||
local function world_has_one_inline(world: World, entity: number, id: i53): boolean
|
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
|
if not record then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
@ -403,7 +413,7 @@ local function world_has_one_inline(world: World, entity: number, id: i53): bool
|
||||||
end
|
end
|
||||||
|
|
||||||
local function world_has(world: World, entity: number, ...: i53): boolean
|
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
|
if not record then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
@ -426,7 +436,7 @@ end
|
||||||
|
|
||||||
local function world_target(world: World, entity: i53, relation: i24, index: number?): i24?
|
local function world_target(world: World, entity: i53, relation: i24, index: number?): i24?
|
||||||
local nth = index or 0
|
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
|
if not record then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
@ -472,7 +482,10 @@ local function id_record_ensure(world: World, id: number): IdRecord
|
||||||
|
|
||||||
if not idr then
|
if not idr then
|
||||||
local flags = ECS_ID_MASK
|
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 = world_target(world, relation, EcsOnDelete, 0)
|
||||||
local cleanup_policy_target = world_target(world, relation, EcsOnDeleteTarget, 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 function world_add(world: World, entity: i53, id: i53): ()
|
||||||
local entity_index = world.entity_index
|
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
|
if not record then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -763,7 +776,7 @@ end
|
||||||
|
|
||||||
local function world_set(world: World, entity: i53, id: i53, data: unknown): ()
|
local function world_set(world: World, entity: i53, id: i53, data: unknown): ()
|
||||||
local entity_index = world.entity_index
|
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
|
if not record then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -836,7 +849,7 @@ end
|
||||||
|
|
||||||
local function world_remove(world: World, entity: i53, id: i53)
|
local function world_remove(world: World, entity: i53, id: i53)
|
||||||
local entity_index = world.entity_index
|
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
|
if not record then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -1598,8 +1611,11 @@ if _G.__JECS_DEBUG then
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function ID_IS_TAG(world, id)
|
local function ID_IS_TAG(world: World, id)
|
||||||
return not world_has_one_inline(world, ECS_ENTITY_T_HI(id), EcsComponent)
|
if ECS_IS_PAIR(id) then
|
||||||
|
id = ecs_pair_first(world, id)
|
||||||
|
end
|
||||||
|
return not world_has_one_inline(world, id, EcsComponent)
|
||||||
end
|
end
|
||||||
|
|
||||||
World.query = function(world: World, ...)
|
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): ()
|
World.set = function(world: World, entity: i53, id: i53, value: any): ()
|
||||||
local is_tag = ID_IS_TAG(world, id)
|
local is_tag = ID_IS_TAG(world, id)
|
||||||
if is_tag and value == nil then
|
if is_tag and value == nil then
|
||||||
world_add(world, entity, id)
|
|
||||||
local _1 = get_name(world, entity)
|
local _1 = get_name(world, entity)
|
||||||
local _2 = get_name(world, id)
|
local _2 = get_name(world, id)
|
||||||
local why = "cannot set component value to nil"
|
local why = "cannot set component value to nil"
|
||||||
throw(why)
|
throw(why)
|
||||||
return
|
return
|
||||||
elseif value ~= nil and is_tag then
|
elseif value ~= nil and is_tag then
|
||||||
world_add(world, entity, id)
|
|
||||||
local _1 = get_name(world, entity)
|
local _1 = get_name(world, entity)
|
||||||
local _2 = get_name(world, id)
|
local _2 = get_name(world, id)
|
||||||
local why = `cannot set a component value because {_2} is a tag`
|
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 _1 = get_name(world, entity)
|
||||||
local _2 = get_name(world, id)
|
local _2 = get_name(world, id)
|
||||||
throw("You provided a value when none was expected. " .. `Did you mean to use "world:add({_1}, {_2})"`)
|
throw("You provided a value when none was expected. " .. `Did you mean to use "world:add({_1}, {_2})"`)
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
world_add(world, entity, id)
|
world_add(world, entity, id)
|
||||||
|
@ -1886,6 +1899,5 @@ return {
|
||||||
entity_index_try_get = entity_index_try_get,
|
entity_index_try_get = entity_index_try_get,
|
||||||
entity_index_try_get_any = entity_index_try_get_any,
|
entity_index_try_get_any = entity_index_try_get_any,
|
||||||
entity_index_is_alive = entity_index_is_alive,
|
entity_index_is_alive = entity_index_is_alive,
|
||||||
entity_index_remove = entity_index_remove,
|
|
||||||
entity_index_new_id = entity_index_new_id,
|
entity_index_new_id = entity_index_new_id,
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ includes = [
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
name = "mark_marks/jecs_pesde"
|
name = "mark_marks/jecs_pesde"
|
||||||
repository = "https://git.devmarked.win/marked/jecs-pesde"
|
repository = "https://git.devmarked.win/marked/jecs-pesde"
|
||||||
version = "0.4.0-rc.0"
|
version = "0.4.0"
|
||||||
|
|
||||||
[indices]
|
[indices]
|
||||||
default = "https://github.com/daimond113/pesde-index"
|
default = "https://github.com/daimond113/pesde-index"
|
||||||
|
|
Loading…
Reference in a new issue