diff --git a/README.md b/README.md index 00a6724..d1bc529 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ batch_multi_assign :: chunk | query, fragment[], component[]? -> integer, boolea batch_multi_insert :: chunk | query, fragment[], component[]? -> 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 fragments :: chunk -> fragment[], integer diff --git a/ROADMAP.md b/ROADMAP.md index 0315482..5877029 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -3,11 +3,11 @@ ## Backlog - should set/assign/insert return a constructed component? -- chunk(...) check for 0 fragments ## After first release - add system groups +- observers and events - add INDEX fragment trait - add REQUIRES fragment trait - use compact prefix-tree for chunks diff --git a/develop/unbench.lua b/develop/unbench.lua index 0c78fe0..8266781 100644 --- a/develop/unbench.lua +++ b/develop/unbench.lua @@ -619,7 +619,7 @@ basics.describe_bench(string.format('create and destroy %d entities / spawn_at', local fragments = {} local components = {} - local chunk = evo.chunk() + local chunk = nil for i = 1, N do entities[i] = spawn_at(chunk, fragments, components) diff --git a/develop/untests.lua b/develop/untests.lua index b489f05..5fbff34 100644 --- a/develop/untests.lua +++ b/develop/untests.lua @@ -647,11 +647,6 @@ do assert(evo.insert(e2b, f1, 44)) assert(evo.insert(e2b, f2, 45)) - do - local chunk, entities = evo.chunk() - assert(not chunk and not entities) - end - do local chunk, entities = evo.chunk(f1) assert(entities and entities[1] == e1) diff --git a/evolved.lua b/evolved.lua index 198e351..206d453 100644 --- a/evolved.lua +++ b/evolved.lua @@ -674,6 +674,7 @@ local __evolved_batch_multi_insert local __evolved_batch_multi_remove local __evolved_chunk + local __evolved_entities local __evolved_fragments local __evolved_components @@ -1175,25 +1176,19 @@ end --- --- ----@param ... evolved.fragment fragments ----@return evolved.chunk? +---@param head_fragment evolved.fragment +---@param ... evolved.fragment tail_fragments +---@return evolved.chunk ---@nodiscard -local function __chunk_fragments(...) - local fragment_count = __lua_select('#', ...) +local function __chunk_fragments(head_fragment, ...) + local chunk = __root_chunks[head_fragment] + or __chunk_with_fragment(nil, head_fragment) - if fragment_count == 0 then - return - end - - local root_fragment = ... - local chunk = __root_chunks[root_fragment] - or __chunk_with_fragment(nil, root_fragment) - - for i = 2, fragment_count do + for i = 1, __lua_select('#', ...) do ---@type evolved.fragment - local child_fragment = __lua_select(i, ...) - chunk = chunk.__with_fragment_edges[child_fragment] - or __chunk_with_fragment(chunk, child_fragment) + local tail_fragment = __lua_select(i, ...) + chunk = chunk.__with_fragment_edges[tail_fragment] + or __chunk_with_fragment(chunk, tail_fragment) end return chunk @@ -5037,8 +5032,7 @@ __evolved_is_empty = function(chunk_or_entity) local entity = chunk_or_entity --[[@as evolved.entity]] local entity_index = entity % 0x100000 - return __freelist_ids[entity_index] ~= entity - or not __entity_chunks[entity_index] + return __freelist_ids[entity_index] ~= entity or not __entity_chunks[entity_index] end end @@ -7088,22 +7082,18 @@ end --- --- ----@param ... evolved.fragment fragments ----@return evolved.chunk? chunk ----@return evolved.entity[]? entity_list ----@return integer? entity_count +---@param head_fragment evolved.fragment +---@param ... evolved.fragment tail_fragments +---@return evolved.chunk chunk +---@return evolved.entity[] entity_list +---@return integer entity_count ---@nodiscard -__evolved_chunk = function(...) +__evolved_chunk = function(head_fragment, ...) if __debug_mode then - __validate_fragments(...) - end - - local chunk = __chunk_fragments(...) - - if not chunk then - return + __validate_fragments(head_fragment, ...) end + local chunk = __chunk_fragments(head_fragment, ...) return chunk, chunk.__entity_list, chunk.__entity_count end