From 6f984b042c7222af7e58b69bed6cd1f2d7d274b2 Mon Sep 17 00:00:00 2001 From: Ukendio Date: Tue, 23 Jul 2024 04:27:27 +0200 Subject: [PATCH] Initial commit --- benches/query.luau | 5 +++++ src/init.luau | 29 ++++++++++++++++++++++++++++- wally.toml | 2 +- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/benches/query.luau b/benches/query.luau index 54cc7d4..f715d47 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 4ccb761..e4126c6 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 363df92..026968f 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 = [