mirror of
https://github.com/BlackMATov/evolved.lua.git
synced 2025-12-16 22:19:25 +07:00
evolved.chunk creates chunks now
This commit is contained in:
@@ -614,13 +614,11 @@ do
|
|||||||
end
|
end
|
||||||
|
|
||||||
do
|
do
|
||||||
local chunk, entities = evo.chunk(f1, f2, f3)
|
local chunk123, entities123 = evo.chunk(f1, f2, f3)
|
||||||
assert(not chunk and not entities)
|
local chunk321, entities321 = evo.chunk(f3, f2, f1)
|
||||||
end
|
assert(chunk123 and #entities123 == 0)
|
||||||
|
assert(chunk321 and #entities321 == 0)
|
||||||
do
|
assert(chunk123 == chunk321 and entities123 == entities321)
|
||||||
local chunk, entities = evo.chunk(f3, f2, f1)
|
|
||||||
assert(not chunk and not entities)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
53
evolved.lua
53
evolved.lua
@@ -2598,22 +2598,12 @@ function evolved.chunk(...)
|
|||||||
|
|
||||||
local root_fragment = fragment_list[1]
|
local root_fragment = fragment_list[1]
|
||||||
local chunk = __root_chunks[root_fragment]
|
local chunk = __root_chunks[root_fragment]
|
||||||
|
or __root_chunk(root_fragment)
|
||||||
if not chunk then
|
|
||||||
__release_table(__TABLE_POOL_TAG__FRAGMENT_LIST, fragment_list)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
for i = 2, fragment_count do
|
for i = 2, fragment_count do
|
||||||
local child_fragment = fragment_list[i]
|
local child_fragment = fragment_list[i]
|
||||||
if child_fragment > fragment_list[i - 1] then
|
chunk = chunk.__with_fragment_edges[child_fragment]
|
||||||
chunk = chunk.__with_fragment_edges[child_fragment]
|
or __chunk_with_fragment(chunk, child_fragment)
|
||||||
|
|
||||||
if not chunk then
|
|
||||||
__release_table(__TABLE_POOL_TAG__FRAGMENT_LIST, fragment_list)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
__release_table(__TABLE_POOL_TAG__FRAGMENT_LIST, fragment_list)
|
__release_table(__TABLE_POOL_TAG__FRAGMENT_LIST, fragment_list)
|
||||||
@@ -2770,8 +2760,8 @@ evolved_entity_builder.__index = evolved_entity_builder
|
|||||||
function evolved.entity()
|
function evolved.entity()
|
||||||
---@type evolved.__entity_builder
|
---@type evolved.__entity_builder
|
||||||
local builder = {
|
local builder = {
|
||||||
__fragment_list = nil,
|
__fragment_list = __acquire_table(__TABLE_POOL_TAG__FRAGMENT_LIST, 8, 0),
|
||||||
__component_list = nil,
|
__component_list = __acquire_table(__TABLE_POOL_TAG__COMPONENT_LIST, 8, 0),
|
||||||
}
|
}
|
||||||
---@cast builder evolved.entity_builder
|
---@cast builder evolved.entity_builder
|
||||||
return setmetatable(builder, evolved_entity_builder)
|
return setmetatable(builder, evolved_entity_builder)
|
||||||
@@ -2786,16 +2776,6 @@ function evolved_entity_builder:set(fragment, ...)
|
|||||||
local fragment_list = self.__fragment_list
|
local fragment_list = self.__fragment_list
|
||||||
local component_list = self.__component_list
|
local component_list = self.__component_list
|
||||||
|
|
||||||
if not fragment_list then
|
|
||||||
fragment_list = __acquire_table(__TABLE_POOL_TAG__FRAGMENT_LIST, 8, 0)
|
|
||||||
self.__fragment_list = fragment_list
|
|
||||||
end
|
|
||||||
|
|
||||||
if not component_list then
|
|
||||||
component_list = __acquire_table(__TABLE_POOL_TAG__COMPONENT_LIST, 8, 0)
|
|
||||||
self.__component_list = component_list
|
|
||||||
end
|
|
||||||
|
|
||||||
fragment_list[#fragment_list + 1] = fragment
|
fragment_list[#fragment_list + 1] = fragment
|
||||||
component_list[#component_list + 1] = component
|
component_list[#component_list + 1] = component
|
||||||
|
|
||||||
@@ -2807,26 +2787,19 @@ function evolved_entity_builder:build()
|
|||||||
local fragment_list = self.__fragment_list
|
local fragment_list = self.__fragment_list
|
||||||
local component_list = self.__component_list
|
local component_list = self.__component_list
|
||||||
|
|
||||||
self.__fragment_list = nil
|
self.__fragment_list = __acquire_table(__TABLE_POOL_TAG__FRAGMENT_LIST, 8, 0)
|
||||||
self.__component_list = nil
|
self.__component_list = __acquire_table(__TABLE_POOL_TAG__COMPONENT_LIST, 8, 0)
|
||||||
|
|
||||||
local entity = evolved.id()
|
local entity = evolved.id()
|
||||||
|
|
||||||
if fragment_list and component_list then
|
for i = 1, #fragment_list do
|
||||||
for i = 1, #fragment_list do
|
local fragment = fragment_list[i]
|
||||||
local fragment = fragment_list[i]
|
local component = component_list[i]
|
||||||
local component = component_list[i]
|
evolved.set(entity, fragment, component)
|
||||||
evolved.set(entity, fragment, component)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if fragment_list then
|
__release_table(__TABLE_POOL_TAG__FRAGMENT_LIST, fragment_list)
|
||||||
__release_table(__TABLE_POOL_TAG__FRAGMENT_LIST, fragment_list)
|
__release_table(__TABLE_POOL_TAG__COMPONENT_LIST, component_list)
|
||||||
end
|
|
||||||
|
|
||||||
if component_list then
|
|
||||||
__release_table(__TABLE_POOL_TAG__COMPONENT_LIST, component_list)
|
|
||||||
end
|
|
||||||
|
|
||||||
return entity
|
return entity
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user