create component storages in one place

This commit is contained in:
BlackMATov
2025-03-03 22:07:22 +07:00
parent 04691e11a4
commit f5ccd775a0

View File

@@ -36,7 +36,7 @@ local evolved = {
---@alias evolved.system evolved.id ---@alias evolved.system evolved.id
---@alias evolved.component any ---@alias evolved.component any
---@alias evolved.component_storage evolved.component[] ---@alias evolved.storage evolved.component[]
---@alias evolved.default evolved.component ---@alias evolved.default evolved.component
---@alias evolved.construct fun(...: any): evolved.component ---@alias evolved.construct fun(...: any): evolved.component
@@ -62,7 +62,7 @@ local evolved = {
---@field package __fragment_count integer ---@field package __fragment_count integer
---@field package __component_count integer ---@field package __component_count integer
---@field package __component_indices table<evolved.fragment, integer> ---@field package __component_indices table<evolved.fragment, integer>
---@field package __component_storages evolved.component_storage[] ---@field package __component_storages evolved.storage[]
---@field package __component_fragments evolved.fragment[] ---@field package __component_fragments evolved.fragment[]
---@field package __with_fragment_edges table<evolved.fragment, evolved.chunk> ---@field package __with_fragment_edges table<evolved.fragment, evolved.chunk>
---@field package __without_fragment_edges table<evolved.fragment, evolved.chunk> ---@field package __without_fragment_edges table<evolved.fragment, evolved.chunk>
@@ -674,6 +674,7 @@ end
---@param ... any component arguments ---@param ... any component arguments
---@return evolved.component ---@return evolved.component
---@nodiscard
local function __component_list(...) local function __component_list(...)
local argument_count = __lua_select('#', ...) local argument_count = __lua_select('#', ...)
@@ -690,8 +691,17 @@ local function __component_list(...)
return argument_list return argument_list
end end
---@param fragment evolved.fragment
---@return evolved.storage
---@nodiscard
---@diagnostic disable-next-line: unused-local
local function __component_storage(fragment)
return {}
end
---@param ... any component arguments ---@param ... any component arguments
---@return evolved.component ---@return evolved.component
---@nodiscard
local function __component_construct(fragment, ...) local function __component_construct(fragment, ...)
---@type evolved.default, evolved.construct ---@type evolved.default, evolved.construct
local default, construct = __evolved_get(fragment, __DEFAULT, __CONSTRUCT) local default, construct = __evolved_get(fragment, __DEFAULT, __CONSTRUCT)
@@ -812,7 +822,7 @@ function __chunk_component_indices_mt.__tostring(self)
return __lua_string_format('{%s}', __lua_table_concat(items, ', ')) return __lua_string_format('{%s}', __lua_table_concat(items, ', '))
end end
---@param self evolved.component_storage[] ---@param self evolved.storage[]
function __chunk_component_storages_mt.__tostring(self) function __chunk_component_storages_mt.__tostring(self)
local items = {} ---@type string[] local items = {} ---@type string[]
@@ -839,6 +849,7 @@ end
---@param chunk_parent? evolved.chunk ---@param chunk_parent? evolved.chunk
---@param chunk_fragment evolved.fragment ---@param chunk_fragment evolved.fragment
---@return evolved.chunk ---@return evolved.chunk
---@nodiscard
local function __new_chunk(chunk_parent, chunk_fragment) local function __new_chunk(chunk_parent, chunk_fragment)
---@type table<evolved.fragment, integer> ---@type table<evolved.fragment, integer>
local chunk_fragment_set = __lua_setmetatable({}, __chunk_fragment_set_mt) local chunk_fragment_set = __lua_setmetatable({}, __chunk_fragment_set_mt)
@@ -855,7 +866,7 @@ local function __new_chunk(chunk_parent, chunk_fragment)
---@type table<evolved.fragment, integer> ---@type table<evolved.fragment, integer>
local chunk_component_indices = __lua_setmetatable({}, __chunk_component_indices_mt) local chunk_component_indices = __lua_setmetatable({}, __chunk_component_indices_mt)
---@type evolved.component_storage[] ---@type evolved.storage[]
local chunk_component_storages = __lua_setmetatable({}, __chunk_component_storages_mt) local chunk_component_storages = __lua_setmetatable({}, __chunk_component_storages_mt)
---@type evolved.fragment[] ---@type evolved.fragment[]
@@ -909,7 +920,7 @@ local function __new_chunk(chunk_parent, chunk_fragment)
if not __evolved_has(parent_fragment, __TAG) then if not __evolved_has(parent_fragment, __TAG) then
chunk_component_count = chunk_component_count + 1 chunk_component_count = chunk_component_count + 1
local component_storage = {} local component_storage = __component_storage(parent_fragment)
local component_storage_index = chunk_component_count local component_storage_index = chunk_component_count
chunk_component_indices[parent_fragment] = component_storage_index chunk_component_indices[parent_fragment] = component_storage_index
chunk_component_storages[component_storage_index] = component_storage chunk_component_storages[component_storage_index] = component_storage
@@ -932,7 +943,7 @@ local function __new_chunk(chunk_parent, chunk_fragment)
if not __evolved_has(chunk_fragment, __TAG) then if not __evolved_has(chunk_fragment, __TAG) then
chunk_component_count = chunk_component_count + 1 chunk_component_count = chunk_component_count + 1
local component_storage = {} local component_storage = __component_storage(chunk_fragment)
local component_storage_index = chunk_component_count local component_storage_index = chunk_component_count
chunk_component_indices[chunk_fragment] = component_storage_index chunk_component_indices[chunk_fragment] = component_storage_index
chunk_component_storages[component_storage_index] = component_storage chunk_component_storages[component_storage_index] = component_storage
@@ -6365,7 +6376,7 @@ end
---@param chunk evolved.chunk ---@param chunk evolved.chunk
---@param ... evolved.fragment fragments ---@param ... evolved.fragment fragments
---@return evolved.component_storage ... component_storages ---@return evolved.storage ... storages
---@nodiscard ---@nodiscard
__evolved_select = function(chunk, ...) __evolved_select = function(chunk, ...)
local fragment_count = __lua_select('#', ...) local fragment_count = __lua_select('#', ...)