rename select to components

This commit is contained in:
BlackMATov
2025-03-17 15:21:52 +07:00
parent 3cec68e98e
commit 9aa7758fc2
6 changed files with 127 additions and 128 deletions

View File

@@ -98,10 +98,10 @@ batch_multi_insert :: query, fragment[], component[]? -> integer, boolean
batch_multi_remove :: query, fragment[] -> integer, boolean batch_multi_remove :: query, fragment[] -> integer, boolean
chunk :: fragment... -> chunk?, entity[]?, integer? chunk :: fragment... -> chunk?, entity[]?, integer?
select :: chunk, fragment... -> component[]...
entities :: chunk -> entity[], integer entities :: chunk -> entity[], integer
fragments :: chunk -> fragment[], integer fragments :: chunk -> fragment[], integer
components :: chunk, fragment... -> component[]...
each :: entity -> {each_state? -> fragment?, component?}, each_state? each :: entity -> {each_state? -> fragment?, component?}, each_state?
execute :: query -> {execute_state? -> chunk?, entity[]?, integer?}, execute_state? execute :: query -> {execute_state? -> chunk?, entity[]?, integer?}, execute_state?

View File

@@ -3,7 +3,6 @@
## Backlog ## Backlog
- add has, has_all, has_any for chunks - add has, has_all, has_any for chunks
- rename `select` function to `components`
## After first release ## After first release

View File

@@ -60,7 +60,7 @@ local integrate_forces_system = evo.system()
evo.get(singles.physics_gravity, singles.physics_gravity) evo.get(singles.physics_gravity, singles.physics_gravity)
---@type evolved.vector2[], evolved.vector2[] ---@type evolved.vector2[], evolved.vector2[]
local forces, velocities = evo.select(chunk, local forces, velocities = evo.components(chunk,
fragments.force, fragments.velocity) fragments.force, fragments.velocity)
for i = 1, entity_count do for i = 1, entity_count do
@@ -81,7 +81,7 @@ local integrate_velocities_system = evo.system()
evo.get(singles.delta_time, singles.delta_time) evo.get(singles.delta_time, singles.delta_time)
---@type evolved.vector2[], evolved.vector2[], evolved.vector2[] ---@type evolved.vector2[], evolved.vector2[], evolved.vector2[]
local forces, positions, velocities = evo.select(chunk, local forces, positions, velocities = evo.components(chunk,
fragments.force, fragments.position, fragments.velocity) fragments.force, fragments.position, fragments.velocity)
for i = 1, entity_count do for i = 1, entity_count do
@@ -100,7 +100,7 @@ local graphics_system = evo.system()
:query(queries.physics_bodies) :query(queries.physics_bodies)
:execute(function(chunk, entities, entity_count) :execute(function(chunk, entities, entity_count)
---@type evolved.vector2[] ---@type evolved.vector2[]
local positions = evo.select(chunk, local positions = evo.components(chunk,
fragments.position) fragments.position)
for i = 1, entity_count do for i = 1, entity_count do

View File

@@ -655,7 +655,7 @@ do
do do
local chunk, entities = evo.chunk(f1) local chunk, entities = evo.chunk(f1)
assert(entities and entities[1] == e1) assert(entities and entities[1] == e1)
assert(chunk and evo.select(chunk, f1)[1] == 41) assert(chunk and evo.components(chunk, f1)[1] == 41)
end end
do do
@@ -667,8 +667,8 @@ do
assert(chunk == evo.chunk(f2, f1)) assert(chunk == evo.chunk(f2, f1))
assert(chunk == evo.chunk(f2, f1, f2, f1)) assert(chunk == evo.chunk(f2, f1, f2, f1))
assert(entities and entities[1] == e2 and entities[2] == e2b) assert(entities and entities[1] == e2 and entities[2] == e2b)
assert(chunk and evo.select(chunk, f1)[1] == 42 and evo.select(chunk, f2)[1] == 43) assert(chunk and evo.components(chunk, f1)[1] == 42 and evo.components(chunk, f2)[1] == 43)
assert(chunk and evo.select(chunk, f1)[2] == 44 and evo.select(chunk, f2)[2] == 45) assert(chunk and evo.components(chunk, f1)[2] == 44 and evo.components(chunk, f2)[2] == 45)
end end
do do
@@ -1969,9 +1969,9 @@ do
assert(chunk_entities[1] == e3 and chunk_entities[2] == e1) assert(chunk_entities[1] == e3 and chunk_entities[2] == e1)
assert(#evo.select(chunk, f1) == 0) assert(#evo.components(chunk, f1) == 0)
assert(#evo.select(chunk, f2) == 0) assert(#evo.components(chunk, f2) == 0)
assert(evo.select(chunk, f3)[1] == 43 and evo.select(chunk, f3)[2] == 50) assert(evo.components(chunk, f3)[1] == 43 and evo.components(chunk, f3)[2] == 50)
end end
end end
end end
@@ -2010,9 +2010,9 @@ do
assert(chunk and chunk_entities) assert(chunk and chunk_entities)
assert(chunk_entities[1] == e1) assert(chunk_entities[1] == e1)
assert(#evo.select(chunk, f1) == 0) assert(#evo.components(chunk, f1) == 0)
assert(#evo.select(chunk, f2) == 0) assert(#evo.components(chunk, f2) == 0)
assert(#evo.select(chunk, f3) == 0) assert(#evo.components(chunk, f3) == 0)
end end
do do
@@ -2020,9 +2020,9 @@ do
assert(chunk and chunk_entities) assert(chunk and chunk_entities)
assert(chunk_entities[1] == e3) assert(chunk_entities[1] == e3)
assert(#evo.select(chunk, f1) == 0) assert(#evo.components(chunk, f1) == 0)
assert(#evo.select(chunk, f2) == 0) assert(#evo.components(chunk, f2) == 0)
assert(evo.select(chunk, f3)[1] == 43) assert(evo.components(chunk, f3)[1] == 43)
end end
end end
end end
@@ -2065,9 +2065,9 @@ do
assert(chunk and chunk_entities) assert(chunk and chunk_entities)
assert(next(chunk_entities) == nil) assert(next(chunk_entities) == nil)
assert(#evo.select(chunk, f1) == 0) assert(#evo.components(chunk, f1) == 0)
assert(#evo.select(chunk, f2) == 0) assert(#evo.components(chunk, f2) == 0)
assert(#evo.select(chunk, f3) == 0) assert(#evo.components(chunk, f3) == 0)
end end
end end
end end
@@ -2110,9 +2110,9 @@ do
assert(chunk and chunk_entities) assert(chunk and chunk_entities)
assert(next(chunk_entities) == nil) assert(next(chunk_entities) == nil)
assert(#evo.select(chunk, f1) == 0) assert(#evo.components(chunk, f1) == 0)
assert(#evo.select(chunk, f2) == 0) assert(#evo.components(chunk, f2) == 0)
assert(#evo.select(chunk, f3) == 0) assert(#evo.components(chunk, f3) == 0)
end end
end end
end end
@@ -2729,7 +2729,7 @@ do
do do
local chunk, entities = evo.chunk(f1, f2) local chunk, entities = evo.chunk(f1, f2)
assert(entities and #entities == 1 and entities[1] == e2) assert(entities and #entities == 1 and entities[1] == e2)
assert(chunk and evo.select(chunk, f2)[1] == 44) assert(chunk and evo.components(chunk, f2)[1] == 44)
end end
end end
@@ -2978,13 +2978,13 @@ do
do do
local chunk, entities = evo.chunk(f1, f2, f3) local chunk, entities = evo.chunk(f1, f2, f3)
assert(entities and #entities == 1 and entities[1] == e2) assert(entities and #entities == 1 and entities[1] == e2)
assert(chunk and evo.select(chunk, f2)[1] == 45) assert(chunk and evo.components(chunk, f2)[1] == 45)
end end
do do
local chunk, entities = evo.chunk(f3) local chunk, entities = evo.chunk(f3)
assert(entities and #entities == 1 and entities[1] == e1) assert(entities and #entities == 1 and entities[1] == e1)
assert(chunk and evo.select(chunk, f3)[1] == 43) assert(chunk and evo.components(chunk, f3)[1] == 43)
end end
end end
end end
@@ -3890,7 +3890,7 @@ do
assert(evo.get(e4, f4) == nil) assert(evo.get(e4, f4) == nil)
for chunk in evo.execute(q) do for chunk in evo.execute(q) do
assert(next(evo.select(chunk, f4)) == nil) assert(next(evo.components(chunk, f4)) == nil)
end end
do do
@@ -3898,14 +3898,14 @@ do
assert(chunk and entities) assert(chunk and entities)
assert(#entities == 2) assert(#entities == 2)
assert(entities[1] == e3, entities[2] == e4) assert(entities[1] == e3, entities[2] == e4)
assert(evo.select(chunk, f2)[1] == 32 and evo.select(chunk, f3)[1] == 33) assert(evo.components(chunk, f2)[1] == 32 and evo.components(chunk, f3)[1] == 33)
assert(evo.select(chunk, f2)[2] == 42 and evo.select(chunk, f3)[2] == 43) assert(evo.components(chunk, f2)[2] == 42 and evo.components(chunk, f3)[2] == 43)
end end
do do
local chunk, entities = evo.chunk(f1, f2, f3, f4) local chunk, entities = evo.chunk(f1, f2, f3, f4)
assert(chunk) assert(chunk)
assert(next(evo.select(chunk, f4)) == nil) assert(next(evo.components(chunk, f4)) == nil)
assert(#entities == 0) assert(#entities == 0)
end end
end end
@@ -3920,7 +3920,7 @@ do
assert(evo.has_all(e4, f2, f3) and not evo.has_any(e4, f1, f4)) assert(evo.has_all(e4, f2, f3) and not evo.has_any(e4, f1, f4))
for chunk in evo.execute(q) do for chunk in evo.execute(q) do
assert(next(evo.select(chunk, f1)) == nil) assert(next(evo.components(chunk, f1)) == nil)
end end
assert(evo.batch_multi_remove(q, { f2, f3 }) == 3) assert(evo.batch_multi_remove(q, { f2, f3 }) == 3)
@@ -3930,24 +3930,24 @@ do
assert(not evo.has_any(e4, f1, f2, f3, f4)) assert(not evo.has_any(e4, f1, f2, f3, f4))
for chunk in evo.execute(q) do for chunk in evo.execute(q) do
assert(next(evo.select(chunk, f2)) == nil) assert(next(evo.components(chunk, f2)) == nil)
assert(next(evo.select(chunk, f3)) == nil) assert(next(evo.components(chunk, f3)) == nil)
end end
do do
local chunk, entities = evo.chunk(f1, f2) local chunk, entities = evo.chunk(f1, f2)
assert(chunk) assert(chunk)
assert(next(evo.select(chunk, f1)) == nil) assert(next(evo.components(chunk, f1)) == nil)
assert(next(evo.select(chunk, f2)) == nil) assert(next(evo.components(chunk, f2)) == nil)
assert(#entities == 0) assert(#entities == 0)
end end
do do
local chunk, entities = evo.chunk(f1, f2, f3) local chunk, entities = evo.chunk(f1, f2, f3)
assert(chunk) assert(chunk)
assert(next(evo.select(chunk, f1)) == nil) assert(next(evo.components(chunk, f1)) == nil)
assert(next(evo.select(chunk, f2)) == nil) assert(next(evo.components(chunk, f2)) == nil)
assert(next(evo.select(chunk, f3)) == nil) assert(next(evo.components(chunk, f3)) == nil)
assert(#entities == 0) assert(#entities == 0)
end end
end end
@@ -4248,16 +4248,16 @@ do
do do
local c123, c123_es = evo.chunk(f1, f2, f3) local c123, c123_es = evo.chunk(f1, f2, f3)
assert(c123 and #c123_es == 0) assert(c123 and #c123_es == 0)
assert(#evo.select(c123, f1) == 0) assert(#evo.components(c123, f1) == 0)
assert(#evo.select(c123, f2) == 0) assert(#evo.components(c123, f2) == 0)
assert(#evo.select(c123, f3) == 0) assert(#evo.components(c123, f3) == 0)
local c1234, c1234_es = evo.chunk(f1, f2, f3, f4) local c1234, c1234_es = evo.chunk(f1, f2, f3, f4)
assert(c1234 and #c1234_es == 2) assert(c1234 and #c1234_es == 2)
assert(#evo.select(c1234, f1) == 2) assert(#evo.components(c1234, f1) == 2)
assert(#evo.select(c1234, f2) == 2) assert(#evo.components(c1234, f2) == 2)
assert(#evo.select(c1234, f3) == 2) assert(#evo.components(c1234, f3) == 2)
assert(#evo.select(c1234, f4) == 2) assert(#evo.components(c1234, f4) == 2)
end end
end end
@@ -4273,31 +4273,31 @@ do
do do
local c1, c1_es = evo.chunk(f1) local c1, c1_es = evo.chunk(f1)
assert(c1 and #c1_es == 0) assert(c1 and #c1_es == 0)
assert(#evo.select(c1, f1) == 0) assert(#evo.components(c1, f1) == 0)
end end
do do
local c12, c12_es = evo.chunk(f1, f2) local c12, c12_es = evo.chunk(f1, f2)
assert(c12 and #c12_es == 0) assert(c12 and #c12_es == 0)
assert(#evo.select(c12, f1) == 0) assert(#evo.components(c12, f1) == 0)
assert(#evo.select(c12, f2) == 0) assert(#evo.components(c12, f2) == 0)
end end
do do
local c134, c134_es = evo.chunk(f1, f3, f4) local c134, c134_es = evo.chunk(f1, f3, f4)
assert(c134 and #c134_es == 1) assert(c134 and #c134_es == 1)
assert(#evo.select(c134, f1) == 1) assert(#evo.components(c134, f1) == 1)
assert(#evo.select(c134, f3) == 1) assert(#evo.components(c134, f3) == 1)
assert(#evo.select(c134, f4) == 1) assert(#evo.components(c134, f4) == 1)
end end
do do
local c1234, c1234_es = evo.chunk(f1, f2, f3, f4) local c1234, c1234_es = evo.chunk(f1, f2, f3, f4)
assert(c1234 and #c1234_es == 3) assert(c1234 and #c1234_es == 3)
assert(#evo.select(c1234, f1) == 3) assert(#evo.components(c1234, f1) == 3)
assert(#evo.select(c1234, f2) == 3) assert(#evo.components(c1234, f2) == 3)
assert(#evo.select(c1234, f3) == 3) assert(#evo.components(c1234, f3) == 3)
assert(#evo.select(c1234, f4) == 3) assert(#evo.components(c1234, f4) == 3)
end end
end end
end end
@@ -4675,14 +4675,14 @@ do
do do
local c12, c12_es = evo.chunk(f1, f2) local c12, c12_es = evo.chunk(f1, f2)
assert(c12 and #c12_es == 0) assert(c12 and #c12_es == 0)
assert(#evo.select(c12, f1) == 0) assert(#evo.components(c12, f1) == 0)
assert(#evo.select(c12, f2) == 0) assert(#evo.components(c12, f2) == 0)
local c123, c123_es = evo.chunk(f1, f2, f3) local c123, c123_es = evo.chunk(f1, f2, f3)
assert(c123 and #c123_es == 4) assert(c123 and #c123_es == 4)
assert(#evo.select(c123, f1) == 4) assert(#evo.components(c123, f1) == 4)
assert(#evo.select(c123, f2) == 4) assert(#evo.components(c123, f2) == 4)
assert(#evo.select(c123, f3) == 4) assert(#evo.components(c123, f3) == 4)
end end
end end
@@ -4704,12 +4704,12 @@ do
do do
local c1, c1_es = evo.chunk(f1) local c1, c1_es = evo.chunk(f1)
assert(c1 and #c1_es == 0) assert(c1 and #c1_es == 0)
assert(#evo.select(c1, f1) == 0) assert(#evo.components(c1, f1) == 0)
local c12, c12_es = evo.chunk(f1, f2) local c12, c12_es = evo.chunk(f1, f2)
assert(c12 and #c12_es == 2) assert(c12 and #c12_es == 2)
assert(#evo.select(c12, f1) == 2) assert(#evo.components(c12, f1) == 2)
assert(#evo.select(c12, f2) == 2) assert(#evo.components(c12, f2) == 2)
end end
end end
end end
@@ -5247,20 +5247,20 @@ do
assert(c and es and #es == 1 and es[1] == e) assert(c and es and #es == 1 and es[1] == e)
do do
local c1, c2 = evo.select(c, f1, f2) local c1, c2 = evo.components(c, f1, f2)
assert(c1 and #c1 == 1 and c1[1] == 1) assert(c1 and #c1 == 1 and c1[1] == 1)
assert(c2 and #c2 == 1 and c2[1] == 2) assert(c2 and #c2 == 1 and c2[1] == 2)
end end
do do
local c1, c2, c3 = evo.select(c, f1, f2, f3) local c1, c2, c3 = evo.components(c, f1, f2, f3)
assert(c1 and #c1 == 1 and c1[1] == 1) assert(c1 and #c1 == 1 and c1[1] == 1)
assert(c2 and #c2 == 1 and c2[1] == 2) assert(c2 and #c2 == 1 and c2[1] == 2)
assert(c3 and #c3 == 1 and c3[1] == 3) assert(c3 and #c3 == 1 and c3[1] == 3)
end end
do do
local c1, c2, c3, c4 = evo.select(c, f1, f2, f3, f4) local c1, c2, c3, c4 = evo.components(c, f1, f2, f3, f4)
assert(c1 and #c1 == 1 and c1[1] == 1) assert(c1 and #c1 == 1 and c1[1] == 1)
assert(c2 and #c2 == 1 and c2[1] == 2) assert(c2 and #c2 == 1 and c2[1] == 2)
assert(c3 and #c3 == 1 and c3[1] == 3) assert(c3 and #c3 == 1 and c3[1] == 3)
@@ -5268,7 +5268,7 @@ do
end end
do do
local c1, c2, c3, c4, c5 = evo.select(c, f1, f2, f3, f4, f5) local c1, c2, c3, c4, c5 = evo.components(c, f1, f2, f3, f4, f5)
assert(c1 and #c1 == 1 and c1[1] == 1) assert(c1 and #c1 == 1 and c1[1] == 1)
assert(c2 and #c2 == 1 and c2[1] == 2) assert(c2 and #c2 == 1 and c2[1] == 2)
assert(c3 and #c3 == 1 and c3[1] == 3) assert(c3 and #c3 == 1 and c3[1] == 3)
@@ -6460,7 +6460,7 @@ do
local c1, c1_es = evo.chunk(f1) local c1, c1_es = evo.chunk(f1)
assert(c1 and c1_es and #c1_es == 2) assert(c1 and c1_es and #c1_es == 2)
assert(c1_es[1] == e1a and c1_es[2] == e1b) assert(c1_es[1] == e1a and c1_es[2] == e1b)
assert(evo.select(c1, f1)[1] == 1 and evo.select(c1, f1)[2] == 11) assert(evo.components(c1, f1)[1] == 1 and evo.components(c1, f1)[2] == 11)
end end
assert(evo.batch_insert(q1, f2, 2) == 2) assert(evo.batch_insert(q1, f2, 2) == 2)
@@ -6472,8 +6472,8 @@ do
local c12, c12_es = evo.chunk(f1, f2) local c12, c12_es = evo.chunk(f1, f2)
assert(c12 and c12_es and #c12_es == 2) assert(c12 and c12_es and #c12_es == 2)
assert(c12_es[1] == e1a and c12_es[2] == e1b) assert(c12_es[1] == e1a and c12_es[2] == e1b)
assert(evo.select(c12, f1)[1] == 1 and evo.select(c12, f1)[2] == 11) assert(evo.components(c12, f1)[1] == 1 and evo.components(c12, f1)[2] == 11)
assert(evo.select(c12, f2)[1] == 2 and evo.select(c12, f2)[2] == 2) assert(evo.components(c12, f2)[1] == 2 and evo.components(c12, f2)[2] == 2)
end end
local e1c = evo.entity():set(f1, 111):build() local e1c = evo.entity():set(f1, 111):build()
@@ -6483,7 +6483,7 @@ do
local c1, c1_es = evo.chunk(f1) local c1, c1_es = evo.chunk(f1)
assert(c1 and c1_es and #c1_es == 2) assert(c1 and c1_es and #c1_es == 2)
assert(c1_es[1] == e1c and c1_es[2] == e1d) assert(c1_es[1] == e1c and c1_es[2] == e1d)
assert(evo.select(c1, f1)[1] == 111 and evo.select(c1, f1)[2] == 1111) assert(evo.components(c1, f1)[1] == 111 and evo.components(c1, f1)[2] == 1111)
end end
assert(evo.batch_insert(q1, f2, 22) == 2) assert(evo.batch_insert(q1, f2, 22) == 2)
@@ -6496,10 +6496,10 @@ do
assert(c12 and c12_es and #c12_es == 4) assert(c12 and c12_es and #c12_es == 4)
assert(c12_es[1] == e1a and c12_es[2] == e1b) assert(c12_es[1] == e1a and c12_es[2] == e1b)
assert(c12_es[3] == e1c and c12_es[4] == e1d) assert(c12_es[3] == e1c and c12_es[4] == e1d)
assert(evo.select(c12, f1)[1] == 1 and evo.select(c12, f1)[2] == 11) assert(evo.components(c12, f1)[1] == 1 and evo.components(c12, f1)[2] == 11)
assert(evo.select(c12, f1)[3] == 111 and evo.select(c12, f1)[4] == 1111) assert(evo.components(c12, f1)[3] == 111 and evo.components(c12, f1)[4] == 1111)
assert(evo.select(c12, f2)[1] == 2 and evo.select(c12, f2)[2] == 2) assert(evo.components(c12, f2)[1] == 2 and evo.components(c12, f2)[2] == 2)
assert(evo.select(c12, f2)[3] == 22 and evo.select(c12, f2)[4] == 22) assert(evo.components(c12, f2)[3] == 22 and evo.components(c12, f2)[4] == 22)
end end
end end
@@ -6515,9 +6515,9 @@ do
local c123, c123_es = evo.chunk(f1, f2, f3) local c123, c123_es = evo.chunk(f1, f2, f3)
assert(c123 and c123_es and #c123_es == 2) assert(c123 and c123_es and #c123_es == 2)
assert(c123_es[1] == e123a and c123_es[2] == e123b) assert(c123_es[1] == e123a and c123_es[2] == e123b)
assert(evo.select(c123, f1)[1] == 1 and evo.select(c123, f1)[2] == 11) assert(evo.components(c123, f1)[1] == 1 and evo.components(c123, f1)[2] == 11)
assert(evo.select(c123, f2)[1] == 2 and evo.select(c123, f2)[2] == 22) assert(evo.components(c123, f2)[1] == 2 and evo.components(c123, f2)[2] == 22)
assert(evo.select(c123, f3)[1] == 3 and evo.select(c123, f3)[2] == 33) assert(evo.components(c123, f3)[1] == 3 and evo.components(c123, f3)[2] == 33)
end end
assert(evo.batch_remove(q1, f2) == 2) assert(evo.batch_remove(q1, f2) == 2)
@@ -6526,9 +6526,9 @@ do
local c13, c13_es = evo.chunk(f3, f1) local c13, c13_es = evo.chunk(f3, f1)
assert(c13 and c13_es and #c13_es == 2) assert(c13 and c13_es and #c13_es == 2)
assert(c13_es[1] == e123a and c13_es[2] == e123b) assert(c13_es[1] == e123a and c13_es[2] == e123b)
assert(evo.select(c13, f1)[1] == 1 and evo.select(c13, f1)[2] == 11) assert(evo.components(c13, f1)[1] == 1 and evo.components(c13, f1)[2] == 11)
assert(evo.select(c13, f2)[1] == nil and evo.select(c13, f2)[2] == nil) assert(evo.components(c13, f2)[1] == nil and evo.components(c13, f2)[2] == nil)
assert(evo.select(c13, f3)[1] == 3 and evo.select(c13, f3)[2] == 33) assert(evo.components(c13, f3)[1] == 3 and evo.components(c13, f3)[2] == 33)
end end
local e3a = evo.entity():set(f3, 3):build() local e3a = evo.entity():set(f3, 3):build()
@@ -6538,7 +6538,7 @@ do
local c3, c3_es = evo.chunk(f3) local c3, c3_es = evo.chunk(f3)
assert(c3 and c3_es and #c3_es == 2) assert(c3 and c3_es and #c3_es == 2)
assert(c3_es[1] == e3a and c3_es[2] == e3b) assert(c3_es[1] == e3a and c3_es[2] == e3b)
assert(evo.select(c3, f3)[1] == 3 and evo.select(c3, f3)[2] == 33) assert(evo.components(c3, f3)[1] == 3 and evo.components(c3, f3)[2] == 33)
end end
assert(evo.batch_remove(q1, f1) == 2) assert(evo.batch_remove(q1, f1) == 2)
@@ -6548,12 +6548,12 @@ do
assert(c3 and c3_es and #c3_es == 4) assert(c3 and c3_es and #c3_es == 4)
assert(c3_es[1] == e3a and c3_es[2] == e3b) assert(c3_es[1] == e3a and c3_es[2] == e3b)
assert(c3_es[3] == e123a and c3_es[4] == e123b) assert(c3_es[3] == e123a and c3_es[4] == e123b)
assert(evo.select(c3, f1)[1] == nil and evo.select(c3, f1)[2] == nil) assert(evo.components(c3, f1)[1] == nil and evo.components(c3, f1)[2] == nil)
assert(evo.select(c3, f1)[3] == nil and evo.select(c3, f1)[4] == nil) assert(evo.components(c3, f1)[3] == nil and evo.components(c3, f1)[4] == nil)
assert(evo.select(c3, f2)[1] == nil and evo.select(c3, f2)[2] == nil) assert(evo.components(c3, f2)[1] == nil and evo.components(c3, f2)[2] == nil)
assert(evo.select(c3, f2)[3] == nil and evo.select(c3, f2)[4] == nil) assert(evo.components(c3, f2)[3] == nil and evo.components(c3, f2)[4] == nil)
assert(evo.select(c3, f3)[1] == 3 and evo.select(c3, f3)[2] == 33) assert(evo.components(c3, f3)[1] == 3 and evo.components(c3, f3)[2] == 33)
assert(evo.select(c3, f3)[3] == 3 and evo.select(c3, f3)[4] == 33) assert(evo.components(c3, f3)[3] == 3 and evo.components(c3, f3)[4] == 33)
end end
end end

View File

@@ -41,7 +41,7 @@ basics.describe_bench(string.format('Evolved Entity Cycle (Defer): %d entities',
evo.defer() evo.defer()
do do
for chunk, entities in evo.execute(A) do for chunk, entities in evo.execute(A) do
local as = evo.select(chunk, a) local as = evo.components(chunk, a)
for i = 1, #entities do for i = 1, #entities do
evo.set(evo.id(), b, as[i]) evo.set(evo.id(), b, as[i])
end end
@@ -70,7 +70,7 @@ basics.describe_bench(string.format('Evolved Entity Cycle (Manual): %d entities'
local to_create = {} local to_create = {}
for chunk, entities in evo.execute(A) do for chunk, entities in evo.execute(A) do
local as = evo.select(chunk, a) local as = evo.components(chunk, a)
for i = 1, #entities do for i = 1, #entities do
to_create[#to_create + 1] = as[i] to_create[#to_create + 1] = as[i]
end end
@@ -144,21 +144,21 @@ basics.describe_bench(string.format('Evolved Simple Iteration: %d entities', N),
---@param CE evolved.query ---@param CE evolved.query
function(a, b, c, d, e, AB, CD, CE) function(a, b, c, d, e, AB, CD, CE)
for chunk, entities in evo.execute(AB) do for chunk, entities in evo.execute(AB) do
local as, bs = evo.select(chunk, a, b) local as, bs = evo.components(chunk, a, b)
for i = 1, #entities do for i = 1, #entities do
as[i], bs[i] = bs[i], as[i] as[i], bs[i] = bs[i], as[i]
end end
end end
for chunk, entities in evo.execute(CD) do for chunk, entities in evo.execute(CD) do
local cs, ds = evo.select(chunk, c, d) local cs, ds = evo.components(chunk, c, d)
for i = 1, #entities do for i = 1, #entities do
cs[i], ds[i] = ds[i], cs[i] cs[i], ds[i] = ds[i], cs[i]
end end
end end
for chunk, entities in evo.execute(CE) do for chunk, entities in evo.execute(CE) do
local cs, es = evo.select(chunk, c, e) local cs, es = evo.components(chunk, c, e)
for i = 1, #entities do for i = 1, #entities do
cs[i], es[i] = es[i], cs[i] cs[i], es[i] = es[i], cs[i]
end end
@@ -240,35 +240,35 @@ basics.describe_bench(string.format('Evolved Packed Iteration: %d entities', N),
---@param E evolved.query ---@param E evolved.query
function(a, b, c, d, e, A, B, C, D, E) function(a, b, c, d, e, A, B, C, D, E)
for chunk, entities in evo.execute(A) do for chunk, entities in evo.execute(A) do
local as = evo.select(chunk, a) local as = evo.components(chunk, a)
for i = 1, #entities do for i = 1, #entities do
as[i] = as[i] * 2 as[i] = as[i] * 2
end end
end end
for chunk, entities in evo.execute(B) do for chunk, entities in evo.execute(B) do
local bs = evo.select(chunk, b) local bs = evo.components(chunk, b)
for i = 1, #entities do for i = 1, #entities do
bs[i] = bs[i] * 2 bs[i] = bs[i] * 2
end end
end end
for chunk, entities in evo.execute(C) do for chunk, entities in evo.execute(C) do
local cs = evo.select(chunk, c) local cs = evo.components(chunk, c)
for i = 1, #entities do for i = 1, #entities do
cs[i] = cs[i] * 2 cs[i] = cs[i] * 2
end end
end end
for chunk, entities in evo.execute(D) do for chunk, entities in evo.execute(D) do
local ds = evo.select(chunk, d) local ds = evo.components(chunk, d)
for i = 1, #entities do for i = 1, #entities do
ds[i] = ds[i] * 2 ds[i] = ds[i] * 2
end end
end end
for chunk, entities in evo.execute(E) do for chunk, entities in evo.execute(E) do
local es = evo.select(chunk, e) local es = evo.components(chunk, e)
for i = 1, #entities do for i = 1, #entities do
es[i] = es[i] * 2 es[i] = es[i] * 2
end end
@@ -335,14 +335,14 @@ basics.describe_bench(string.format('Evolved Fragmented Iteration: %d entities',
---@param Last evolved.query ---@param Last evolved.query
function(data, last, Data, Last) function(data, last, Data, Last)
for chunk, entities in evo.execute(Data) do for chunk, entities in evo.execute(Data) do
local ds = evo.select(chunk, data) local ds = evo.components(chunk, data)
for i = 1, #entities do for i = 1, #entities do
ds[i] = ds[i] * 2 ds[i] = ds[i] * 2
end end
end end
for chunk, entities in evo.execute(Last) do for chunk, entities in evo.execute(Last) do
local ls = evo.select(chunk, last) local ls = evo.components(chunk, last)
for i = 1, #entities do for i = 1, #entities do
ls[i] = ls[i] * 2 ls[i] = ls[i] * 2
end end

View File

@@ -672,9 +672,9 @@ local __evolved_batch_multi_insert
local __evolved_batch_multi_remove local __evolved_batch_multi_remove
local __evolved_chunk local __evolved_chunk
local __evolved_select
local __evolved_entities local __evolved_entities
local __evolved_fragments local __evolved_fragments
local __evolved_components
local __evolved_each local __evolved_each
local __evolved_execute local __evolved_execute
@@ -7017,11 +7017,35 @@ __evolved_chunk = function(...)
return chunk, chunk.__entity_list, chunk.__entity_count return chunk, chunk.__entity_list, chunk.__entity_count
end end
---@param chunk evolved.chunk
---@return evolved.entity[] entity_list
---@return integer entity_count
---@nodiscard
__evolved_entities = function(chunk)
if __debug_mode then
__validate_chunk(chunk)
end
return chunk.__entity_list, chunk.__entity_count
end
---@param chunk evolved.chunk
---@return evolved.fragment[] fragments
---@return integer fragment_count
---@nodiscard
__evolved_fragments = function(chunk)
if __debug_mode then
__validate_chunk(chunk)
end
return chunk.__fragment_list, chunk.__fragment_count
end
---@param chunk evolved.chunk ---@param chunk evolved.chunk
---@param ... evolved.fragment fragments ---@param ... evolved.fragment fragments
---@return evolved.storage ... storages ---@return evolved.storage ... storages
---@nodiscard ---@nodiscard
__evolved_select = function(chunk, ...) __evolved_components = function(chunk, ...)
local fragment_count = __lua_select('#', ...) local fragment_count = __lua_select('#', ...)
if fragment_count == 0 then if fragment_count == 0 then
@@ -7080,34 +7104,10 @@ __evolved_select = function(chunk, ...)
i2 and storages[i2] or empty_component_storage, i2 and storages[i2] or empty_component_storage,
i3 and storages[i3] or empty_component_storage, i3 and storages[i3] or empty_component_storage,
i4 and storages[i4] or empty_component_storage, i4 and storages[i4] or empty_component_storage,
__evolved_select(chunk, __lua_select(5, ...)) __evolved_components(chunk, __lua_select(5, ...))
end end
end end
---@param chunk evolved.chunk
---@return evolved.entity[] entity_list
---@return integer entity_count
---@nodiscard
__evolved_entities = function(chunk)
if __debug_mode then
__validate_chunk(chunk)
end
return chunk.__entity_list, chunk.__entity_count
end
---@param chunk evolved.chunk
---@return evolved.fragment[] fragments
---@return integer fragment_count
---@nodiscard
__evolved_fragments = function(chunk)
if __debug_mode then
__validate_chunk(chunk)
end
return chunk.__fragment_list, chunk.__fragment_count
end
---@param entity evolved.entity ---@param entity evolved.entity
---@return evolved.each_iterator iterator ---@return evolved.each_iterator iterator
---@return evolved.each_state? iterator_state ---@return evolved.each_state? iterator_state
@@ -8492,10 +8492,10 @@ evolved.batch_multi_insert = __evolved_batch_multi_insert
evolved.batch_multi_remove = __evolved_batch_multi_remove evolved.batch_multi_remove = __evolved_batch_multi_remove
evolved.chunk = __evolved_chunk evolved.chunk = __evolved_chunk
evolved.select = __evolved_select
evolved.entities = __evolved_entities evolved.entities = __evolved_entities
evolved.fragments = __evolved_fragments evolved.fragments = __evolved_fragments
evolved.components = __evolved_components
evolved.each = __evolved_each evolved.each = __evolved_each
evolved.execute = __evolved_execute evolved.execute = __evolved_execute