Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add with function to query. #86

Merged
merged 2 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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