mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-24 17:10:03 +00:00
Add without (#3)
This commit is contained in:
parent
b75dc91a6a
commit
13c703211d
2 changed files with 106 additions and 81 deletions
|
@ -196,21 +196,21 @@ return {
|
|||
Functions = {
|
||||
Mater = function()
|
||||
local matched = 0
|
||||
for entityId, firstComponent in newWorld:query(A2, A4, A6, A8) do
|
||||
for entityId, firstComponent in newWorld:query(A1, A4, A6, A8) do
|
||||
matched += 1
|
||||
end
|
||||
end,
|
||||
|
||||
ECR = function()
|
||||
local matched = 0
|
||||
for entityId, firstComponent in registry2:view(B2, B4, B6, B8) do
|
||||
for entityId, firstComponent in registry2:view(B1, B4, B6, B8) do
|
||||
matched += 1
|
||||
end
|
||||
end,
|
||||
|
||||
Jecs = function()
|
||||
local matched = 0
|
||||
for entityId, firstComponent in ecs:query(D2, D4, D6, D8) do
|
||||
for entityId, firstComponent in ecs:query(D1, D4, D6, D8) do
|
||||
matched += 1
|
||||
end
|
||||
|
||||
|
|
33
lib/init.lua
33
lib/init.lua
|
@ -361,8 +361,7 @@ local function getSmallestMap(componentIndex, components)
|
|||
return s.sparse
|
||||
end
|
||||
|
||||
function World.query(world: World, ...: i53): (() -> (number, ...any)) | () -> ()
|
||||
|
||||
function World.query(world: World, ...: i53): any
|
||||
local compatibleArchetypes = {}
|
||||
local components = { ... }
|
||||
local archetypes = world.archetypes
|
||||
|
@ -400,12 +399,35 @@ function World.query(world: World, ...: i53): (() -> (number, ...any)) | () -> (
|
|||
end
|
||||
|
||||
local lastArchetype, compatibleArchetype = next(compatibleArchetypes)
|
||||
if not compatibleArchetype then
|
||||
if not lastArchetype then
|
||||
return noop()
|
||||
end
|
||||
|
||||
local lastRow
|
||||
local preparedQuery = {}
|
||||
preparedQuery.__index = preparedQuery
|
||||
|
||||
function preparedQuery:without(...)
|
||||
local components = { ... }
|
||||
for i, component in components do
|
||||
components[i] = #component
|
||||
end
|
||||
for i = #compatibleArchetypes, 1, - 1 do
|
||||
local archetype = compatibleArchetypes[i].archetype
|
||||
local shouldRemove = false
|
||||
for _, componentId in components do
|
||||
if archetype.records[componentId] then
|
||||
shouldRemove = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if shouldRemove then
|
||||
table.remove(compatibleArchetypes, i)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local lastRow
|
||||
function preparedQuery:__iter()
|
||||
return function()
|
||||
local archetype = compatibleArchetype.archetype
|
||||
local indices = compatibleArchetype.indices
|
||||
|
@ -480,6 +502,9 @@ function World.query(world: World, ...: i53): (() -> (number, ...any)) | () -> (
|
|||
|
||||
return entityId, unpack(queryOutput, 1, queryLength)
|
||||
end
|
||||
end
|
||||
|
||||
return setmetatable({}, preparedQuery)
|
||||
end
|
||||
|
||||
function World.component(world: World)
|
||||
|
|
Loading…
Reference in a new issue