Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ukendio committed Jul 23, 2024
1 parent 0292574 commit 6f984b0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
5 changes: 5 additions & 0 deletions benches/query.luau
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ do
end
end)

BENCH("1 component, 7 tags", function()
for _ in world:query(H):with(G, F, E, D, C, B, A) do
end
end)

local e = world:entity()
world:set(e, A, true)
world:set(e, B, true)
Expand Down
29 changes: 28 additions & 1 deletion src/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,32 @@ do
end
end

local function world_query_with(query, ...)
local ids = { ... }
for i = #compatibleArchetypes, 1, -1 do
local archetype = compatibleArchetypes[i]
local records = archetype.records
local shouldRemove = false

for _, id in ids do
if not records[id] then
shouldRemove = true
break
end
end

if shouldRemove then
table.remove(compatibleArchetypes, i)
end
end

if #compatibleArchetypes == 0 then
return EmptyQuery
end

return query
end

function world_query(world: World, ...: number): Query
-- breaking?
if (...) == nil then
Expand Down Expand Up @@ -924,7 +950,8 @@ do
__iter = world_query_iter,
next = world_query_next,
without = world_query_without,
replace = world_query_replace
with = world_query_with,
replace = world_query_replace,
}

return setmetatable(it, it) :: any
Expand Down
2 changes: 1 addition & 1 deletion wally.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ukendio/jecs"
version = "0.2.3"
version = "0.2.5"
registry = "https://github.com/UpliftGames/wally-index"
realm = "shared"
include = [
Expand Down

0 comments on commit 6f984b0

Please sign in to comment.