mirror of
https://github.com/BlackMATov/evolved.lua.git
synced 2025-12-15 12:19:47 +07:00
new evolved.entities function
This commit is contained in:
@@ -94,6 +94,7 @@ batch_multi_remove :: query, fragment[] -> integer, boolean
|
|||||||
|
|
||||||
chunk :: fragment... -> chunk?, entity[]?, integer?
|
chunk :: fragment... -> chunk?, entity[]?, integer?
|
||||||
select :: chunk, fragment... -> component[]...
|
select :: chunk, fragment... -> component[]...
|
||||||
|
entities :: chunk -> entity[], integer
|
||||||
|
|
||||||
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?
|
||||||
|
|||||||
@@ -6651,3 +6651,46 @@ do
|
|||||||
assert(evo.get(s, s) == nil)
|
assert(evo.get(s, s) == nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
local f1, f2 = evo.id(2)
|
||||||
|
|
||||||
|
local c1 = evo.chunk(f1)
|
||||||
|
local c2 = evo.chunk(f2)
|
||||||
|
local c12 = 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 c1_es, c1_ec = evo.entities(c1)
|
||||||
|
assert(c1_es and #c1_es == 2 and c1_ec == 2)
|
||||||
|
assert(c1_es[1] == e1a and c1_es[2] == e1b)
|
||||||
|
|
||||||
|
local c2_es, c2_ec = evo.entities(c2)
|
||||||
|
assert(c2_es and #c2_es == 0 and c2_ec == 0)
|
||||||
|
|
||||||
|
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)
|
||||||
|
end
|
||||||
|
|
||||||
|
assert(evo.remove(e12a, f1) and evo.remove(e12b, f1))
|
||||||
|
assert(evo.insert(e1a, f2, 7) and evo.insert(e1b, f2, 8))
|
||||||
|
|
||||||
|
do
|
||||||
|
local c1_es, c1_ec = evo.entities(c1)
|
||||||
|
assert(c1_es and #c1_es == 0 and c1_ec == 0)
|
||||||
|
|
||||||
|
local c2_es, c2_ec = evo.entities(c2)
|
||||||
|
assert(c2_es and #c2_es == 2 and c2_ec == 2)
|
||||||
|
assert(c2_es[1] == e12a and c2_es[2] == e12b)
|
||||||
|
|
||||||
|
local c12_es, c12_ec = evo.entities(c12)
|
||||||
|
assert(c12_es and #c12_es == 2 and c12_ec == 2)
|
||||||
|
assert(c12_es[1] == e1a and c12_es[2] == e1b)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|||||||
21
evolved.lua
21
evolved.lua
@@ -633,6 +633,7 @@ local __evolved_batch_multi_remove
|
|||||||
|
|
||||||
local __evolved_chunk
|
local __evolved_chunk
|
||||||
local __evolved_select
|
local __evolved_select
|
||||||
|
local __evolved_entities
|
||||||
|
|
||||||
local __evolved_each
|
local __evolved_each
|
||||||
local __evolved_execute
|
local __evolved_execute
|
||||||
@@ -4997,12 +4998,10 @@ __evolved_clear = function(entity)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
do
|
__detach_entity(chunk, place)
|
||||||
__detach_entity(chunk, place)
|
|
||||||
|
|
||||||
entity_chunks[entity_index] = nil
|
entity_chunks[entity_index] = nil
|
||||||
entity_places[entity_index] = nil
|
entity_places[entity_index] = nil
|
||||||
end
|
|
||||||
|
|
||||||
__structural_changes = __structural_changes + 1
|
__structural_changes = __structural_changes + 1
|
||||||
end
|
end
|
||||||
@@ -5066,8 +5065,8 @@ __evolved_destroy = function(entity)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
__detach_entity(chunk, place)
|
|
||||||
__release_id(entity)
|
__release_id(entity)
|
||||||
|
__detach_entity(chunk, place)
|
||||||
|
|
||||||
entity_chunks[entity_index] = nil
|
entity_chunks[entity_index] = nil
|
||||||
entity_places[entity_index] = nil
|
entity_places[entity_index] = nil
|
||||||
@@ -6196,6 +6195,7 @@ end
|
|||||||
---@return evolved.chunk? chunk
|
---@return evolved.chunk? chunk
|
||||||
---@return evolved.entity[]? entities
|
---@return evolved.entity[]? entities
|
||||||
---@return integer? entity_count
|
---@return integer? entity_count
|
||||||
|
---@nodiscard
|
||||||
__evolved_chunk = function(...)
|
__evolved_chunk = function(...)
|
||||||
local fragment_count = __lua_select('#', ...)
|
local fragment_count = __lua_select('#', ...)
|
||||||
|
|
||||||
@@ -6300,6 +6300,14 @@ __evolved_select = function(chunk, ...)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param chunk evolved.chunk
|
||||||
|
---@return evolved.entity[] entities
|
||||||
|
---@return integer entity_count
|
||||||
|
---@nodiscard
|
||||||
|
__evolved_entities = function(chunk)
|
||||||
|
return chunk.__entities, chunk.__entity_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
|
||||||
@@ -7595,6 +7603,7 @@ evolved.batch_multi_remove = __evolved_batch_multi_remove
|
|||||||
|
|
||||||
evolved.chunk = __evolved_chunk
|
evolved.chunk = __evolved_chunk
|
||||||
evolved.select = __evolved_select
|
evolved.select = __evolved_select
|
||||||
|
evolved.entities = __evolved_entities
|
||||||
|
|
||||||
evolved.each = __evolved_each
|
evolved.each = __evolved_each
|
||||||
evolved.execute = __evolved_execute
|
evolved.execute = __evolved_execute
|
||||||
|
|||||||
Reference in New Issue
Block a user