diff --git a/init.luau b/init.luau index d9b4434..2b96b0a 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,16 +198,6 @@ 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 @@ -348,7 +338,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_fast(world.entity_index, entity) + local record = entity_index_try_get(world.entity_index, entity) if not record then return nil end @@ -379,7 +369,7 @@ do end local function world_get_one_inline(world: World, entity: i53, id: i53): any - local record = entity_index_try_get_fast(world.entity_index, entity) + local record = entity_index_try_get(world.entity_index, entity) if not record then return nil end @@ -397,7 +387,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_fast(world.entity_index, entity) + local record = entity_index_try_get(world.entity_index, entity) if not record then return false end @@ -413,7 +403,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_fast(world.entity_index, entity) + local record = entity_index_try_get(world.entity_index, entity) if not record then return false end @@ -436,7 +426,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_fast(world.entity_index, entity) + local record = entity_index_try_get(world.entity_index, entity) if not record then return nil end @@ -482,10 +472,7 @@ local function id_record_ensure(world: World, id: number): IdRecord if not idr then local flags = ECS_ID_MASK - local relation = id - if ECS_IS_PAIR(id) then - relation = ecs_pair_first(world, id) - end + local relation = ECS_ENTITY_T_HI(id) local cleanup_policy = world_target(world, relation, EcsOnDelete, 0) local cleanup_policy_target = world_target(world, relation, EcsOnDeleteTarget, 0) @@ -748,7 +735,7 @@ end local function world_add(world: World, entity: i53, id: i53): () local entity_index = world.entity_index - local record = entity_index_try_get_fast(entity_index, entity) + local record = entity_index_try_get(entity_index, entity) if not record then return end @@ -776,7 +763,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_fast(entity_index, entity) + local record = entity_index_try_get(entity_index, entity) if not record then return end @@ -849,7 +836,7 @@ end local function world_remove(world: World, entity: i53, id: i53) local entity_index = world.entity_index - local record = entity_index_try_get_fast(entity_index, entity) + local record = entity_index_try_get(entity_index, entity) if not record then return end @@ -1611,11 +1598,8 @@ if _G.__JECS_DEBUG then end end - 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) + local function ID_IS_TAG(world, id) + return not world_has_one_inline(world, ECS_ENTITY_T_HI(id), EcsComponent) end World.query = function(world: World, ...) @@ -1626,12 +1610,14 @@ 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` @@ -1648,6 +1634,7 @@ 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) @@ -1899,5 +1886,6 @@ 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 b9a5002..0fd4bfd 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" +version = "0.4.0-rc.0" [indices] default = "https://github.com/daimond113/pesde-index"