Skip to content

Commit

Permalink
Initial commit (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ukendio authored Jul 26, 2024
1 parent 2f0f817 commit d46df8c
Show file tree
Hide file tree
Showing 3 changed files with 33 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
28 changes: 27 additions & 1 deletion src/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,31 @@ 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, ...: any): Query
-- breaking?
Expand Down Expand Up @@ -969,8 +994,9 @@ do
local it = {
__iter = world_query_iter,
next = world_query_next,
with = world_query_with,
without = world_query_without,
replace = world_query_replace
replace = world_query_replace,
} :: any

setmetatable(it, it)
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 d46df8c

Please sign in to comment.