Merge branch 'dev'

This commit is contained in:
BlackMATov
2025-03-18 07:08:27 +07:00
8 changed files with 1274 additions and 794 deletions

View File

@@ -60,18 +60,19 @@ unpack :: id -> integer, integer
defer :: boolean
commit :: boolean
is_alive :: entity -> boolean
is_alive_all :: entity... -> boolean
is_alive_any :: entity... -> boolean
is_alive :: chunk | entity -> boolean
is_alive_all :: chunk | entity... -> boolean
is_alive_any :: chunk | entity... -> boolean
is_empty :: entity -> boolean
is_empty_all :: entity... -> boolean
is_empty_any :: entity... -> boolean
is_empty :: chunk | entity -> boolean
is_empty_all :: chunk | entity... -> boolean
is_empty_any :: chunk | entity... -> boolean
has :: chunk | entity, fragment -> boolean
has_all :: chunk | entity, fragment... -> boolean
has_any :: chunk | entity, fragment... -> boolean
get :: entity, fragment... -> component...
has :: entity, fragment -> boolean
has_all :: entity, fragment... -> boolean
has_any :: entity, fragment... -> boolean
set :: entity, fragment, any... -> boolean, boolean
assign :: entity, fragment, any... -> boolean, boolean
@@ -85,23 +86,23 @@ multi_assign :: entity, fragment[], component[]? -> boolean, boolean
multi_insert :: entity, fragment[], component[]? -> boolean, boolean
multi_remove :: entity, fragment[] -> boolean, boolean
batch_set :: query, fragment, any... -> integer, boolean
batch_assign :: query, fragment, any... -> integer, boolean
batch_insert :: query, fragment, any... -> integer, boolean
batch_remove :: query, fragment... -> integer, boolean
batch_clear :: query... -> integer, boolean
batch_destroy :: query... -> integer, boolean
batch_set :: chunk | query, fragment, any... -> integer, boolean
batch_assign :: chunk | query, fragment, any... -> integer, boolean
batch_insert :: chunk | query, fragment, any... -> integer, boolean
batch_remove :: chunk | query, fragment... -> integer, boolean
batch_clear :: chunk | query... -> integer, boolean
batch_destroy :: chunk | query... -> integer, boolean
batch_multi_set :: query, fragment[], component[]? -> integer, boolean
batch_multi_assign :: query, fragment[], component[]? -> integer, boolean
batch_multi_insert :: query, fragment[], component[]? -> integer, boolean
batch_multi_remove :: query, fragment[] -> integer, boolean
batch_multi_set :: chunk | query, fragment[], component[]? -> integer, boolean
batch_multi_assign :: chunk | query, fragment[], component[]? -> integer, boolean
batch_multi_insert :: chunk | query, fragment[], component[]? -> integer, boolean
batch_multi_remove :: chunk | query, fragment[] -> integer, boolean
chunk :: fragment... -> chunk?, entity[]?, integer?
select :: chunk, fragment... -> component[]...
chunk :: fragment, fragment... -> chunk, entity[], integer
entities :: chunk -> entity[], integer
fragments :: chunk -> fragment[], integer
components :: chunk, fragment... -> component[]...
each :: entity -> {each_state? -> fragment?, component?}, each_state?
execute :: query -> {execute_state? -> chunk?, entity[]?, integer?}, execute_state?

View File

@@ -2,9 +2,12 @@
## Backlog
- should set/assign/insert return a constructed component?
## After first release
- add system groups
- observers and events
- add INDEX fragment trait
- add REQUIRES fragment trait
- use compact prefix-tree for chunks

View File

@@ -1,4 +1,4 @@
require 'develop.example'
require 'develop.unbench'
-- require 'develop.unbench'
require 'develop.untests'
require 'develop.usbench'
-- require 'develop.usbench'

View File

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

View File

