mirror of
https://github.com/BlackMATov/evolved.lua.git
synced 2025-12-14 12:10:23 +07:00
is_alive/empty for multiple entities
This commit is contained in:
@@ -60,8 +60,8 @@ unpack :: id -> integer, integer
|
|||||||
defer :: boolean
|
defer :: boolean
|
||||||
commit :: boolean
|
commit :: boolean
|
||||||
|
|
||||||
is_alive :: entity -> boolean
|
is_alive :: entity... -> boolean
|
||||||
is_empty :: entity -> boolean
|
is_empty :: entity... -> boolean
|
||||||
|
|
||||||
get :: entity, fragment... -> component...
|
get :: entity, fragment... -> component...
|
||||||
has :: entity, fragment -> boolean
|
has :: entity, fragment -> boolean
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'develop.example'
|
require 'develop.example'
|
||||||
-- require 'develop.unbench'
|
require 'develop.unbench'
|
||||||
require 'develop.untests'
|
require 'develop.untests'
|
||||||
-- require 'develop.usbench'
|
require 'develop.usbench'
|
||||||
|
|||||||
@@ -7643,3 +7643,61 @@ do
|
|||||||
assert(not evo.is_alive(e1) and evo.is_empty(e1))
|
assert(not evo.is_alive(e1) and evo.is_empty(e1))
|
||||||
assert(not evo.is_alive(e2) and evo.is_empty(e2))
|
assert(not evo.is_alive(e2) and evo.is_empty(e2))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
local a1, a2, a3, a4, a5 = evo.id(5)
|
||||||
|
|
||||||
|
assert(evo.is_alive())
|
||||||
|
assert(evo.is_alive(a1))
|
||||||
|
assert(evo.is_alive(a1, a2))
|
||||||
|
assert(evo.is_alive(a1, a2, a3))
|
||||||
|
assert(evo.is_alive(a1, a2, a3, a4))
|
||||||
|
assert(evo.is_alive(a1, a2, a3, a4, a5))
|
||||||
|
|
||||||
|
local d1, d2 = evo.id(2)
|
||||||
|
assert(evo.destroy(d1, d2))
|
||||||
|
|
||||||
|
assert(not evo.is_alive(d1))
|
||||||
|
assert(not evo.is_alive(d1, d2))
|
||||||
|
assert(not evo.is_alive(d1, a1))
|
||||||
|
assert(not evo.is_alive(a1, d1))
|
||||||
|
assert(not evo.is_alive(d1, d2, a1))
|
||||||
|
assert(not evo.is_alive(d1, a1, a2))
|
||||||
|
assert(not evo.is_alive(d1, a1, a2, d2, a3))
|
||||||
|
assert(not evo.is_alive(d1, a1, a2, d2, a3, d1))
|
||||||
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
local e1, e2, e3, e4, e5 = evo.id(5)
|
||||||
|
|
||||||
|
assert(evo.is_empty())
|
||||||
|
assert(evo.is_empty(e1))
|
||||||
|
assert(evo.is_empty(e1, e2))
|
||||||
|
assert(evo.is_empty(e1, e2, e3))
|
||||||
|
assert(evo.is_empty(e1, e2, e3, e4))
|
||||||
|
assert(evo.is_empty(e1, e2, e3, e4, e5))
|
||||||
|
|
||||||
|
local d1, d2 = evo.id(2)
|
||||||
|
assert(evo.destroy(d1, d2))
|
||||||
|
|
||||||
|
assert(evo.is_empty(d1))
|
||||||
|
assert(evo.is_empty(d1, d2))
|
||||||
|
assert(evo.is_empty(d1, e1))
|
||||||
|
assert(evo.is_empty(e1, d1))
|
||||||
|
assert(evo.is_empty(d1, d2, e1))
|
||||||
|
assert(evo.is_empty(d1, e1, e2))
|
||||||
|
assert(evo.is_empty(d1, e1, e2, d2, e3))
|
||||||
|
assert(evo.is_empty(d1, e1, e2, d2, e3, d1))
|
||||||
|
|
||||||
|
local f1, f2 = evo.id(2)
|
||||||
|
assert(evo.insert(f1, f1) and evo.insert(f2, f2))
|
||||||
|
|
||||||
|
assert(not evo.is_empty(f1))
|
||||||
|
assert(not evo.is_empty(f1, f2))
|
||||||
|
assert(not evo.is_empty(f1, e1))
|
||||||
|
assert(not evo.is_empty(e1, f1))
|
||||||
|
assert(not evo.is_empty(f1, f2, e1))
|
||||||
|
assert(not evo.is_empty(f1, e1, e2))
|
||||||
|
assert(not evo.is_empty(f1, e1, e2, f2, e3))
|
||||||
|
assert(not evo.is_empty(f1, e1, e2, f2, e3, f1))
|
||||||
|
end
|
||||||
|
|||||||
123
evolved.lua
123
evolved.lua
@@ -4865,26 +4865,121 @@ __evolved_commit = function()
|
|||||||
return __commit()
|
return __commit()
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param entity evolved.entity
|
---@param ... evolved.entity entities
|
||||||
---@return boolean
|
---@return boolean
|
||||||
---@nodiscard
|
---@nodiscard
|
||||||
__evolved_is_alive = function(entity)
|
__evolved_is_alive = function(...)
|
||||||
local entity_index = entity % 0x100000
|
local entity_count = __lua_select('#', ...)
|
||||||
|
|
||||||
return __freelist_ids[entity_index] == entity
|
if entity_count == 0 then
|
||||||
end
|
|
||||||
|
|
||||||
---@param entity evolved.entity
|
|
||||||
---@return boolean
|
|
||||||
---@nodiscard
|
|
||||||
__evolved_is_empty = function(entity)
|
|
||||||
local entity_index = entity % 0x100000
|
|
||||||
|
|
||||||
if __freelist_ids[entity_index] ~= entity then
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
return not __entity_chunks[entity_index]
|
local ids = __freelist_ids
|
||||||
|
|
||||||
|
if entity_count == 1 then
|
||||||
|
local e1 = ...
|
||||||
|
local i1 = e1 % 0x100000
|
||||||
|
return
|
||||||
|
(ids[i1] == e1)
|
||||||
|
end
|
||||||
|
|
||||||
|
if entity_count == 2 then
|
||||||
|
local e1, e2 = ...
|
||||||
|
local i1, i2 = e1 % 0x100000, e2 % 0x100000
|
||||||
|
return
|
||||||
|
(ids[i1] == e1) and
|
||||||
|
(ids[i2] == e2)
|
||||||
|
end
|
||||||
|
|
||||||
|
if entity_count == 3 then
|
||||||
|
local e1, e2, e3 = ...
|
||||||
|
local i1, i2, i3 = e1 % 0x100000, e2 % 0x100000, e3 % 0x100000
|
||||||
|
return
|
||||||
|
(ids[i1] == e1) and
|
||||||
|
(ids[i2] == e2) and
|
||||||
|
(ids[i3] == e3)
|
||||||
|
end
|
||||||
|
|
||||||
|
if entity_count == 4 then
|
||||||
|
local e1, e2, e3, e4 = ...
|
||||||
|
local i1, i2, i3, i4 = e1 % 0x100000, e2 % 0x100000, e3 % 0x100000, e4 % 0x100000
|
||||||
|
return
|
||||||
|
(ids[i1] == e1) and
|
||||||
|
(ids[i2] == e2) and
|
||||||
|
(ids[i3] == e3) and
|
||||||
|
(ids[i4] == e4)
|
||||||
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
local e1, e2, e3, e4 = ...
|
||||||
|
local i1, i2, i3, i4 = e1 % 0x100000, e2 % 0x100000, e3 % 0x100000, e4 % 0x100000
|
||||||
|
return
|
||||||
|
(ids[i1] == e1) and
|
||||||
|
(ids[i2] == e2) and
|
||||||
|
(ids[i3] == e3) and
|
||||||
|
(ids[i4] == e4) and
|
||||||
|
__evolved_is_alive(__lua_select(5, ...))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param ... evolved.entity entities
|
||||||
|
---@return boolean
|
||||||
|
---@nodiscard
|
||||||
|
__evolved_is_empty = function(...)
|
||||||
|
local entity_count = __lua_select('#', ...)
|
||||||
|
|
||||||
|
if entity_count == 0 then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
local ids = __freelist_ids
|
||||||
|
local ecs = __entity_chunks
|
||||||
|
|
||||||
|
if entity_count == 1 then
|
||||||
|
local e1 = ...
|
||||||
|
local i1 = e1 % 0x100000
|
||||||
|
return
|
||||||
|
(ids[i1] ~= e1 or not ecs[i1])
|
||||||
|
end
|
||||||
|
|
||||||
|
if entity_count == 2 then
|
||||||
|
local e1, e2 = ...
|
||||||
|
local i1, i2 = e1 % 0x100000, e2 % 0x100000
|
||||||
|
return
|
||||||
|
(ids[i1] ~= e1 or not ecs[i1]) and
|
||||||
|
(ids[i2] ~= e2 or not ecs[i2])
|
||||||
|
end
|
||||||
|
|
||||||
|
if entity_count == 3 then
|
||||||
|
local e1, e2, e3 = ...
|
||||||
|
local i1, i2, i3 = e1 % 0x100000, e2 % 0x100000, e3 % 0x100000
|
||||||
|
return
|
||||||
|
(ids[i1] ~= e1 or not ecs[i1]) and
|
||||||
|
(ids[i2] ~= e2 or not ecs[i2]) and
|
||||||
|
(ids[i3] ~= e3 or not ecs[i3])
|
||||||
|
end
|
||||||
|
|
||||||
|
if entity_count == 4 then
|
||||||
|
local e1, e2, e3, e4 = ...
|
||||||
|
local i1, i2, i3, i4 = e1 % 0x100000, e2 % 0x100000, e3 % 0x100000, e4 % 0x100000
|
||||||
|
return
|
||||||
|
(ids[i1] ~= e1 or not ecs[i1]) and
|
||||||
|
(ids[i2] ~= e2 or not ecs[i2]) and
|
||||||
|
(ids[i3] ~= e3 or not ecs[i3]) and
|
||||||
|
(ids[i4] ~= e4 or not ecs[i4])
|
||||||
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
local e1, e2, e3, e4 = ...
|
||||||
|
local i1, i2, i3, i4 = e1 % 0x100000, e2 % 0x100000, e3 % 0x100000, e4 % 0x100000
|
||||||
|
return
|
||||||
|
(ids[i1] ~= e1 or not ecs[i1]) and
|
||||||
|
(ids[i2] ~= e2 or not ecs[i2]) and
|
||||||
|
(ids[i3] ~= e3 or not ecs[i3]) and
|
||||||
|
(ids[i4] ~= e4 or not ecs[i4]) and
|
||||||
|
__evolved_is_empty(__lua_select(5, ...))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param entity evolved.entity
|
---@param entity evolved.entity
|
||||||
|
|||||||
Reference in New Issue
Block a user