From c5db5baaec24bc8d761563b082fe5f25784620cb Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Wed, 27 Nov 2024 10:47:02 +0700 Subject: [PATCH] style fixes --- ROADMAP.md | 3 ++- develop/untests/registry_untests.lua | 15 +++++++++++++++ evolved/registry.lua | 21 ++++++++++++++++----- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/ROADMAP.md b/ROADMAP.md index 91aeeb2..bfe66fa 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -10,4 +10,5 @@ - [ ] cache matched chunks in queries - [x] cache transitions between chunks - [x] chunk's children should be stored in an array instead of a table -- [x] support queries without fragments \ No newline at end of file +- [x] support queries without fragments +- [ ] add assertions for input arguments \ No newline at end of file diff --git a/develop/untests/registry_untests.lua b/develop/untests/registry_untests.lua index 51f8925..060a6b1 100644 --- a/develop/untests/registry_untests.lua +++ b/develop/untests/registry_untests.lua @@ -483,6 +483,21 @@ do assert(not excludes(query, f1) and not excludes(query, f2) and not excludes(query, f3)) end +do + local f1, f2, f3 = + evo.registry.entity(), + evo.registry.entity(), + evo.registry.entity() + + local e1 = evo.registry.entity():set(f2):set(f1) + + local q0 = evo.registry.query() + local q1 = evo.registry.query(f3) + + assert(q0:execute()) + assert(q1:execute()) +end + for _ = 1, 100 do local all_fragments = {} ---@type evolved.entity[] local all_fragment_count = math.random(10, 20) diff --git a/evolved/registry.lua b/evolved/registry.lua index 5b491d7..55d70cd 100644 --- a/evolved/registry.lua +++ b/evolved/registry.lua @@ -654,15 +654,26 @@ end ---@return fun(): evolved.chunk? ---@nodiscard function registry.execute(query) - local main_fragment = query.__include_list[#query.__include_list] - local main_fragment_chunks = __chunks[main_fragment] or {} + local include_list, exclude_list, exclude_set = + query.__include_list, query.__exclude_list, query.__exclude_set + + if #include_list == 0 then + return function() end + end + + local main_fragment = include_list[#include_list] + local main_fragment_chunks = __chunks[main_fragment] + + if main_fragment_chunks == nil or #main_fragment_chunks == 0 then + return function() end + end ---@type evolved.chunk[] local matched_chunk_stack = {} for _, main_fragment_chunk in ipairs(main_fragment_chunks) do - if __chunk_has_all_fragment_list(main_fragment_chunk, query.__include_list) then - if not __chunk_has_any_fragment_list(main_fragment_chunk, query.__exclude_list) then + if __chunk_has_all_fragment_list(main_fragment_chunk, include_list) then + if not __chunk_has_any_fragment_list(main_fragment_chunk, exclude_list) then matched_chunk_stack[#matched_chunk_stack + 1] = main_fragment_chunk end end @@ -674,7 +685,7 @@ function registry.execute(query) matched_chunk_stack[#matched_chunk_stack] = nil for _, matched_chunk_child in ipairs(matched_chunk.__children) do - if not query.__exclude_set[matched_chunk_child.__fragment] then + if not exclude_set[matched_chunk_child.__fragment] then matched_chunk_stack[#matched_chunk_stack + 1] = matched_chunk_child end end