@@ -619,7 +619,7 @@ basics.describe_bench(string.format('create and destroy %d entities / spawn_at',
local fragments = {}
local components = {}
local chunk = evo.chunk()
local chunk = nil
for i = 1, N do
entities[i] = spawn_at(chunk, fragments, components)

View File

@@ -647,15 +647,10 @@ do
assert(evo.insert(e2b, f1, 44))
assert(evo.insert(e2b, f2, 45))
do
local chunk, entities = evo.chunk()
assert(not chunk and not entities)
end
do
local chunk, entities = evo.chunk(f1)
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
do
@@ -667,8 +662,8 @@ do
assert(chunk == evo.chunk(f2, f1))
assert(chunk == evo.chunk(f2, f1, f2, f1))
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.select(chunk, f1)[2] == 44 and evo.select(chunk, f2)[2] == 45)
assert(chunk and evo.components(chunk, f1)[1] == 42 and evo.components(chunk, f2)[1] == 43)
assert(chunk and evo.components(chunk, f1)[2] == 44 and evo.components(chunk, f2)[2] == 45)
end
do
@@ -1969,9 +1964,9 @@ do
assert(chunk_entities[1] == e3 and chunk_entities[2] == e1)
assert(#evo.select(chunk, f1) == 0)
assert(#evo.select(chunk, f2) == 0)
assert(evo.select(chunk, f3)[1] == 43 and evo.select(chunk, f3)[2] == 50)
assert(#evo.components(chunk, f1) == 0)
assert(#evo.components(chunk, f2) == 0)
assert(evo.components(chunk, f3)[1] == 43 and evo.components(chunk, f3)[2] == 50)
end
end
end
@@ -2010,9 +2005,9 @@ do
assert(chunk and chunk_entities)
assert(chunk_entities[1] == e1)
assert(#evo.select(chunk, f1) == 0)
assert(#evo.select(chunk, f2) == 0)
assert(#evo.select(chunk, f3) == 0)
assert(#evo.components(chunk, f1) == 0)
assert(#evo.components(chunk, f2) == 0)
assert(#evo.components(chunk, f3) == 0)
end
do
@@ -2020,9 +2015,9 @@ do
assert(chunk and chunk_entities)
assert(chunk_entities[1] == e3)
assert(#evo.select(chunk, f1) == 0)
assert(#evo.select(chunk, f2) == 0)
assert(evo.select(chunk, f3)[1] == 43)
assert(#evo.components(chunk, f1) == 0)
assert(#evo.components(chunk, f2) == 0)
assert(evo.components(chunk, f3)[1] == 43)
end
end
end
@@ -2065,9 +2060,9 @@ do
assert(chunk and chunk_entities)
assert(next(chunk_entities) == nil)
assert(#evo.select(chunk, f1) == 0)
assert(#evo.select(chunk, f2) == 0)
assert(#evo.select(chunk, f3) == 0)
assert(#evo.components(chunk, f1) == 0)
assert(#evo.components(chunk, f2) == 0)
assert(#evo.components(chunk, f3) == 0)
end
end
end
@@ -2110,9 +2105,9 @@ do
assert(chunk and chunk_entities)
assert(next(chunk_entities) == nil)
assert(#evo.select(chunk, f1) == 0)
assert(#evo.select(chunk, f2) == 0)
assert(#evo.select(chunk, f3) == 0)
assert(#evo.components(chunk, f1) == 0)
assert(#evo.components(chunk, f2) == 0)
assert(#evo.components(chunk, f3) == 0)
end
end
end
@@ -2729,7 +2724,7 @@ do
do
local chunk, entities = evo.chunk(f1, f2)
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
@@ -2978,13 +2973,13 @@ do
do
local chunk, entities = evo.chunk(f1, f2, f3)
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
do
local chunk, entities = evo.chunk(f3)
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
@@ -3890,7 +3885,7 @@ do
assert(evo.get(e4, f4) == nil)
for chunk in evo.execute(q) do
assert(next(evo.select(chunk, f4)) == nil)
assert(next(evo.components(chunk, f4)) == nil)
end
do
@@ -3898,14 +3893,14 @@ do
assert(chunk and entities)
assert(#entities == 2)
assert(entities[1] == e3, entities[2] == e4)
assert(evo.select(chunk, f2)[1] == 32 and evo.select(chunk, f3)[1] == 33)
assert(evo.select(chunk, f2)[2] == 42 and evo.select(chunk, f3)[2] == 43)
assert(evo.components(chunk, f2)[1] == 32 and evo.components(chunk, f3)[1] == 33)
assert(evo.components(chunk, f2)[2] == 42 and evo.components(chunk, f3)[2] == 43)
end
do
local chunk, entities = evo.chunk(f1, f2, f3, f4)
assert(chunk)
assert(next(evo.select(chunk, f4)) == nil)
assert(next(evo.components(chunk, f4)) == nil)
assert(#entities == 0)
end
end
@@ -3920,7 +3915,7 @@ do
assert(evo.has_all(e4, f2, f3) and not evo.has_any(e4, f1, f4))
for chunk in evo.execute(q) do
assert(next(evo.select(chunk, f1)) == nil)
assert(next(evo.components(chunk, f1)) == nil)
end
assert(evo.batch_multi_remove(q, { f2, f3 }) == 3)
@@ -3930,24 +3925,24 @@ do
assert(not evo.has_any(e4, f1, f2, f3, f4))
for chunk in evo.execute(q) do
assert(next(evo.select(chunk, f2)) == nil)
assert(next(evo.select(chunk, f3)) == nil)
assert(next(evo.components(chunk, f2)) == nil)
assert(next(evo.components(chunk, f3)) == nil)
end
do
local chunk, entities = evo.chunk(f1, f2)
assert(chunk)
assert(next(evo.select(chunk, f1)) == nil)
assert(next(evo.select(chunk, f2)) == nil)
assert(next(evo.components(chunk, f1)) == nil)
assert(next(evo.components(chunk, f2)) == nil)
assert(#entities == 0)
end
do
local chunk, entities = evo.chunk(f1, f2, f3)
assert(chunk)
assert(next(evo.select(chunk, f1)) == nil)
assert(next(evo.select(chunk, f2)) == nil)
assert(next(evo.select(chunk, f3)) == nil)
assert(next(evo.components(chunk, f1)) == nil)
assert(next(evo.components(chunk, f2)) == nil)
assert(next(evo.components(chunk, f3)) == nil)
assert(#entities == 0)
end
end
@@ -4248,16 +4243,16 @@ do
do
local c123, c123_es = evo.chunk(f1, f2, f3)
assert(c123 and #c123_es == 0)
assert(#evo.select(c123, f1) == 0)
assert(#evo.select(c123, f2) == 0)
assert(#evo.select(c123, f3) == 0)
assert(#evo.components(c123, f1) == 0)
assert(#evo.components(c123, f2) == 0)
assert(#evo.components(c123, f3) == 0)
local c1234, c1234_es = evo.chunk(f1, f2, f3, f4)
assert(c1234 and #c1234_es == 2)
assert(#evo.select(c1234, f1) == 2)
assert(#evo.select(c1234, f2) == 2)
assert(#evo.select(c1234, f3) == 2)
assert(#evo.select(c1234, f4) == 2)
assert(#evo.components(c1234, f1) == 2)
assert(#evo.components(c1234, f2) == 2)
assert(#evo.components(c1234, f3) == 2)
assert(#evo.components(c1234, f4) == 2)
end
end
@@ -4273,31 +4268,31 @@ do
do
local c1, c1_es = evo.chunk(f1)
assert(c1 and #c1_es == 0)
assert(#evo.select(c1, f1) == 0)
assert(#evo.components(c1, f1) == 0)
end
do
local c12, c12_es = evo.chunk(f1, f2)
assert(c12 and #c12_es == 0)
assert(#evo.select(c12, f1) == 0)
assert(#evo.select(c12, f2) == 0)
assert(#evo.components(c12, f1) == 0)
assert(#evo.components(c12, f2) == 0)
end
do
local c134, c134_es = evo.chunk(f1, f3, f4)
assert(c134 and #c134_es == 1)
assert(#evo.select(c134, f1) == 1)
assert(#evo.select(c134, f3) == 1)
assert(#evo.select(c134, f4) == 1)
assert(#evo.components(c134, f1) == 1)
assert(#evo.components(c134, f3) == 1)
assert(#evo.components(c134, f4) == 1)
end
do
local c1234, c1234_es = evo.chunk(f1, f2, f3, f4)
assert(c1234 and #c1234_es == 3)
assert(#evo.select(c1234, f1) == 3)
assert(#evo.select(c1234, f2) == 3)
assert(#evo.select(c1234, f3) == 3)
assert(#evo.select(c1234, f4) == 3)
assert(#evo.components(c1234, f1) == 3)
assert(#evo.components(c1234, f2) == 3)
assert(#evo.components(c1234, f3) == 3)
assert(#evo.components(c1234, f4) == 3)
end
end
end
@@ -4675,14 +4670,14 @@ do
do
local c12, c12_es = evo.chunk(f1, f2)
assert(c12 and #c12_es == 0)
assert(#evo.select(c12, f1) == 0)
assert(#evo.select(c12, f2) == 0)
assert(#evo.components(c12, f1) == 0)
assert(#evo.components(c12, f2) == 0)
local c123, c123_es = evo.chunk(f1, f2, f3)
assert(c123 and #c123_es == 4)
assert(#evo.select(c123, f1) == 4)
assert(#evo.select(c123, f2) == 4)
assert(#evo.select(c123, f3) == 4)
assert(#evo.components(c123, f1) == 4)
assert(#evo.components(c123, f2) == 4)
assert(#evo.components(c123, f3) == 4)
end
end
@@ -4704,12 +4699,12 @@ do
do
local c1, c1_es = evo.chunk(f1)
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)
assert(c12 and #c12_es == 2)
assert(#evo.select(c12, f1) == 2)
assert(#evo.select(c12, f2) == 2)
assert(#evo.components(c12, f1) == 2)
assert(#evo.components(c12, f2) == 2)
end
end
end
@@ -5247,20 +5242,20 @@ do
assert(c and es and #es == 1 and es[1] == e)
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(c2 and #c2 == 1 and c2[1] == 2)
end
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(c2 and #c2 == 1 and c2[1] == 2)
assert(c3 and #c3 == 1 and c3[1] == 3)
end
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(c2 and #c2 == 1 and c2[1] == 2)
assert(c3 and #c3 == 1 and c3[1] == 3)
@@ -5268,7 +5263,7 @@ do
end
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(c2 and #c2 == 1 and c2[1] == 2)
assert(c3 and #c3 == 1 and c3[1] == 3)
@@ -6460,7 +6455,7 @@ do
local c1, c1_es = evo.chunk(f1)
assert(c1 and c1_es and #c1_es == 2)
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
assert(evo.batch_insert(q1, f2, 2) == 2)
@@ -6472,8 +6467,8 @@ do
local c12, c12_es = evo.chunk(f1, f2)
assert(c12 and c12_es and #c12_es == 2)
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.select(c12, f2)[1] == 2 and evo.select(c12, f2)[2] == 2)
assert(evo.components(c12, f1)[1] == 1 and evo.components(c12, f1)[2] == 11)
assert(evo.components(c12, f2)[1] == 2 and evo.components(c12, f2)[2] == 2)
end
local e1c = evo.entity():set(f1, 111):build()
@@ -6483,7 +6478,7 @@ do
local c1, c1_es = evo.chunk(f1)
assert(c1 and c1_es and #c1_es == 2)
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
assert(evo.batch_insert(q1, f2, 22) == 2)
@@ -6496,10 +6491,10 @@ do
assert(c12 and c12_es and #c12_es == 4)
assert(c12_es[1] == e1a and c12_es[2] == e1b)
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.select(c12, f1)[3] == 111 and evo.select(c12, f1)[4] == 1111)
assert(evo.select(c12, f2)[1] == 2 and evo.select(c12, f2)[2] == 2)
assert(evo.select(c12, f2)[3] == 22 and evo.select(c12, f2)[4] == 22)
assert(evo.components(c12, f1)[1] == 1 and evo.components(c12, f1)[2] == 11)
assert(evo.components(c12, f1)[3] == 111 and evo.components(c12, f1)[4] == 1111)
assert(evo.components(c12, f2)[1] == 2 and evo.components(c12, f2)[2] == 2)
assert(evo.components(c12, f2)[3] == 22 and evo.components(c12, f2)[4] == 22)
end
end
@@ -6515,9 +6510,9 @@ do
local c123, c123_es = evo.chunk(f1, f2, f3)
assert(c123 and c123_es and #c123_es == 2)
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.select(c123, f2)[1] == 2 and evo.select(c123, f2)[2] == 22)
assert(evo.select(c123, f3)[1] == 3 and evo.select(c123, f3)[2] == 33)
assert(evo.components(c123, f1)[1] == 1 and evo.components(c123, f1)[2] == 11)
assert(evo.components(c123, f2)[1] == 2 and evo.components(c123, f2)[2] == 22)
assert(evo.components(c123, f3)[1] == 3 and evo.components(c123, f3)[2] == 33)
end
assert(evo.batch_remove(q1, f2) == 2)
@@ -6526,9 +6521,9 @@ do
local c13, c13_es = evo.chunk(f3, f1)
assert(c13 and c13_es and #c13_es == 2)
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.select(c13, f2)[1] == nil and evo.select(c13, f2)[2] == nil)
assert(evo.select(c13, f3)[1] == 3 and evo.select(c13, f3)[2] == 33)
assert(evo.components(c13, f1)[1] == 1 and evo.components(c13, f1)[2] == 11)
assert(evo.components(c13, f2)[1] == nil and evo.components(c13, f2)[2] == nil)
assert(evo.components(c13, f3)[1] == 3 and evo.components(c13, f3)[2] == 33)
end
local e3a = evo.entity():set(f3, 3):build()
@@ -6538,7 +6533,7 @@ do
local c3, c3_es = evo.chunk(f3)
assert(c3 and c3_es and #c3_es == 2)
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
assert(evo.batch_remove(q1, f1) == 2)
@@ -6548,12 +6543,12 @@ do
assert(c3 and c3_es and #c3_es == 4)
assert(c3_es[1] == e3a and c3_es[2] == e3b)
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.select(c3, f1)[3] == nil and evo.select(c3, f1)[4] == nil)
assert(evo.select(c3, f2)[1] == nil and evo.select(c3, f2)[2] == nil)
assert(evo.select(c3, f2)[3] == nil and evo.select(c3, f2)[4] == nil)
assert(evo.select(c3, f3)[1] == 3 and evo.select(c3, f3)[2] == 33)
assert(evo.select(c3, f3)[3] == 3 and evo.select(c3, f3)[4] == 33)
assert(evo.components(c3, f1)[1] == nil and evo.components(c3, f1)[2] == nil)
assert(evo.components(c3, f1)[3] == nil and evo.components(c3, f1)[4] == nil)
assert(evo.components(c3, f2)[1] == nil and evo.components(c3, f2)[2] == nil)
assert(evo.components(c3, f2)[3] == nil and evo.components(c3, f2)[4] == nil)
assert(evo.components(c3, f3)[1] == 3 and evo.components(c3, f3)[2] == 33)
assert(evo.components(c3, f3)[3] == 3 and evo.components(c3, f3)[4] == 33)
end
end
@@ -7316,6 +7311,7 @@ do
local e12 = evo.entity():set(f1, 2):set(f2, 3):build()
do
assert(evo.is_alive(old_c1))
assert(old_c1 == evo.chunk(f1))
local old_c1_es, old_c1_ec = evo.entities(old_c1)
@@ -7326,6 +7322,8 @@ do
do
local new_c12 = assert(evo.chunk(f1, f2))
assert(not evo.is_alive(old_c12))
assert(old_c12 ~= new_c12)
local new_c12_es, new_c12_ec = evo.entities(new_c12)
@@ -7341,24 +7339,31 @@ do
do
local new_c1 = assert(evo.chunk(f1))
assert(not evo.is_alive(old_c1))
assert(old_c1 ~= new_c1)
local new_c12 = assert(evo.chunk(f1, f2))
assert(not evo.is_alive(old_c12))
assert(old_c12 ~= new_c12)
end
end
do
local f1 = evo.id()
local old_c1 = evo.chunk(f1)
local old_c1 = assert(evo.chunk(f1))
assert(evo.defer())
assert(not evo.collect_garbage())
assert(evo.is_alive(old_c1))
assert(old_c1 == evo.chunk(f1))
assert(evo.commit())
assert(not evo.is_alive(old_c1))
assert(old_c1 ~= evo.chunk(f1))
end
@@ -7805,3 +7810,395 @@ do
assert(not evo.has_any(e5, f7, f7))
assert(not evo.has_any(e5, f7, f7, f6))
end
do
local f1 = evo.id()
local c1 = assert(evo.chunk(f1))
assert(evo.is_alive(c1) and evo.is_empty(c1))
local e1 = evo.spawn_at(c1)
assert(evo.is_alive(c1) and not evo.is_empty(c1))
assert(evo.destroy(e1))
assert(evo.is_alive(c1) and evo.is_empty(c1))
assert(evo.collect_garbage())
assert(not evo.is_alive(c1) and evo.is_empty(c1))
end
do
local f1, f2 = evo.id(2)
local c1 = assert(evo.chunk(f1))
local c12 = assert(evo.chunk(f1, f2))
assert(evo.is_alive(c1))
assert(evo.is_alive(c12))
assert(evo.is_alive_all())
assert(evo.is_alive_all(c1))
assert(evo.is_alive_all(c1, c12))
assert(not evo.is_alive_any())
assert(evo.is_alive_any(c1))
assert(evo.is_alive_any(c1, c12))
assert(evo.is_empty(c1))
assert(evo.is_empty(c12))
assert(evo.is_empty_all())
assert(evo.is_empty_all(c1))
assert(evo.is_empty_all(c1, c12))
assert(not evo.is_empty_any())
assert(evo.is_empty_any(c1))
assert(evo.is_empty_any(c1, c12))
local e12 = evo.spawn_at(c12)
assert(evo.is_alive(c1))
assert(evo.is_alive(c12))
assert(evo.is_alive_all())
assert(evo.is_alive_all(c1))
assert(evo.is_alive_all(c1, c12))
assert(not evo.is_alive_any())
assert(evo.is_alive_any(c1))
assert(evo.is_alive_any(c1, c12))
assert(evo.is_empty(c1))
assert(not evo.is_empty(c12))
assert(evo.is_empty_all())
assert(evo.is_empty_all(c1))
assert(not evo.is_empty_all(c1, c12))
assert(not evo.is_empty_any())
assert(evo.is_empty_any(c1))
assert(evo.is_empty_any(c1, c12))
assert(evo.remove(e12, f2))
assert(evo.is_alive(c1))
assert(evo.is_alive(c12))
assert(evo.is_alive_all())
assert(evo.is_alive_all(c1))
assert(evo.is_alive_all(c1, c12))
assert(not evo.is_alive_any())
assert(evo.is_alive_any(c1))
assert(evo.is_alive_any(c1, c12))
assert(not evo.is_empty(c1))
assert(evo.is_empty(c12))
assert(evo.is_empty_all())
assert(not evo.is_empty_all(c1))
assert(not evo.is_empty_all(c1, c12))
assert(not evo.is_empty_any())
assert(not evo.is_empty_any(c1))
assert(evo.is_empty_any(c1, c12))
assert(evo.collect_garbage())
assert(evo.is_alive(c1))
assert(not evo.is_alive(c12))
assert(evo.is_alive_all())
assert(evo.is_alive_all(c1))
assert(not evo.is_alive_all(c1, c12))
assert(not evo.is_alive_any())
assert(evo.is_alive_any(c1))
assert(evo.is_alive_any(c1, c12))
assert(not evo.is_empty(c1))
assert(evo.is_empty(c12))
assert(evo.is_empty_all())
assert(not evo.is_empty_all(c1))
assert(not evo.is_empty_all(c1, c12))
assert(not evo.is_empty_any())
assert(not evo.is_empty_any(c1))
assert(evo.is_empty_any(c1, c12))
assert(evo.remove(e12, f1))
assert(evo.is_alive(c1))
assert(not evo.is_alive(c12))
assert(evo.is_alive_all())
assert(evo.is_alive_all(c1))
assert(not evo.is_alive_all(c1, c12))
assert(not evo.is_alive_any())
assert(evo.is_alive_any(c1))
assert(evo.is_alive_any(c1, c12))
assert(evo.is_empty(c1))
assert(evo.is_empty(c12))
assert(evo.is_empty_all())
assert(evo.is_empty_all(c1))
assert(evo.is_empty_all(c1, c12))
assert(not evo.is_empty_any())
assert(evo.is_empty_any(c1))
assert(evo.is_empty_any(c1, c12))
assert(evo.collect_garbage())
assert(not evo.is_alive(c1))
assert(not evo.is_alive(c12))
assert(evo.is_alive_all())
assert(not evo.is_alive_all(c1))
assert(not evo.is_alive_all(c1, c12))
assert(not evo.is_alive_any())
assert(not evo.is_alive_any(c1))
assert(not evo.is_alive_any(c1, c12))
assert(evo.is_empty(c1))
assert(evo.is_empty(c12))
assert(evo.is_empty_all())
assert(evo.is_empty_all(c1))
assert(evo.is_empty_all(c1, c12))
assert(not evo.is_empty_any())
assert(evo.is_empty_any(c1))
assert(evo.is_empty_any(c1, c12))
end
do
local f1, f2 = evo.id(2)
local c1 = assert(evo.chunk(f1))
local c12 = assert(evo.chunk(f1, f2))
assert(evo.has(c1, f1))
assert(not evo.has(c1, f2))
assert(evo.has(c12, f1))
assert(evo.has(c12, f2))
assert(evo.has_all(c1))
assert(evo.has_all(c1, f1))
assert(not evo.has_all(c1, f1, f2))
assert(evo.has_all(c12))
assert(evo.has_all(c12, f1))
assert(evo.has_all(c12, f1, f2))
assert(not evo.has_any(c1))
assert(evo.has_any(c1, f1))
assert(evo.has_any(c1, f1, f2))
assert(not evo.has_any(c12))
assert(evo.has_any(c12, f1))
assert(evo.has_any(c12, f1, f2))
assert(evo.collect_garbage())
assert(not evo.is_alive_any(c1, c12))
assert(evo.has(c1, f1))
assert(not evo.has(c1, f2))
assert(evo.has(c12, f1))
assert(evo.has(c12, f2))
assert(evo.has_all(c1))
assert(evo.has_all(c1, f1))
assert(not evo.has_all(c1, f1, f2))
assert(evo.has_all(c12))
assert(evo.has_all(c12, f1))
assert(evo.has_all(c12, f1, f2))
assert(not evo.has_any(c1))
assert(evo.has_any(c1, f1))
assert(evo.has_any(c1, f1, f2))
assert(not evo.has_any(c12))
assert(evo.has_any(c12, f1))
assert(evo.has_any(c12, f1, f2))
end
do
local f1, f2 = evo.id(2)
local c1 = assert(evo.chunk(f1))
local c12 = assert(evo.chunk(f1, f2))
local e1a = evo.entity():set(f1, 1):build()
local e1b = evo.entity():set(f1, 2):build()
local e12a = evo.entity():set(f1, 3):set(f2, 4):build()
local e12b = evo.entity():set(f1, 5):set(f2, 6):build()
do
local c12_es, c12_ec = evo.entities(c12)
assert(c12_es and #c12_es == 2 and c12_ec == 2)
assert(c12_es[1] == e12a and c12_es[2] == e12b)
assert(evo.get(e12a, f2) == 4 and evo.get(e12b, f2) == 6)
end
assert(2 == evo.batch_set(c1, f2, 0))
do
local c12_es, c12_ec = evo.entities(c12)
assert(c12_es and #c12_es == 4 and c12_ec == 4)
assert(c12_es[1] == e12a and c12_es[2] == e12b and c12_es[3] == e1a and c12_es[4] == e1b)
assert(evo.get(e1a, f2) == 0 and evo.get(e1b, f2) == 0)
assert(evo.get(e12a, f2) == 4 and evo.get(e12b, f2) == 6)
end
assert(4 == evo.batch_set(c12, f2, 7))
do
local c12_es, c12_ec = evo.entities(c12)
assert(c12_es and #c12_es == 4 and c12_ec == 4)
assert(c12_es[1] == e12a and c12_es[2] == e12b and c12_es[3] == e1a and c12_es[4] == e1b)
assert(evo.get(e1a, f2) == 7 and evo.get(e1b, f2) == 7)
assert(evo.get(e12a, f2) == 7 and evo.get(e12b, f2) == 7)
end
assert(4 == evo.batch_assign(c12, f2, 8))
do
local c12_es, c12_ec = evo.entities(c12)
assert(c12_es and #c12_es == 4 and c12_ec == 4)
assert(c12_es[1] == e12a and c12_es[2] == e12b and c12_es[3] == e1a and c12_es[4] == e1b)
assert(evo.get(e1a, f2) == 8 and evo.get(e1b, f2) == 8)
assert(evo.get(e12a, f2) == 8 and evo.get(e12b, f2) == 8)
end
assert(4 == evo.batch_remove(c12, f2))
do
local c1_es, c1_ec = evo.entities(c1)
assert(c1_es and #c1_es == 4 and c1_ec == 4)
assert(c1_es[1] == e12a and c1_es[2] == e12b and c1_es[3] == e1a and c1_es[4] == e1b)
assert(evo.get(e1a, f1) == 1 and evo.get(e1b, f1) == 2)
assert(evo.get(e12a, f1) == 3 and evo.get(e12b, f1) == 5)
end
assert(4 == evo.batch_insert(c1, f2, 9))
do
local c12_es, c12_ec = evo.entities(c12)
assert(c12_es and #c12_es == 4 and c12_ec == 4)
assert(c12_es[1] == e12a and c12_es[2] == e12b and c12_es[3] == e1a and c12_es[4] == e1b)
assert(evo.get(e1a, f2) == 9 and evo.get(e1b, f2) == 9)
assert(evo.get(e12a, f2) == 9 and evo.get(e12b, f2) == 9)
end
assert(4 == evo.batch_clear(c12))
do
assert(evo.is_alive_all(e1a, e1b, e12a, e12b))
assert(evo.is_empty_all(e1a, e1b, e12a, e12b))
end
assert(evo.insert(e1a, f1, 1) and evo.insert(e1b, f1, 2))
assert(evo.multi_insert(e12a, { f1, f2 }, { 3, 4 }) and evo.multi_insert(e12b, { f1, f2 }, { 5, 6 }))
do
assert(evo.is_alive_all(e1a, e1b, e12a, e12b))
assert(not evo.is_empty_any(e1a, e1b, e12a, e12b))
end
assert(2 == evo.batch_destroy(c12))
do
assert(evo.is_alive_all(e1a, e1b))
assert(not evo.is_alive_any(e12a, e12b))
assert(not evo.is_empty_any(e1a, e1b))
assert(evo.is_empty_all(e12a, e12b))
end
end
do
local f1, f2 = evo.id(2)
local c1 = assert(evo.chunk(f1))
local c12 = assert(evo.chunk(f1, f2))
local e1a = evo.entity():set(f1, 1):build()
local e1b = evo.entity():set(f1, 2):build()
local e12a = evo.entity():set(f1, 3):set(f2, 4):build()
local e12b = evo.entity():set(f1, 5):set(f2, 6):build()
do
local c12_es, c12_ec = evo.entities(c12)
assert(c12_es and #c12_es == 2 and c12_ec == 2)
assert(c12_es[1] == e12a and c12_es[2] == e12b)
assert(evo.get(e12a, f2) == 4 and evo.get(e12b, f2) == 6)
end
assert(2 == evo.batch_multi_set(c1, { f2, f1 }, { 7, 0 }))
do
local c12_es, c12_ec = evo.entities(c12)
assert(c12_es and #c12_es == 4 and c12_ec == 4)
assert(c12_es[1] == e12a and c12_es[2] == e12b and c12_es[3] == e1a and c12_es[4] == e1b)
assert(evo.get(e1a, f1) == 0 and evo.get(e1b, f1) == 0)
assert(evo.get(e1a, f2) == 7 and evo.get(e1b, f2) == 7)
assert(evo.get(e12a, f1) == 3 and evo.get(e12b, f1) == 5)
assert(evo.get(e12a, f2) == 4 and evo.get(e12b, f2) == 6)
end
assert(4 == evo.batch_multi_assign(c12, { f1 }, { 7 }))
do
local c12_es, c12_ec = evo.entities(c12)
assert(c12_es and #c12_es == 4 and c12_ec == 4)
assert(c12_es[1] == e12a and c12_es[2] == e12b and c12_es[3] == e1a and c12_es[4] == e1b)
assert(evo.get(e1a, f1) == 7 and evo.get(e1b, f1) == 7)
assert(evo.get(e1a, f2) == 7 and evo.get(e1b, f2) == 7)
assert(evo.get(e12a, f1) == 7 and evo.get(e12b, f1) == 7)
assert(evo.get(e12a, f2) == 4 and evo.get(e12b, f2) == 6)
end
assert(4 == evo.batch_multi_remove(c12, { f2 }))
do
local c1_es, c1_ec = evo.entities(c1)
assert(c1_es and #c1_es == 4 and c1_ec == 4)
assert(c1_es[1] == e12a and c1_es[2] == e12b and c1_es[3] == e1a and c1_es[4] == e1b)
assert(evo.get(e1a, f1) == 7 and evo.get(e1b, f1) == 7)
assert(evo.get(e12a, f1) == 7 and evo.get(e12b, f1) == 7)
end
assert(4 == evo.batch_multi_insert(c1, { f2 }, { 8 }))
do
local c12_es, c12_ec = evo.entities(c12)
assert(c12_es and #c12_es == 4 and c12_ec == 4)
assert(c12_es[1] == e12a and c12_es[2] == e12b and c12_es[3] == e1a and c12_es[4] == e1b)
assert(evo.get(e1a, f1) == 7 and evo.get(e1b, f1) == 7)
assert(evo.get(e1a, f2) == 8 and evo.get(e1b, f2) == 8)
assert(evo.get(e12a, f1) == 7 and evo.get(e12b, f1) == 7)
assert(evo.get(e12a, f2) == 8 and evo.get(e12b, f2) == 8)
end
assert(4 == evo.batch_destroy(c12))
do
assert(not evo.is_alive_any(e1a, e1b, e12a, e12b))
assert(evo.is_empty_all(e1a, e1b, e12a, e12b))
end
end
do
local f1, f2 = evo.id(2)
local c1 = assert(evo.chunk(f1))
local c12 = assert(evo.chunk(f1, f2))
local e1a = evo.entity():set(f1, 1):build()
local e1b = evo.entity():set(f1, 2):build()
local e12a = evo.entity():set(f1, 3):set(f2, 4):build()
local e12b = evo.entity():set(f1, 5):set(f2, 6):build()
assert(4 == evo.batch_clear(c1, c12))
assert(evo.is_alive_all(e1a, e1b, e12a, e12b))
assert(evo.is_empty_all(e1a, e1b, e12a, e12b))
end
do
local f1, f2 = evo.id(2)
local c1 = assert(evo.chunk(f1))
local c12 = assert(evo.chunk(f1, f2))
local e1a = evo.entity():set(f1, 1):build()
local e1b = evo.entity():set(f1, 2):build()
local e12a = evo.entity():set(f1, 3):set(f2, 4):build()
local e12b = evo.entity():set(f1, 5):set(f2, 6):build()
assert(4 == evo.batch_destroy(c1, c12))
assert(not evo.is_alive_any(e1a, e1b, e12a, e12b))
assert(evo.is_empty_all(e1a, e1b, e12a, e12b))
end

View File

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

File diff suppressed because it is too large Load Diff