mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-25 09:30:03 +00:00
Reorganize file
This commit is contained in:
parent
1de41447b6
commit
87d49e5134
2 changed files with 52 additions and 47 deletions
5
lib/a.lua
Normal file
5
lib/a.lua
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
local test = {
|
||||||
|
ez = "godo"
|
||||||
|
}
|
||||||
|
|
||||||
|
test.ez = "good"
|
94
lib/init.lua
94
lib/init.lua
|
@ -143,14 +143,14 @@ local function createArchetypeRecords(componentIndex: ComponentIndex, to: Archet
|
||||||
end
|
end
|
||||||
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 ty = hash(types)
|
||||||
|
|
||||||
local id = world.nextArchetypeId + 1
|
local id = world.nextArchetypeId + 1
|
||||||
world.nextArchetypeId = id
|
world.nextArchetypeId = id
|
||||||
|
|
||||||
local length = #types
|
local length = #types
|
||||||
local columns = table.create(length) :: {any}
|
local columns = table.create(length)
|
||||||
|
|
||||||
for index in types do
|
for index in types do
|
||||||
columns[index] = {}
|
columns[index] = {}
|
||||||
|
@ -174,51 +174,6 @@ local function archetypeOf(world: World, types: {i24}, prev: Archetype?): Archet
|
||||||
return archetype
|
return archetype
|
||||||
end
|
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)
|
local function ensureArchetype(world: World, types, prev)
|
||||||
if #types < 1 then
|
if #types < 1 then
|
||||||
return world.ROOT_ARCHETYPE
|
return world.ROOT_ARCHETYPE
|
||||||
|
@ -306,6 +261,51 @@ local function ensureRecord(world, entityId: i53): Record
|
||||||
return record
|
return record
|
||||||
end
|
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)
|
function World.add(world: World, entityId: i53, componentId: i53)
|
||||||
local record = ensureRecord(world, entityId)
|
local record = ensureRecord(world, entityId)
|
||||||
|
|
Loading…
Reference in a new issue