From 87d49e513422a47d5022932c1c8143a4dbd0504a Mon Sep 17 00:00:00 2001 From: Ukendio Date: Thu, 9 May 2024 02:20:54 +0200 Subject: [PATCH] Reorganize file --- lib/a.lua | 5 +++ lib/init.lua | 94 ++++++++++++++++++++++++++-------------------------- 2 files changed, 52 insertions(+), 47 deletions(-) create mode 100644 lib/a.lua diff --git a/lib/a.lua b/lib/a.lua new file mode 100644 index 0000000..68b844c --- /dev/null +++ b/lib/a.lua @@ -0,0 +1,5 @@ +local test = { + ez = "godo" +} + + test.ez = "good" \ No newline at end of file diff --git a/lib/init.lua b/lib/init.lua index 29396a5..93e5021 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -143,14 +143,14 @@ local function createArchetypeRecords(componentIndex: ComponentIndex, to: Archet end end -local function archetypeOf(world: World, types: {i24}, prev: Archetype?): Archetype +local function archetypeOf(world: any, types: {i24}, prev: Archetype?): Archetype local ty = hash(types) local id = world.nextArchetypeId + 1 world.nextArchetypeId = id local length = #types - local columns = table.create(length) :: {any} + local columns = table.create(length) for index in types do columns[index] = {} @@ -174,51 +174,6 @@ local function archetypeOf(world: World, types: {i24}, prev: Archetype?): Archet return archetype end -local World = {} -World.__index = World -function World.new() - local self = setmetatable({ - archetypeIndex = {}; - archetypes = {}; - componentIndex = {}; - entityIndex = {}; - hooks = { - [ON_ADD] = {}; - }; - nextArchetypeId = 0; - nextComponentId = 0; - nextEntityId = 0; - ROOT_ARCHETYPE = (nil :: any) :: Archetype; - }, World) - self.ROOT_ARCHETYPE = archetypeOf(self, {}, nil) - return self -end - -local function emit(world, eventDescription) - local event = eventDescription.event - - table.insert(world.hooks[event], { - archetype = eventDescription.archetype; - ids = eventDescription.ids; - offset = eventDescription.offset; - otherArchetype = eventDescription.otherArchetype; - }) -end - -local function onNotifyAdd(world, archetype, otherArchetype, row: number, added: Ty) - if #added > 0 then - emit(world, { - archetype = archetype; - event = ON_ADD; - ids = added; - offset = row; - otherArchetype = otherArchetype; - }) - end -end - -export type World = typeof(World.new()) - local function ensureArchetype(world: World, types, prev) if #types < 1 then return world.ROOT_ARCHETYPE @@ -306,6 +261,51 @@ local function ensureRecord(world, entityId: i53): Record return record end +local World = {} +World.__index = World +function World.new() + local self = setmetatable({ + archetypeIndex = {}; + archetypes = {}; + componentIndex = {}; + entityIndex = {}; + hooks = { + [ON_ADD] = {}; + }; + nextArchetypeId = 0; + nextComponentId = 0; + nextEntityId = 0; + ROOT_ARCHETYPE = (nil :: any) :: Archetype; + }, World) + self.ROOT_ARCHETYPE = archetypeOf(self, {}, nil) + return self +end + +local function emit(world, eventDescription) + local event = eventDescription.event + + table.insert(world.hooks[event], { + archetype = eventDescription.archetype; + ids = eventDescription.ids; + offset = eventDescription.offset; + otherArchetype = eventDescription.otherArchetype; + }) +end + +local function onNotifyAdd(world, archetype, otherArchetype, row: number, added: Ty) + if #added > 0 then + emit(world, { + archetype = archetype; + event = ON_ADD; + ids = added; + offset = row; + otherArchetype = otherArchetype; + }) + end +end + +export type World = typeof(World.new()) + function World.add(world: World, entityId: i53, componentId: i53) local record = ensureRecord(world, entityId)