don't match chunks with hidden fragments (while they are not explicit)

This commit is contained in:
BlackMATov
2025-04-28 03:12:30 +07:00
parent bea5058ec0
commit 4632a61bb5
3 changed files with 244 additions and 36 deletions

View File

@@ -0,0 +1,81 @@
local evo = require 'evolved'
evo.debug_mode(true)
---
---
---
---
---
local __table_unpack = (function()
---@diagnostic disable-next-line: deprecated
return table.unpack or unpack
end)()
---
---
---
---
---
local all_entity_list = {} ---@type evolved.entity[]
for i = 1, math.random(1, 10) do
local entity = evo.id()
all_entity_list[i] = entity
end
for _, entity in ipairs(all_entity_list) do
for _ = 0, math.random(0, #all_entity_list) do
local fragment = all_entity_list[math.random(1, #all_entity_list)]
evo.set(entity, fragment)
end
if math.random(1, 5) == 1 then
evo.set(entity, evo.HIDDEN)
end
end
---
---
---
---
---
for _ = 1, 100 do
local include_set = {} ---@type table<evolved.entity, integer>
local include_list = {} ---@type evolved.entity[]
local include_count = 0
for _ = 1, math.random(1, #all_entity_list) do
local include = all_entity_list[math.random(1, #all_entity_list)]
if not include_set[include] then
include_count = include_count + 1
include_set[include] = include_count
include_list[include_count] = include
end
end
local q = evo.builder():include(__table_unpack(include_list)):spawn()
for chunk in evo.execute(q) do
local fragment_list, fragment_count = chunk:fragments()
for i = 1, fragment_count do
local fragment = fragment_list[i]
assert(include_set[fragment] or not evo.has(fragment, evo.HIDDEN))
end
end
evo.destroy(q)
end
---
---
---
---
---
evo.destroy(__table_unpack(all_entity_list))
evo.collect_garbage()

View File

@@ -6235,3 +6235,87 @@ do
assert(evo.has(e, f3) and evo.get(e, f3) == 3)
end
end
do
local f1, f2, f3 = evo.id(3)
evo.set(f2, evo.HIDDEN)
do
local p = evo.spawn { [f1] = 11, [f2] = 22, [f3] = 33 }
local e = evo.clone(p)
assert(evo.has(p, f1) and evo.get(p, f1) == 11)
assert(evo.has(p, f2) and evo.get(p, f2) == 22)
assert(evo.has(p, f3) and evo.get(p, f3) == 33)
assert(evo.has(e, f1) and evo.get(e, f1) == 11)
assert(not evo.has(e, f2) and evo.get(e, f2) == nil)
assert(evo.has(e, f3) and evo.get(e, f3) == 33)
end
end
do
local f1, f2 = evo.id(2)
local p = evo.builder():prefab():set(f1, 11):set(f2, 22):spawn()
local e = evo.clone(p)
do
local q = evo.builder():include(f1, f2):spawn()
local iter, state = evo.execute(q)
local chunk, entity_list, entity_count = iter(state)
assert(chunk and entity_list and entity_count)
assert(chunk == evo.chunk(f1, f2))
assert(entity_count == 1 and entity_list[1] == e)
end
do
local q = evo.builder():exclude(f1):spawn()
for c in evo.execute(q) do
local fs, fc = c:fragments()
for i = 1, fc do assert(not evo.has(fs[i], evo.HIDDEN)) end
end
end
do
local q = evo.builder():spawn()
for c in evo.execute(q) do
local fs, fc = c:fragments()
for i = 1, fc do assert(not evo.has(fs[i], evo.HIDDEN)) end
end
end
end
do
local f1, f2 = evo.id(2)
evo.set(f2, evo.HIDDEN)
local e1 = evo.builder():set(f1, 11):spawn()
local e2 = evo.builder():set(f1, 11):set(f2, 22):spawn()
do
local q = evo.builder():include(f1):spawn()
local iter, state = evo.execute(q)
local chunk, entity_list, entity_count = iter(state)
assert(chunk and entity_list and entity_count)
assert(chunk == evo.chunk(f1))
assert(entity_count == 1 and entity_list[1] == e1)
chunk, entity_list, entity_count = iter(state)
assert(not chunk and not entity_list and not entity_count)
end
do
local q = evo.builder():include(f1, f2):spawn()
local iter, state = evo.execute(q)
local chunk, entity_list, entity_count = iter(state)
assert(chunk and entity_list and entity_count)
assert(chunk == evo.chunk(f1, f2))
assert(entity_count == 1 and entity_list[1] == e2)
chunk, entity_list, entity_count = iter(state)
assert(not chunk and not entity_list and not entity_count)
end
end