chunk function returns entity_count now

This commit is contained in:
BlackMATov
2025-02-22 04:43:03 +07:00
parent 0fdf8d369a
commit e3e7ec2bac
3 changed files with 24 additions and 2 deletions

View File

@@ -87,7 +87,7 @@ batch_multi_assign :: query, fragment[], component[]? -> integer, boolean
batch_multi_insert :: query, fragment[], component[]? -> integer, boolean
batch_multi_remove :: query, fragment[] -> integer, boolean
chunk :: fragment... -> chunk?, entity[]?
chunk :: fragment... -> chunk?, entity[]?, integer?
select :: chunk, fragment... -> component[]...
each :: entity -> {each_state? -> fragment?, component?}, each_state?

View File

@@ -6546,3 +6546,24 @@ do
assert(#after == 2 and after[1] == s1 and after[2] == s2)
end
end
do
local f1, f2 = evo.id(2)
local e1a = evo.entity():set(f1, 1):build()
local e1b = evo.entity():set(f1, 2):build()
local e12 = evo.entity():set(f1, 3):set(f2, 4):build()
do
local c1, c1_es, c1_ec = evo.chunk(f1)
assert(c1 and c1_es and c1_ec)
assert(c1_ec == 2 and #c1_es == 2 and c1_es[1] == e1a and c1_es[2] == e1b)
end
do
local c12, c12_es, c12_ec = evo.chunk(f1, f2)
assert(c12 and c12_es and c12_ec)
assert(c12_ec == 1 and #c12_es == 1 and c12_es[1] == e12)
end
end

View File

@@ -5684,6 +5684,7 @@ end
---@param ... evolved.fragment fragments
---@return evolved.chunk? chunk
---@return evolved.entity[]? entities
---@return integer? entity_count
function evolved.chunk(...)
local chunk = __chunk_fragments(...)
@@ -5691,7 +5692,7 @@ function evolved.chunk(...)
return
end
return chunk, chunk.__entities
return chunk, chunk.__entities, chunk.__entity_count
end
---@param chunk evolved.chunk