mirror of
https://github.com/BlackMATov/evolved.lua.git
synced 2025-12-13 11:38:15 +07:00
Merge branch 'dev'
This commit is contained in:
@@ -60,8 +60,8 @@ unpack :: id -> integer, integer
|
||||
defer :: boolean
|
||||
commit :: boolean
|
||||
|
||||
is_alive :: entity -> boolean
|
||||
is_empty :: entity -> boolean
|
||||
is_alive :: entity... -> boolean
|
||||
is_empty :: entity... -> boolean
|
||||
|
||||
get :: entity, fragment... -> component...
|
||||
has :: entity, fragment -> boolean
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
require 'develop.example'
|
||||
-- require 'develop.unbench'
|
||||
require 'develop.unbench'
|
||||
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(e2) and evo.is_empty(e2))
|
||||
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
|
||||
|
||||
125
evolved.lua
125
evolved.lua
@@ -269,7 +269,7 @@ local function __release_id(id)
|
||||
__error_fmt('id is not acquired or already released')
|
||||
end
|
||||
|
||||
shifted_version = shifted_version == 0xFFFFF00000
|
||||
shifted_version = shifted_version == 0xFFFFF * 0x100000
|
||||
and 0x100000
|
||||
or shifted_version + 0x100000
|
||||
|
||||
@@ -4865,26 +4865,121 @@ __evolved_commit = function()
|
||||
return __commit()
|
||||
end
|
||||
|
||||
---@param entity evolved.entity
|
||||
---@param ... evolved.entity entities
|
||||
---@return boolean
|
||||
---@nodiscard
|
||||
__evolved_is_alive = function(entity)
|
||||
local entity_index = entity % 0x100000
|
||||
__evolved_is_alive = function(...)
|
||||
local entity_count = __lua_select('#', ...)
|
||||
|
||||
return __freelist_ids[entity_index] == entity
|
||||
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
|
||||
if entity_count == 0 then
|
||||
return true
|
||||
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
|
||||
|
||||
---@param entity evolved.entity
|
||||
|
||||
Reference in New Issue
Block a user