mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-24 17:10:03 +00:00
Index into archetypemap
This commit is contained in:
parent
b1626a9be0
commit
74fe5be0c0
4 changed files with 119 additions and 104 deletions
|
@ -65,12 +65,14 @@ local E8 = mcs:entity()
|
||||||
local registry2 = ecr.registry()
|
local registry2 = ecr.registry()
|
||||||
|
|
||||||
local function flip()
|
local function flip()
|
||||||
return math.random() >= 0.5
|
return math.random() >= 0.15
|
||||||
end
|
end
|
||||||
|
|
||||||
local common = 0
|
local common = 0
|
||||||
local N = 2^16-2
|
local N = 2^16-2
|
||||||
local archetypes = {}
|
local archetypes = {}
|
||||||
|
|
||||||
|
local hm = 0
|
||||||
for i = 1, N do
|
for i = 1, N do
|
||||||
local id = registry2.create()
|
local id = registry2.create()
|
||||||
local combination = ""
|
local combination = ""
|
||||||
|
@ -153,8 +155,15 @@ for i = 1, N do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if combination:find("BCDF") then
|
||||||
|
if not archetypes[combination] then
|
||||||
|
print(combination)
|
||||||
|
end
|
||||||
|
hm += 1
|
||||||
|
end
|
||||||
archetypes[combination] = true
|
archetypes[combination] = true
|
||||||
end
|
end
|
||||||
|
print("TEST", hm)
|
||||||
|
|
||||||
local white = rgb.white
|
local white = rgb.white
|
||||||
local yellow = rgb.yellow
|
local yellow = rgb.yellow
|
||||||
|
@ -179,6 +188,8 @@ print(
|
||||||
..yellow("Total Archetypes: "..numberOfArchetypes)
|
..yellow("Total Archetypes: "..numberOfArchetypes)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
local q = ecs:query(D4, D2, D3, D6)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ParameterGenerator = function()
|
ParameterGenerator = function()
|
||||||
return
|
return
|
||||||
|
@ -187,16 +198,17 @@ return {
|
||||||
Functions = {
|
Functions = {
|
||||||
Mirror = function()
|
Mirror = function()
|
||||||
local matched = 0
|
local matched = 0
|
||||||
for entityId, firstComponent in mcs:query(E1, E2, E3, E4) do
|
for entityId, firstComponent in mcs:query(E2, E3, E4, E1) do
|
||||||
matched += 1
|
matched += 1
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
Jecs = function()
|
Jecs = function()
|
||||||
local matched = 0
|
local matched = 0
|
||||||
for entityId, firstComponent in ecs:query(D1, D2, D3, D4) do
|
for entityId, firstComponent in ecs:query(E2, E3, E4, E1) do
|
||||||
matched += 1
|
matched += 1
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
|
end,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
15
lib/init.lua
15
lib/init.lua
|
@ -276,7 +276,7 @@ end
|
||||||
|
|
||||||
local function get(componentIndex: { [i24]: ArchetypeMap }, record: Record, componentId: i24)
|
local function get(componentIndex: { [i24]: ArchetypeMap }, record: Record, componentId: i24)
|
||||||
local archetype = record.archetype
|
local archetype = record.archetype
|
||||||
local archetypeRecord = componentIndex[componentId][archetype.id]
|
local archetypeRecord = componentIndex[componentId].map[archetype.id]
|
||||||
|
|
||||||
if not archetypeRecord then
|
if not archetypeRecord then
|
||||||
return nil
|
return nil
|
||||||
|
@ -347,15 +347,15 @@ function World.query(world: World, ...: i53): (() -> (number, ...any)) | () -> (
|
||||||
local columns = archetype.columns
|
local columns = archetype.columns
|
||||||
local archetypeRecords = archetype.records
|
local archetypeRecords = archetype.records
|
||||||
local indices = {}
|
local indices = {}
|
||||||
|
|
||||||
local skip = false
|
local skip = false
|
||||||
|
|
||||||
for i, componentId in components do
|
for i, componentId in components do
|
||||||
local data = columns[archetypeRecords[componentId]]
|
local index = archetypeRecords[componentId]
|
||||||
if not data then
|
if not index then
|
||||||
skip = true
|
skip = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
indices[i] = data
|
indices[i] = columns[index]
|
||||||
end
|
end
|
||||||
|
|
||||||
if skip then
|
if skip then
|
||||||
|
@ -369,9 +369,12 @@ function World.query(world: World, ...: i53): (() -> (number, ...any)) | () -> (
|
||||||
end
|
end
|
||||||
|
|
||||||
local lastArchetype, compatibleArchetype = next(compatibleArchetypes)
|
local lastArchetype, compatibleArchetype = next(compatibleArchetypes)
|
||||||
|
if not compatibleArchetype then
|
||||||
|
return noop()
|
||||||
|
end
|
||||||
|
|
||||||
local lastRow
|
local lastRow
|
||||||
|
|
||||||
return function()
|
return function()
|
||||||
local archetype = compatibleArchetype.archetype
|
local archetype = compatibleArchetype.archetype
|
||||||
local indices = compatibleArchetype.indices
|
local indices = compatibleArchetype.indices
|
||||||
|
|
|
@ -11,22 +11,77 @@ print("F", F)
|
||||||
print("G", G)
|
print("G", G)
|
||||||
print("H", H)
|
print("H", H)
|
||||||
|
|
||||||
for i = 1, 256 do
|
local common = 0
|
||||||
local entity = ecs:entity()
|
local N = 2^16-2
|
||||||
ecs:set(entity, A, true)
|
local archetypes = {}
|
||||||
ecs:set(entity, B, true)
|
local function flip()
|
||||||
ecs:set(entity, C, true)
|
return math.random() >= 0.5
|
||||||
ecs:set(entity, D, true)
|
|
||||||
|
|
||||||
--[[
|
|
||||||
ecs:set(entity, E, true)
|
|
||||||
ecs:set(entity, F, true)
|
|
||||||
ecs:set(entity, G, true)
|
|
||||||
ecs:set(entity, H, true)
|
|
||||||
print("end")
|
|
||||||
]]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local hm = 0
|
||||||
|
for i = 1, N do
|
||||||
|
local entity = ecs:entity()
|
||||||
|
local combination = ""
|
||||||
|
|
||||||
|
if flip() then
|
||||||
|
combination ..= "2_"
|
||||||
|
ecs:set(entity, B, { value = true})
|
||||||
|
end
|
||||||
|
if flip() then
|
||||||
|
combination ..= "3_"
|
||||||
|
ecs:set(entity, C, { value = true})
|
||||||
|
end
|
||||||
|
if flip() then
|
||||||
|
combination ..= "4_"
|
||||||
|
ecs:set(entity, D, { value = true})
|
||||||
|
end
|
||||||
|
if flip() then
|
||||||
|
combination ..= "5_"
|
||||||
|
ecs:set(entity, E, { value = true})
|
||||||
|
end
|
||||||
|
if flip() then
|
||||||
|
combination ..= "6_"
|
||||||
|
ecs:set(entity, F, { value = true})
|
||||||
|
end
|
||||||
|
if flip() then
|
||||||
|
combination ..= "7_"
|
||||||
|
ecs:set(entity, G, { value = true})
|
||||||
|
end
|
||||||
|
if flip() then
|
||||||
|
combination ..= "8"
|
||||||
|
ecs:set(entity, H, { value = true})
|
||||||
|
end
|
||||||
|
|
||||||
|
if #combination == 7 then
|
||||||
|
combination = "1_" .. combination
|
||||||
|
common += 1
|
||||||
|
ecs:set(entity, A, { value = true})
|
||||||
|
end
|
||||||
|
|
||||||
|
if combination:find("2")
|
||||||
|
and combination:find("3")
|
||||||
|
and combination:find("4")
|
||||||
|
and combination:find("6")
|
||||||
|
then
|
||||||
|
hm += 1
|
||||||
|
end
|
||||||
|
archetypes[combination] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local arch = 0
|
||||||
|
for combination in archetypes do
|
||||||
|
if combination:find("2")
|
||||||
|
and combination:find("3")
|
||||||
|
and combination:find("4")
|
||||||
|
and combination:find("6")
|
||||||
|
then
|
||||||
|
print(combination)
|
||||||
|
arch += 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
print("TEST", hm, arch)
|
||||||
|
|
||||||
return function()
|
return function()
|
||||||
describe("World", function()
|
describe("World", function()
|
||||||
it("should add component", function()
|
it("should add component", function()
|
||||||
|
@ -60,10 +115,11 @@ return function()
|
||||||
end)
|
end)
|
||||||
it("query", function()
|
it("query", function()
|
||||||
local added = 0
|
local added = 0
|
||||||
for e, a, b, c, d in ecs:query(A, B, C, D) do
|
for _ in ecs:query(B, C, D, F) do
|
||||||
added += 1
|
added += 1
|
||||||
end
|
end
|
||||||
expect(added).to.equal(256)
|
expect(added).to.equal(hm)
|
||||||
|
print(added, hm)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
100
mirror/init.lua
100
mirror/init.lua
|
@ -276,7 +276,7 @@ end
|
||||||
|
|
||||||
local function get(componentIndex: { [i24]: ArchetypeMap }, record: Record, componentId: i24)
|
local function get(componentIndex: { [i24]: ArchetypeMap }, record: Record, componentId: i24)
|
||||||
local archetype = record.archetype
|
local archetype = record.archetype
|
||||||
local archetypeRecord = componentIndex[componentId][archetype.id]
|
local archetypeRecord = componentIndex[componentId].map[archetype.id]
|
||||||
|
|
||||||
if not archetypeRecord then
|
if not archetypeRecord then
|
||||||
return nil
|
return nil
|
||||||
|
@ -338,8 +338,6 @@ function World.query(world: World, ...: i53): (() -> (number, ...any)) | () -> (
|
||||||
local queryLength = #components
|
local queryLength = #components
|
||||||
local firstArchetypeMap = getSmallestMap(world.componentIndex, components)
|
local firstArchetypeMap = getSmallestMap(world.componentIndex, components)
|
||||||
|
|
||||||
local a, b, c, d, e, f, g, h = ...
|
|
||||||
|
|
||||||
if not firstArchetypeMap then
|
if not firstArchetypeMap then
|
||||||
return noop()
|
return noop()
|
||||||
end
|
end
|
||||||
|
@ -349,85 +347,31 @@ function World.query(world: World, ...: i53): (() -> (number, ...any)) | () -> (
|
||||||
local columns = archetype.columns
|
local columns = archetype.columns
|
||||||
local archetypeRecords = archetype.records
|
local archetypeRecords = archetype.records
|
||||||
local indices = {}
|
local indices = {}
|
||||||
if queryLength == 1 then
|
local skip = false
|
||||||
indices = {
|
|
||||||
columns[archetypeRecords[a]],
|
for i, componentId in components do
|
||||||
}
|
local index = archetypeRecords[componentId]
|
||||||
elseif queryLength == 2 then
|
if not index then
|
||||||
indices = {
|
skip = true
|
||||||
columns[archetypeRecords[a]],
|
break
|
||||||
columns[archetypeRecords[b]]
|
end
|
||||||
}
|
indices[i] = columns[index]
|
||||||
elseif queryLength == 3 then
|
|
||||||
indices = {
|
|
||||||
columns[archetypeRecords[a]],
|
|
||||||
columns[archetypeRecords[b]],
|
|
||||||
columns[archetypeRecords[c]]
|
|
||||||
}
|
|
||||||
elseif queryLength == 4 then
|
|
||||||
indices = {
|
|
||||||
columns[archetypeRecords[a]],
|
|
||||||
columns[archetypeRecords[b]],
|
|
||||||
columns[archetypeRecords[c]],
|
|
||||||
columns[archetypeRecords[d]]
|
|
||||||
}
|
|
||||||
elseif queryLength == 5 then
|
|
||||||
indices = {
|
|
||||||
columns[archetypeRecords[a]],
|
|
||||||
columns[archetypeRecords[b]],
|
|
||||||
columns[archetypeRecords[c]],
|
|
||||||
columns[archetypeRecords[d]],
|
|
||||||
columns[archetypeRecords[e]]
|
|
||||||
}
|
|
||||||
elseif queryLength == 6 then
|
|
||||||
indices = {
|
|
||||||
columns[archetypeRecords[a]],
|
|
||||||
columns[archetypeRecords[b]],
|
|
||||||
columns[archetypeRecords[c]],
|
|
||||||
columns[archetypeRecords[d]],
|
|
||||||
columns[archetypeRecords[e]],
|
|
||||||
columns[archetypeRecords[f]],
|
|
||||||
}
|
|
||||||
elseif queryLength == 7 then
|
|
||||||
indices = {
|
|
||||||
columns[archetypeRecords[a]],
|
|
||||||
columns[archetypeRecords[b]],
|
|
||||||
columns[archetypeRecords[c]],
|
|
||||||
columns[archetypeRecords[d]],
|
|
||||||
columns[archetypeRecords[e]],
|
|
||||||
columns[archetypeRecords[f]],
|
|
||||||
columns[archetypeRecords[g]],
|
|
||||||
}
|
|
||||||
elseif queryLength == 8 then
|
|
||||||
indices = {
|
|
||||||
columns[archetypeRecords[a]],
|
|
||||||
columns[archetypeRecords[b]],
|
|
||||||
columns[archetypeRecords[c]],
|
|
||||||
columns[archetypeRecords[d]],
|
|
||||||
columns[archetypeRecords[e]],
|
|
||||||
columns[archetypeRecords[f]],
|
|
||||||
columns[archetypeRecords[g]],
|
|
||||||
columns[archetypeRecords[h]],
|
|
||||||
}
|
|
||||||
else
|
|
||||||
for i, componentId in components do
|
|
||||||
indices[i] = columns[archetypeRecords[componentId]]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local i = 0
|
|
||||||
for _ in indices do
|
|
||||||
i += 1
|
|
||||||
end
|
|
||||||
if queryLength == i then
|
|
||||||
table.insert(compatibleArchetypes, {
|
|
||||||
archetype = archetype,
|
|
||||||
indices = indices
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if skip then
|
||||||
|
continue
|
||||||
|
end
|
||||||
|
|
||||||
|
table.insert(compatibleArchetypes, {
|
||||||
|
archetype = archetype,
|
||||||
|
indices = indices
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
local lastArchetype, compatibleArchetype = next(compatibleArchetypes)
|
local lastArchetype, compatibleArchetype = next(compatibleArchetypes)
|
||||||
|
if not compatibleArchetype then
|
||||||
|
return noop()
|
||||||
|
end
|
||||||
|
|
||||||
local lastRow
|
local lastRow
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue