registry.batch_apply impl

This commit is contained in:
BlackMATov
2024-11-29 12:53:28 +07:00
parent dd6a6579dd
commit e5f0a54d92
2 changed files with 75 additions and 1 deletions
+47
View File
@@ -415,6 +415,53 @@ do
end
end
do
local f1, f2 = evo.registry.entity(), evo.registry.entity()
local function mul2(v) return v * 2 end
local function null(_) end
local e1 = evo.registry.entity():set(f1, 10)
local e2 = evo.registry.entity():set(f1, 15)
local e3 = evo.registry.entity():set(f1, 20):set(f2, 40)
local e4 = evo.registry.entity():set(f1, 25):set(f2, 45)
do
local q = evo.registry.query(f2)
assert(2 == evo.registry.batch_apply(q, f1, mul2))
assert(e1:get(f1) == 10 and e2:get(f1) == 15 and e3:get(f1) == 40 and e4:get(f1) == 50)
assert(e3:get(f2) == 40 and e4:get(f2) == 45)
end
do
local q = evo.registry.query(f1)
assert(4 == evo.registry.batch_apply(q, f1, mul2))
assert(e1:get(f1) == 20 and e2:get(f1) == 30 and e3:get(f1) == 80 and e4:get(f1) == 100)
assert(e3:get(f2) == 40 and e4:get(f2) == 45)
end
do
local q = evo.registry.query(f1, f2)
assert(2 == evo.registry.batch_apply(q, f1, null))
assert(e1:get(f1) == 20 and e2:get(f1) == 30 and e3:get(f1) == true and e4:get(f1) == true)
assert(e3:get(f2) == 40 and e4:get(f2) == 45)
end
do
local q = evo.registry.query(f1)
assert(2 == evo.registry.batch_apply(q, f2, mul2))
assert(e1:get(f1) == 20 and e2:get(f1) == 30 and e3:get(f1) == true and e4:get(f1) == true)
assert(e3:get(f2) == 80 and e4:get(f2) == 90)
end
do
local q = evo.registry.query(f1):exclude(f2)
assert(2 == evo.registry.batch_apply(q, f1, mul2))
assert(e1:get(f1) == 40 and e2:get(f1) == 60 and e3:get(f1) == true and e4:get(f1) == true)
assert(e3:get(f2) == 80 and e4:get(f2) == 90)
end
end
for _ = 1, 100 do
local insert_fragments = {} ---@type evolved.entity[]
local insert_fragment_count = math.random(0, 10)