new evolved.empty function

This commit is contained in:
BlackMATov
2024-12-29 03:58:07 +07:00
parent 6f8294f4ba
commit c11714e390
4 changed files with 46 additions and 9 deletions

View File

@@ -1,8 +1,7 @@
# evolved.lua (work in progress)
```
id :: id
alive :: id -> boolean
id :: integer? -> id...
pack :: integer, integer -> id
unpack :: id -> integer, integer
@@ -10,6 +9,9 @@ unpack :: id -> integer, integer
defer :: boolean
commit :: boolean
alive :: entity -> boolean
empty :: entity -> boolean
get :: entity, fragment... -> component...
has :: entity, fragment -> boolean
has_all :: entity, fragment... -> boolean

View File

@@ -6,3 +6,4 @@
- should insert/assign throw errors on failure?
- add auto chunk count reducing
- batching api for set/assign/insert/remove/clear/destroy
- every chunk can hold has_on_assign/has_on_insert/has_on_remove tags

View File

@@ -552,6 +552,32 @@ do
assert(not evo.alive(e))
end
do
local f = evo.id()
do
local e = evo.id()
assert(evo.empty(e))
evo.insert(e, f, 42)
assert(not evo.empty(e))
evo.clear(e)
assert(evo.empty(e))
end
do
local e = evo.id()
assert(evo.empty(e))
evo.insert(e, f, 42)
assert(not evo.empty(e))
evo.destroy(e)
assert(evo.empty(e))
end
end
do
local f1, f2, f3 = evo.id(3)

View File

@@ -1009,13 +1009,6 @@ function evolved.id(count)
end
end
---@param id evolved.id
---@return boolean
---@nodiscard
function evolved.alive(id)
return __alive_id(id)
end
---@param index integer
---@param version integer
---@return evolved.id
@@ -1042,6 +1035,21 @@ function evolved.commit()
return __defer_commit()
end
---@param entity evolved.entity
---@return boolean
---@nodiscard
function evolved.alive(entity)
return __alive_id(entity)
end
---@param entity evolved.entity
---@return boolean
---@nodiscard
function evolved.empty(entity)
return not __alive_id(entity)
or not __entity_chunks[__unpack_id(entity)]
end
---@param entity evolved.entity
---@param ... evolved.fragment fragments
---@return evolved.component ... components