rename is_alive to alive

This commit is contained in:
BlackMATov
2024-11-27 00:07:22 +07:00
parent 651edfe574
commit d2910f2e3f
5 changed files with 44 additions and 44 deletions
+4 -4
View File
@@ -6,9 +6,9 @@
idpools.idpool -> (idpool)
idpools.pack -> integer -> integer -> (id)
idpools.unpack -> id -> (integer, integer)
idpools.alive -> idpool -> id -> (boolean)
idpools.acquire -> idpool -> (id)
idpools.release -> idpool -> id -> ()
idpools.is_alive -> idpool -> id -> (boolean)
```
### Instance `idpool`
@@ -16,9 +16,9 @@ idpools.is_alive -> idpool -> id -> (boolean)
```
idpool.pack -> integer -> integer -> (id)
idpool.unpack -> id -> (integer, integer)
idpool:alive -> id -> (boolean)
idpool:acquire -> (id)
idpool:release -> id -> ()
idpool:is_alive -> id -> (boolean)
```
## Module `registry`
@@ -26,7 +26,7 @@ idpool:is_alive -> id -> (boolean)
```
registry.entity -> (entity)
registry.guid -> entity -> (id)
registry.is_alive -> entity -> (boolean)
registry.alive -> entity -> (boolean)
registry.destroy -> entity -> ()
registry.del -> entity -> entity... -> (entity)
registry.set -> entity -> entity -> any -> (entity)
@@ -52,7 +52,7 @@ registry.components -> chunk -> entity -> (any[])
```
entity:guid -> (id)
entity:is_alive -> (boolean)
entity:alive -> (boolean)
entity:destroy -> ()
entity:del -> entity... -> (entity)
entity:set -> entity -> any -> (entity)
+10 -10
View File
@@ -32,16 +32,16 @@ do
local i1_1 = p:acquire()
local i2_1 = p:acquire()
assert(p:is_alive(i1_1))
assert(p:is_alive(i2_1))
assert(p:alive(i1_1))
assert(p:alive(i2_1))
p:release(i1_1)
assert(not p:is_alive(i1_1))
assert(p:is_alive(i2_1))
assert(not p:alive(i1_1))
assert(p:alive(i2_1))
p:release(i2_1)
assert(not p:is_alive(i1_1))
assert(not p:is_alive(i2_1))
assert(not p:alive(i1_1))
assert(not p:alive(i2_1))
local i2_2 = p:acquire()
assert(i2_2 == 0x200002)
@@ -49,10 +49,10 @@ do
local i1_2 = p:acquire()
assert(i1_2 == 0x200001)
assert(not p:is_alive(i1_1))
assert(not p:is_alive(i2_1))
assert(p:is_alive(i1_2))
assert(p:is_alive(i2_2))
assert(not p:alive(i1_1))
assert(not p:alive(i2_1))
assert(p:alive(i1_2))
assert(p:alive(i2_2))
end
do
+12 -12
View File
@@ -120,15 +120,15 @@ do
assert(e:insert(f1))
assert(e:insert(f2))
assert(e:is_alive())
assert(e:alive())
assert(e.__chunk == evo.registry.chunk(f1, f2))
assert(e:destroy())
assert(not e:is_alive())
assert(not e:alive())
assert(e.__chunk == nil)
assert(not e:destroy())
assert(not e:is_alive())
assert(not e:alive())
assert(e.__chunk == nil)
end
@@ -218,15 +218,15 @@ do
assert(e:insert(f1))
assert(e:insert(f2))
assert(e:is_alive())
assert(e:alive())
assert(e.__chunk == evo.registry.chunk(f1, f2))
assert(e == e:detach())
assert(e:is_alive())
assert(e:alive())
assert(e.__chunk == nil)
assert(e == e:detach())
assert(e:is_alive())
assert(e:alive())
assert(e.__chunk == nil)
end
@@ -282,30 +282,30 @@ do
local e = evo.registry.entity()
assert(e:insert(f1))
assert(e:is_alive())
assert(e:alive())
assert(e.__chunk == evo.registry.chunk(f1))
assert(e:destroy())
assert(not e:is_alive())
assert(not e:alive())
assert(e.__chunk == nil)
assert(not e:assign(f1, 42))
assert(not e:assign(f2, 42))
assert(not e:is_alive())
assert(not e:alive())
assert(e.__chunk == nil)
assert(not e:insert(f1, 42))
assert(not e:insert(f2, 42))
assert(not e:is_alive())
assert(not e:alive())
assert(e.__chunk == nil)
assert(not e:remove(f1, 42))
assert(not e:remove(f2, 42))
assert(not e:is_alive())
assert(not e:alive())
assert(e.__chunk == nil)
assert(e == e:detach())
assert(not e:is_alive())
assert(not e:alive())
assert(e.__chunk == nil)
end
+10 -10
View File
@@ -49,6 +49,15 @@ function idpools.unpack(id)
return index, version
end
---@param idpool evolved.idpool
---@param id evolved.id
---@return boolean
---@nodiscard
function idpools.alive(idpool, id)
local index = id % 0x100000
return idpool.__freelist_ids[index] == id
end
---@param idpool evolved.idpool
---@return evolved.id
---@nodiscard
@@ -94,15 +103,6 @@ function idpools.release(idpool, id)
idpool.__available_index = index
end
---@param idpool evolved.idpool
---@param id evolved.id
---@return boolean
---@nodiscard
function idpools.is_alive(idpool, id)
local index = id % 0x100000
return idpool.__freelist_ids[index] == id
end
---
---
---
@@ -111,9 +111,9 @@ end
evolved_idpool_mt.pack = idpools.pack
evolved_idpool_mt.unpack = idpools.unpack
evolved_idpool_mt.alive = idpools.alive
evolved_idpool_mt.acquire = idpools.acquire
evolved_idpool_mt.release = idpools.release
evolved_idpool_mt.is_alive = idpools.is_alive
---
---
+8 -8
View File
@@ -338,14 +338,14 @@ end
---@param entity evolved.entity
---@return boolean
---@nodiscard
function registry.is_alive(entity)
return idpools.is_alive(__guids, entity.__guid)
function registry.alive(entity)
return idpools.alive(__guids, entity.__guid)
end
---@param entity evolved.entity
---@return boolean is_destroyed
function registry.destroy(entity)
if not idpools.is_alive(__guids, entity.__guid) then
if not idpools.alive(__guids, entity.__guid) then
return false
end
@@ -464,7 +464,7 @@ end
---@param component any
---@return boolean is_assigned
function registry.assign(entity, fragment, component)
if not idpools.is_alive(__guids, entity.__guid) then
if not idpools.alive(__guids, entity.__guid) then
return false
end
@@ -487,7 +487,7 @@ end
---@param component any
---@return boolean is_inserted
function registry.insert(entity, fragment, component)
if not idpools.is_alive(__guids, entity.__guid) then
if not idpools.alive(__guids, entity.__guid) then
return false
end
@@ -525,7 +525,7 @@ end
---@param ... evolved.entity fragments
---@return boolean is_removed
function registry.remove(entity, ...)
if not idpools.is_alive(__guids, entity.__guid) then
if not idpools.alive(__guids, entity.__guid) then
return false
end
@@ -564,7 +564,7 @@ end
---@param entity evolved.entity
---@return evolved.entity
function registry.detach(entity)
if not idpools.is_alive(__guids, entity.__guid) then
if not idpools.alive(__guids, entity.__guid) then
return entity
end
@@ -738,7 +738,7 @@ function evolved_entity_mt:__tostring()
end
evolved_entity_mt.guid = registry.guid
evolved_entity_mt.is_alive = registry.is_alive
evolved_entity_mt.alive = registry.alive
evolved_entity_mt.destroy = registry.destroy
evolved_entity_mt.del = registry.del
evolved_entity_mt.set = registry.set