From faf9b365cf7be9b10f9d19e6d6b53c678642e0e5 Mon Sep 17 00:00:00 2001 From: kalrnlo Date: Sun, 23 Jun 2024 20:45:15 -0400 Subject: [PATCH] Fixes --- lib/init.lua | 63 +++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/lib/init.lua b/lib/init.lua index 6aa0fe7..76e9e9e 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -114,9 +114,8 @@ local function ECS_GENERATION_INC(e: i53) local generation = flags % ECS_GENERATION_MASK return ECS_COMBINE(id, generation + 1) + flags - else - return ECS_COMBINE(e, 1) end + return ECS_COMBINE(e, 1) end -- FIRST gets the high ID @@ -834,41 +833,39 @@ function World.__iter(world: World): WorldIterator -- new solver doesnt like the world iterator type even tho its correct -- so any cast here i come - local iterator: WorldIterator = ( - function() - local lastEntity: number?, entityId: number = next(dense, last) - if not lastEntity then - -- ignore type error - return - end - - last = lastEntity - - local record = sparse[entityId] - local archetype = record.archetype - if not archetype then - -- Returns only the entity id as an entity without data should not return - -- data and allow the user to get an error if they don't handle the case. - return entityId - end - - local row = record.row - local types = archetype.types - local columns = archetype.columns - local entityData = {} - for i, column in columns do - -- We use types because the key should be the component ID not the column index - entityData[types[i]] = column[row] - end - - return entityId, entityData + local function iterator() + local lastEntity: number?, entityId: number = next(dense, last) + if not lastEntity then + -- ignore type error + return end - ) :: any - return iterator + last = lastEntity + + local record = sparse[entityId] + local archetype = record.archetype + if not archetype then + -- Returns only the entity id as an entity without data should not return + -- data and allow the user to get an error if they don't handle the case. + return entityId + end + + local row = record.row + local types = archetype.types + local columns = archetype.columns + local entityData = {} + for i, column in columns do + -- We use types because the key should be the component ID not the column index + entityData[types[i]] = column[row] + end + + return entityId, entityData + end + + return iterator :: any end --- freezing it incase somebody trys doing something stupid and modifying it +-- freezing it incase somebody tries doing something stupid and modifying it -- (unlikely but its easy to add extra safety so) table.freeze(World)