first eithers impl

This commit is contained in:
BlackMATov
2026-01-11 20:33:17 +07:00
parent c9f4a74518
commit a5319351c1
2 changed files with 211 additions and 64 deletions
+47 -6
View File
@@ -28,6 +28,20 @@ end
---@param query evolved.query
local function generate_query(query)
local either_set = {}
local either_list = {}
local either_count = 0
for _ = 1, math.random(0, #all_fragment_list) do
local either = all_fragment_list[math.random(1, #all_fragment_list)]
if not either_set[either] then
either_count = either_count + 1
either_set[either] = either_count
either_list[either_count] = either
end
end
local include_set = {}
local include_list = {}
local include_count = 0
@@ -56,6 +70,10 @@ local function generate_query(query)
end
end
if either_count > 0 then
evo.set(query, evo.EITHERS, either_list)
end
if include_count > 0 then
evo.set(query, evo.INCLUDES, include_list)
end
@@ -171,9 +189,19 @@ local function execute_query(query)
local query_chunk_set = {}
local query_entity_set = {}
local query_either_list = evo.get(query, evo.EITHERS) or {}
local query_include_list = evo.get(query, evo.INCLUDES) or {}
local query_exclude_list = evo.get(query, evo.EXCLUDES) or {}
local query_either_count = #query_either_list
local query_include_count = #query_include_list
local query_exclude_count = #query_exclude_list
local query_either_set = {}
for _, either in ipairs(query_either_list) do
query_either_set[either] = true
end
local query_include_set = {}
for _, include in ipairs(query_include_list) do
query_include_set[include] = true
@@ -189,19 +217,29 @@ local function execute_query(query)
query_entity_set[entity] = true
end
assert(chunk:has_all(__table_unpack(query_include_list)))
assert(not chunk:has_any(__table_unpack(query_exclude_list)))
if query_either_count > 0 then
assert(chunk:has_any(__table_unpack(query_either_list)))
end
if query_include_count > 0 then
assert(chunk:has_all(__table_unpack(query_include_list)))
end
if query_exclude_count > 0 then
assert(not chunk:has_any(__table_unpack(query_exclude_list)))
end
end
for i = 1, all_entity_count do
local entity = all_entity_list[i]
local is_entity_matched =
evo.has_all(entity, __table_unpack(query_include_list))
and not evo.has_any(entity, __table_unpack(query_exclude_list))
(query_either_count == 0 or evo.has_any(entity, __table_unpack(query_either_list))) and
(query_include_count == 0 or evo.has_all(entity, __table_unpack(query_include_list))) and
(query_exclude_count == 0 or not evo.has_any(entity, __table_unpack(query_exclude_list)))
for fragment in evo.each(entity) do
if evo.has(fragment, evo.EXPLICIT) and not query_include_set[fragment] then
if evo.has(fragment, evo.EXPLICIT) and not query_either_set[fragment] and not query_include_set[fragment] then
is_entity_matched = false
end
end
@@ -236,7 +274,10 @@ for _ = 1, math.random(1, 5) do
if math.random(1, 2) == 1 then
generate_query(query)
else
if math.random(1, 2) == 1 then
local r = math.random(1, 3)
if r == 1 then
evo.remove(query, evo.EITHERS)
elseif r == 2 then
evo.remove(query, evo.INCLUDES)
else
evo.remove(query, evo.EXCLUDES)