diff --git a/benches/query.luau b/benches/query.luau index 54cc7d41..f715d47a 100644 --- a/benches/query.luau +++ b/benches/query.luau @@ -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) diff --git a/src/init.luau b/src/init.luau index 4ccb761d..e4126c60 100644 --- a/src/init.luau +++ b/src/init.luau @@ -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 @@ -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 diff --git a/wally.toml b/wally.toml index 363df92a..026968f6 100644 --- a/wally.toml +++ b/wally.toml @@ -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 = [