From 102ecc71390531f18cd46ef05768d36e466f096c Mon Sep 17 00:00:00 2001 From: forgejo-actions <+forgejo-actions@users.noreply.github.com> Date: Mon, 18 Nov 2024 00:11:02 +0000 Subject: [PATCH] Sync to upstream Jecs 0.4.0 --- init.luau | 46 +++++++++++++++++++++++++++++----------------- pesde.toml | 2 +- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/init.luau b/init.luau index 2b96b0a..d9b4434 100644 --- a/init.luau +++ b/init.luau @@ -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, } diff --git a/pesde.toml b/pesde.toml index 0fd4bfd..b9a5002 100644 --- a/pesde.toml +++ b/pesde.toml @@ -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"