From 91e2f1a52aed9d2d3ad5b869321bb8b1f6cd2c18 Mon Sep 17 00:00:00 2001 From: Ukendio Date: Sun, 11 Aug 2024 03:16:46 +0200 Subject: [PATCH] Move functions for get and has --- src/init.luau | 63 ++++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/src/init.luau b/src/init.luau index 52f4505..d8d3720 100644 --- a/src/init.luau +++ b/src/init.luau @@ -364,6 +364,38 @@ local function world_parent(world: World, entity: i53) return world_target(world, entity, EcsChildOf) end +local function world_get(world: World, entity: i53, id: i53) + local record = world.entityIndex.sparse[entity] + if not record then + return nil + end + + local archetype = record.archetype + if not archetype then + return nil + end + + local tr = archetype.records[id] + if not tr then + return nil + end + return archetype.columns[tr.column][record.row] +end + +local function world_has(world: World, entity: i53, id: i53): boolean + local record = world.entityIndex.sparse[entity] + if not record then + return false + end + + local archetype = record.archetype + if not archetype then + return false + end + + return archetype.records[id] ~= nil +end + local function archetype_ensure(world: World, types, prev): Archetype if #types < 1 then return world.ROOT_ARCHETYPE @@ -609,37 +641,6 @@ local function world_clear(world: World, entity: i53) entity_move(world.entityIndex, entity, record, ROOT_ARCHETYPE) end -local function world_get(world: World, entity: i53, id: i53) - local record = world.entityIndex.sparse[entity] - if not record then - return nil - end - - local archetype = record.archetype - if not archetype then - return nil - end - - local tr = archetype.records[id] - if not tr then - return nil - end - return archetype.columns[tr.column][record.row] -end - -local function world_has(world: World, entity: i53, id: i53): boolean - local record = world.entityIndex.sparse[entity] - if not record then - return false - end - - local archetype = record.archetype - if not archetype then - return false - end - - return archetype.records[id] ~= nil -end type CompatibleArchetype = { archetype: Archetype, indices: { number } }