mirror of
https://github.com/BlackMATov/evolved.lua.git
synced 2025-12-16 22:19:25 +07:00
chunk(...) must accept at least one fragment
This commit is contained in:
@@ -98,7 +98,7 @@ batch_multi_assign :: chunk | query, fragment[], component[]? -> integer, boolea
|
|||||||
batch_multi_insert :: chunk | query, fragment[], component[]? -> integer, boolean
|
batch_multi_insert :: chunk | query, fragment[], component[]? -> integer, boolean
|
||||||
batch_multi_remove :: chunk | query, fragment[] -> integer, boolean
|
batch_multi_remove :: chunk | query, fragment[] -> integer, boolean
|
||||||
|
|
||||||
chunk :: fragment... -> chunk?, entity[]?, integer?
|
chunk :: fragment, fragment... -> chunk, entity[], integer
|
||||||
|
|
||||||
entities :: chunk -> entity[], integer
|
entities :: chunk -> entity[], integer
|
||||||
fragments :: chunk -> fragment[], integer
|
fragments :: chunk -> fragment[], integer
|
||||||
|
|||||||
@@ -3,11 +3,11 @@
|
|||||||
## Backlog
|
## Backlog
|
||||||
|
|
||||||
- should set/assign/insert return a constructed component?
|
- should set/assign/insert return a constructed component?
|
||||||
- chunk(...) check for 0 fragments
|
|
||||||
|
|
||||||
## After first release
|
## After first release
|
||||||
|
|
||||||
- add system groups
|
- add system groups
|
||||||
|
- observers and events
|
||||||
- add INDEX fragment trait
|
- add INDEX fragment trait
|
||||||
- add REQUIRES fragment trait
|
- add REQUIRES fragment trait
|
||||||
- use compact prefix-tree for chunks
|
- use compact prefix-tree for chunks
|
||||||
|
|||||||
@@ -619,7 +619,7 @@ basics.describe_bench(string.format('create and destroy %d entities / spawn_at',
|
|||||||
local fragments = {}
|
local fragments = {}
|
||||||
local components = {}
|
local components = {}
|
||||||
|
|
||||||
local chunk = evo.chunk()
|
local chunk = nil
|
||||||
|
|
||||||
for i = 1, N do
|
for i = 1, N do
|
||||||
entities[i] = spawn_at(chunk, fragments, components)
|
entities[i] = spawn_at(chunk, fragments, components)
|
||||||
|
|||||||
@@ -647,11 +647,6 @@ do
|
|||||||
assert(evo.insert(e2b, f1, 44))
|
assert(evo.insert(e2b, f1, 44))
|
||||||
assert(evo.insert(e2b, f2, 45))
|
assert(evo.insert(e2b, f2, 45))
|
||||||
|
|
||||||
do
|
|
||||||
local chunk, entities = evo.chunk()
|
|
||||||
assert(not chunk and not entities)
|
|
||||||
end
|
|
||||||
|
|
||||||
do
|
do
|
||||||
local chunk, entities = evo.chunk(f1)
|
local chunk, entities = evo.chunk(f1)
|
||||||
assert(entities and entities[1] == e1)
|
assert(entities and entities[1] == e1)
|
||||||
|
|||||||
50
evolved.lua
50
evolved.lua
@@ -674,6 +674,7 @@ local __evolved_batch_multi_insert
|
|||||||
local __evolved_batch_multi_remove
|
local __evolved_batch_multi_remove
|
||||||
|
|
||||||
local __evolved_chunk
|
local __evolved_chunk
|
||||||
|
|
||||||
local __evolved_entities
|
local __evolved_entities
|
||||||
local __evolved_fragments
|
local __evolved_fragments
|
||||||
local __evolved_components
|
local __evolved_components
|
||||||
@@ -1175,25 +1176,19 @@ end
|
|||||||
---
|
---
|
||||||
---
|
---
|
||||||
|
|
||||||
---@param ... evolved.fragment fragments
|
---@param head_fragment evolved.fragment
|
||||||
---@return evolved.chunk?
|
---@param ... evolved.fragment tail_fragments
|
||||||
|
---@return evolved.chunk
|
||||||
---@nodiscard
|
---@nodiscard
|
||||||
local function __chunk_fragments(...)
|
local function __chunk_fragments(head_fragment, ...)
|
||||||
local fragment_count = __lua_select('#', ...)
|
local chunk = __root_chunks[head_fragment]
|
||||||
|
or __chunk_with_fragment(nil, head_fragment)
|
||||||
|
|
||||||
if fragment_count == 0 then
|
for i = 1, __lua_select('#', ...) do
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local root_fragment = ...
|
|
||||||
local chunk = __root_chunks[root_fragment]
|
|
||||||
or __chunk_with_fragment(nil, root_fragment)
|
|
||||||
|
|
||||||
for i = 2, fragment_count do
|
|
||||||
---@type evolved.fragment
|
---@type evolved.fragment
|
||||||
local child_fragment = __lua_select(i, ...)
|
local tail_fragment = __lua_select(i, ...)
|
||||||
chunk = chunk.__with_fragment_edges[child_fragment]
|
chunk = chunk.__with_fragment_edges[tail_fragment]
|
||||||
or __chunk_with_fragment(chunk, child_fragment)
|
or __chunk_with_fragment(chunk, tail_fragment)
|
||||||
end
|
end
|
||||||
|
|
||||||
return chunk
|
return chunk
|
||||||
@@ -5037,8 +5032,7 @@ __evolved_is_empty = function(chunk_or_entity)
|
|||||||
local entity = chunk_or_entity --[[@as evolved.entity]]
|
local entity = chunk_or_entity --[[@as evolved.entity]]
|
||||||
|
|
||||||
local entity_index = entity % 0x100000
|
local entity_index = entity % 0x100000
|
||||||
return __freelist_ids[entity_index] ~= entity
|
return __freelist_ids[entity_index] ~= entity or not __entity_chunks[entity_index]
|
||||||
or not __entity_chunks[entity_index]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -7088,22 +7082,18 @@ end
|
|||||||
---
|
---
|
||||||
---
|
---
|
||||||
|
|
||||||
---@param ... evolved.fragment fragments
|
---@param head_fragment evolved.fragment
|
||||||
---@return evolved.chunk? chunk
|
---@param ... evolved.fragment tail_fragments
|
||||||
---@return evolved.entity[]? entity_list
|
---@return evolved.chunk chunk
|
||||||
---@return integer? entity_count
|
---@return evolved.entity[] entity_list
|
||||||
|
---@return integer entity_count
|
||||||
---@nodiscard
|
---@nodiscard
|
||||||
__evolved_chunk = function(...)
|
__evolved_chunk = function(head_fragment, ...)
|
||||||
if __debug_mode then
|
if __debug_mode then
|
||||||
__validate_fragments(...)
|
__validate_fragments(head_fragment, ...)
|
||||||
end
|
|
||||||
|
|
||||||
local chunk = __chunk_fragments(...)
|
|
||||||
|
|
||||||
if not chunk then
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local chunk = __chunk_fragments(head_fragment, ...)
|
||||||
return chunk, chunk.__entity_list, chunk.__entity_count
|
return chunk, chunk.__entity_list, chunk.__entity_count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user