mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-25 09:30:03 +00:00
guarantee monomorphic objects (laymans term: alphabetize)
This commit is contained in:
parent
4d1e62cc4e
commit
19819bfcad
1 changed files with 15 additions and 15 deletions
30
lib/init.lua
30
lib/init.lua
|
@ -157,13 +157,13 @@ local function archetypeOf(world: World, types: {i24}, prev: Archetype?): Archet
|
||||||
end
|
end
|
||||||
|
|
||||||
local archetype = {
|
local archetype = {
|
||||||
id = id;
|
|
||||||
types = types;
|
|
||||||
type = ty;
|
|
||||||
columns = columns;
|
columns = columns;
|
||||||
entities = {};
|
|
||||||
edges = {};
|
edges = {};
|
||||||
|
entities = {};
|
||||||
|
id = id;
|
||||||
records = {};
|
records = {};
|
||||||
|
type = ty;
|
||||||
|
types = types;
|
||||||
}
|
}
|
||||||
world.archetypeIndex[ty] = archetype
|
world.archetypeIndex[ty] = archetype
|
||||||
world.archetypes[id] = archetype
|
world.archetypes[id] = archetype
|
||||||
|
@ -178,17 +178,17 @@ local World = {}
|
||||||
World.__index = World
|
World.__index = World
|
||||||
function World.new()
|
function World.new()
|
||||||
local self = setmetatable({
|
local self = setmetatable({
|
||||||
entityIndex = {};
|
|
||||||
componentIndex = {};
|
|
||||||
archetypes = {};
|
|
||||||
archetypeIndex = {};
|
archetypeIndex = {};
|
||||||
ROOT_ARCHETYPE = (nil :: any) :: Archetype;
|
archetypes = {};
|
||||||
nextEntityId = 0;
|
componentIndex = {};
|
||||||
nextComponentId = 0;
|
entityIndex = {};
|
||||||
nextArchetypeId = 0;
|
|
||||||
hooks = {
|
hooks = {
|
||||||
[ON_ADD] = {};
|
[ON_ADD] = {};
|
||||||
};
|
};
|
||||||
|
nextArchetypeId = 0;
|
||||||
|
nextComponentId = 0;
|
||||||
|
nextEntityId = 0;
|
||||||
|
ROOT_ARCHETYPE = (nil :: any) :: Archetype;
|
||||||
}, World)
|
}, World)
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
@ -197,21 +197,21 @@ local function emit(world, eventDescription)
|
||||||
local event = eventDescription.event
|
local event = eventDescription.event
|
||||||
|
|
||||||
table.insert(world.hooks[event], {
|
table.insert(world.hooks[event], {
|
||||||
ids = eventDescription.ids;
|
|
||||||
archetype = eventDescription.archetype;
|
archetype = eventDescription.archetype;
|
||||||
otherArchetype = eventDescription.otherArchetype;
|
ids = eventDescription.ids;
|
||||||
offset = eventDescription.offset;
|
offset = eventDescription.offset;
|
||||||
|
otherArchetype = eventDescription.otherArchetype;
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
local function onNotifyAdd(world, archetype, otherArchetype, row: number, added: Ty)
|
local function onNotifyAdd(world, archetype, otherArchetype, row: number, added: Ty)
|
||||||
if #added > 0 then
|
if #added > 0 then
|
||||||
emit(world, {
|
emit(world, {
|
||||||
|
archetype = archetype;
|
||||||
event = ON_ADD;
|
event = ON_ADD;
|
||||||
ids = added;
|
ids = added;
|
||||||
archetype = archetype;
|
|
||||||
otherArchetype = otherArchetype;
|
|
||||||
offset = row;
|
offset = row;
|
||||||
|
otherArchetype = otherArchetype;
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue