style fixes

This commit is contained in:
BlackMATov
2024-11-27 10:47:02 +07:00
parent d2910f2e3f
commit c5db5baaec
3 changed files with 33 additions and 6 deletions

View File

@@ -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
- [x] support queries without fragments
- [ ] add assertions for input arguments

View File

@@ -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)

View File

@@ -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