From d46df8c0a06a9aa43069a5a6fa24a8ee335ef20b Mon Sep 17 00:00:00 2001 From: Marcus Date: Fri, 26 Jul 2024 16:21:13 +0200 Subject: [PATCH] Initial commit (#86) --- benches/query.luau | 5 +++++ src/init.luau | 28 +++++++++++++++++++++++++++- wally.toml | 2 +- 3 files changed, 33 insertions(+), 2 deletions(-) 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 c4231d8e..0004c6c8 100644 --- a/src/init.luau +++ b/src/init.luau @@ -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? @@ -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) 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 = [