check modifications after destroying

This commit is contained in:
BlackMATov
2024-11-24 11:28:13 +07:00
parent cd3f895d15
commit 13c3de1e89
3 changed files with 49 additions and 1 deletions

View File

@@ -5,7 +5,7 @@
- [x] add additional oop-like api
- [ ] add blocklist of fragments for queries
- [ ] add checks of prohibited changes while querying
- [ ] add check inserts and removes after destroying entity
- [x] add check inserts and removes after destroying entity
- [x] add multi remove fragments function from entities
- [ ] cache matched chunks in queries
- [x] cache transitions between chunks

View File

@@ -162,6 +162,38 @@ do
end
end
do
local f1, f2 = evo.registry.entity(), evo.registry.entity()
local e = evo.registry.entity()
assert(e:insert(f1))
assert(e:is_alive())
assert(e.__chunk == evo.registry.chunk(f1))
assert(e:destroy())
assert(not e:is_alive())
assert(e.__chunk == nil)
assert(not e:assign(f1, 42))
assert(not e:assign(f2, 42))
assert(not e:is_alive())
assert(e.__chunk == nil)
assert(not e:insert(f1, 42))
assert(not e:insert(f2, 42))
assert(not e:is_alive())
assert(e.__chunk == nil)
assert(not e:remove(f1, 42))
assert(not e:remove(f2, 42))
assert(not e:is_alive())
assert(e.__chunk == nil)
assert(not e:clear())
assert(not e:is_alive())
assert(e.__chunk == nil)
end
for _ = 1, 100 do
local insert_fragments = {} ---@type evolved.entity[]
local insert_fragment_count = math.random(0, 10)

View File

@@ -349,6 +349,10 @@ end
---@param component any
---@return boolean is_assigned
function registry.assign(entity, fragment, component)
if not idpools.is_alive(__guids, entity.__guid) then
return false
end
component = component == nil and true or component
local chunk_components = entity.__chunk and entity.__chunk.__components[fragment]
@@ -366,6 +370,10 @@ end
---@param component any
---@return boolean is_inserted
function registry.insert(entity, fragment, component)
if not idpools.is_alive(__guids, entity.__guid) then
return false
end
component = component == nil and true or component
local old_chunk = entity.__chunk
@@ -402,6 +410,10 @@ end
---@param ... evolved.entity fragments
---@return boolean is_removed
function registry.remove(entity, ...)
if not idpools.is_alive(__guids, entity.__guid) then
return false
end
local old_chunk = entity.__chunk
local new_chunk = entity.__chunk
@@ -442,6 +454,10 @@ end
---@param entity evolved.entity
---@return boolean is_cleared
function registry.clear(entity)
if not idpools.is_alive(__guids, entity.__guid) then
return false
end
if entity.__chunk == nil then
return false
end