From 7d94689a39cc9d836590444816448c742f039325 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Sat, 8 Mar 2025 22:57:28 +0700 Subject: [PATCH] rename destroy policies --- README.md | 8 +++--- ROADMAP.md | 6 ----- develop/untests.lua | 32 +++++++++++------------ evolved.lua | 62 ++++++++++++++++++++++----------------------- 4 files changed, 51 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index 293eac1..35e2936 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,6 @@ ON_SET :: fragment ON_ASSIGN :: fragment ON_INSERT :: fragment ON_REMOVE :: fragment -ON_DESTROY :: fragment PHASE :: fragment AFTER :: fragment @@ -45,8 +44,9 @@ EXECUTE :: fragment PROLOGUE :: fragment EPILOGUE :: fragment -DESTROY_ENTITY_POLICY :: id -REMOVE_FRAGMENT_POLICY :: id +DESTROY_POLICY :: fragment +DESTROY_POLICY_DESTROY_ENTITY :: id +DESTROY_POLICY_REMOVE_FRAGMENT :: id ``` ## Functions @@ -126,7 +126,7 @@ fragment_builder:on_set :: {entity, fragment, component, component?} -> fragment fragment_builder:on_assign :: {entity, fragment, component, component} -> fragment_builder fragment_builder:on_insert :: {entity, fragment, component} -> fragment_builder fragment_builder:on_remove :: {entity, fragment} -> fragment_builder -fragment_builder:on_destroy :: id -> fragment_builder +fragment_builder:destroy_policy :: id -> fragment_builder fragment_builder:build :: fragment, boolean ``` diff --git a/ROADMAP.md b/ROADMAP.md index 2030052..3fad77f 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -6,12 +6,6 @@ - add destroing policies (fragments, phases, systems) - add debug view for chunks with help of NAME fragment traits -## Known issues - -- destroying of fragments leave chunks with dead fragments (destroing policies) -- destroying of systems can leave dead systems in the library state (destroying policies) -- destroying of phases can leave dead phases in the library state (destroying policies) - ## After first release - add system groups diff --git a/develop/untests.lua b/develop/untests.lua index c46d198..7427235 100644 --- a/develop/untests.lua +++ b/develop/untests.lua @@ -6726,7 +6726,7 @@ do local c1 = assert(evo.chunk(f1)) local c2 = assert(evo.chunk(f2)) local c12 = assert(evo.chunk(f1, f2)) - assert(evo.set(f1, evo.ON_DESTROY, evo.REMOVE_FRAGMENT_POLICY)) + assert(evo.set(f1, evo.DESTROY_POLICY, evo.DESTROY_POLICY_REMOVE_FRAGMENT)) assert(evo.set(f1, f1)) assert(evo.set(f2, f1)) assert(evo.set(f2, f2)) @@ -6760,7 +6760,7 @@ do local c1 = assert(evo.chunk(f1)) local c2 = assert(evo.chunk(f2)) local c12 = assert(evo.chunk(f1, f2)) - assert(evo.set(f1, evo.ON_DESTROY, evo.DESTROY_ENTITY_POLICY)) + assert(evo.set(f1, evo.DESTROY_POLICY, evo.DESTROY_POLICY_DESTROY_ENTITY)) assert(evo.set(f1, f1)) assert(evo.set(f2, f1)) assert(evo.set(f2, f2)) @@ -6818,7 +6818,7 @@ do local f1, f2, f3 = evo.id(3) local c1 = assert(evo.chunk(f1)) local c2 = assert(evo.chunk(f2)) - assert(evo.set(f1, evo.ON_DESTROY, evo.REMOVE_FRAGMENT_POLICY)) + assert(evo.set(f1, evo.DESTROY_POLICY, evo.DESTROY_POLICY_REMOVE_FRAGMENT)) assert(evo.set(f2, f1)) assert(evo.set(f3, f2)) do @@ -6845,7 +6845,7 @@ do local f1, f2, f3 = evo.id(3) local c1 = assert(evo.chunk(f1)) local c2 = assert(evo.chunk(f2)) - assert(evo.set(f1, evo.ON_DESTROY, evo.DESTROY_ENTITY_POLICY)) + assert(evo.set(f1, evo.DESTROY_POLICY, evo.DESTROY_POLICY_DESTROY_ENTITY)) assert(evo.set(f2, f1)) assert(evo.set(f3, f2)) do @@ -6872,7 +6872,7 @@ do assert(evo.set(f1, ft)) assert(evo.set(f2, ft)) assert(evo.set(f3, ft)) - assert(evo.set(f3, evo.ON_DESTROY, evo.DESTROY_ENTITY_POLICY)) + assert(evo.set(f3, evo.DESTROY_POLICY, evo.DESTROY_POLICY_DESTROY_ENTITY)) local qt = evo.query():include(ft):build() local c4 = assert(evo.chunk(f4)) @@ -6907,7 +6907,7 @@ end do local f1 = evo.id() - assert(evo.set(f1, evo.ON_DESTROY, evo.DESTROY_ENTITY_POLICY)) + assert(evo.set(f1, evo.DESTROY_POLICY, evo.DESTROY_POLICY_DESTROY_ENTITY)) assert(evo.set(f1, f1, f1)) local remove_count = 0 @@ -6933,7 +6933,7 @@ end do local f1 = evo.id() - assert(evo.set(f1, evo.ON_DESTROY, evo.REMOVE_FRAGMENT_POLICY)) + assert(evo.set(f1, evo.DESTROY_POLICY, evo.DESTROY_POLICY_REMOVE_FRAGMENT)) assert(evo.set(f1, f1, f1)) local remove_count = 0 @@ -7016,7 +7016,7 @@ do local f1, f2 = evo.id(2) evo.set(f1, f1) evo.set(f2, f1) - evo.set(f1, evo.ON_DESTROY, evo.DESTROY_ENTITY_POLICY) + evo.set(f1, evo.DESTROY_POLICY, evo.DESTROY_POLICY_DESTROY_ENTITY) assert(evo.destroy(f1)) assert(not evo.is_alive(f1)) assert(not evo.is_alive(f2)) @@ -7026,7 +7026,7 @@ do local f1, f2 = evo.id(2) evo.set(f1, f1) evo.set(f2, f1) - evo.set(f1, evo.ON_DESTROY, evo.REMOVE_FRAGMENT_POLICY) + evo.set(f1, evo.DESTROY_POLICY, evo.DESTROY_POLICY_REMOVE_FRAGMENT) assert(evo.destroy(f1)) assert(not evo.is_alive(f1)) assert(evo.is_alive(f2) and evo.is_empty(f2)) @@ -7036,7 +7036,7 @@ end do local f1, f2 = evo.id(2) - evo.set(f1, evo.ON_DESTROY, evo.DESTROY_ENTITY_POLICY) + evo.set(f1, evo.DESTROY_POLICY, evo.DESTROY_POLICY_DESTROY_ENTITY) local e12a = evo.entity():set(f1, 1):set(f2, 2):build() local e12b = evo.entity():set(f1, 3):set(f2, 4):build() @@ -7081,7 +7081,7 @@ do assert(c12, c123) end - evo.set(f1, evo.ON_DESTROY, evo.REMOVE_FRAGMENT_POLICY) + evo.set(f1, evo.DESTROY_POLICY, evo.DESTROY_POLICY_REMOVE_FRAGMENT) local e12a = evo.entity():set(f1, 1):set(f2, 2):build() local e12b = evo.entity():set(f1, 3):set(f2, 4):build() @@ -7112,12 +7112,12 @@ do local fb = evo.fragment() local f1 = fb:build() - local f2 = fb:on_destroy(evo.DESTROY_ENTITY_POLICY):build() - local f3 = fb:on_destroy(evo.REMOVE_FRAGMENT_POLICY):build() + local f2 = fb:destroy_policy(evo.DESTROY_POLICY_DESTROY_ENTITY):build() + local f3 = fb:destroy_policy(evo.DESTROY_POLICY_REMOVE_FRAGMENT):build() - assert(evo.get(f1, evo.ON_DESTROY) == nil) - assert(evo.get(f2, evo.ON_DESTROY) == evo.DESTROY_ENTITY_POLICY) - assert(evo.get(f3, evo.ON_DESTROY) == evo.REMOVE_FRAGMENT_POLICY) + assert(evo.get(f1, evo.DESTROY_POLICY) == nil) + assert(evo.get(f2, evo.DESTROY_POLICY) == evo.DESTROY_POLICY_DESTROY_ENTITY) + assert(evo.get(f3, evo.DESTROY_POLICY) == evo.DESTROY_POLICY_REMOVE_FRAGMENT) end do diff --git a/evolved.lua b/evolved.lua index 271c153..37765a2 100644 --- a/evolved.lua +++ b/evolved.lua @@ -555,7 +555,6 @@ local __ON_SET = __acquire_id() local __ON_ASSIGN = __acquire_id() local __ON_INSERT = __acquire_id() local __ON_REMOVE = __acquire_id() -local __ON_DESTROY = __acquire_id() local __PHASE = __acquire_id() local __AFTER = __acquire_id() @@ -566,8 +565,9 @@ local __EXECUTE = __acquire_id() local __PROLOGUE = __acquire_id() local __EPILOGUE = __acquire_id() -local __DESTROY_ENTITY_POLICY = __acquire_id() -local __REMOVE_FRAGMENT_POLICY = __acquire_id() +local __DESTROY_POLICY = __acquire_id() +local __DESTROY_POLICY_DESTROY_ENTITY = __acquire_id() +local __DESTROY_POLICY_REMOVE_FRAGMENT = __acquire_id() --- --- @@ -1681,18 +1681,18 @@ local function __purge_fragment(fragment, policy) local minor_chunk_list = minor_chunks.__item_list local minor_chunk_count = minor_chunks.__item_count - if policy == __DESTROY_ENTITY_POLICY then + if policy == __DESTROY_POLICY_DESTROY_ENTITY then for minor_chunk_index = minor_chunk_count, 1, -1 do local minor_chunk = minor_chunk_list[minor_chunk_index] purged_count = purged_count + __chunk_destroy(minor_chunk) end - elseif policy == __REMOVE_FRAGMENT_POLICY then + elseif policy == __DESTROY_POLICY_REMOVE_FRAGMENT then for minor_chunk_index = minor_chunk_count, 1, -1 do local minor_chunk = minor_chunk_list[minor_chunk_index] purged_count = purged_count + __chunk_remove(minor_chunk, fragment) end else - __lua_print(__lua_string_format('| evolved.lua | unknown ON_DESTROY policy (%s) on (%s)', + __lua_print(__lua_string_format('| evolved.lua | unknown DESTROY_POLICY policy (%s) on (%s)', __id_name(policy), __id_name(fragment))) end @@ -1713,12 +1713,12 @@ local function __purge_fragments(fragments, policies, count) for index = 1, count do local fragment, policy = fragments[index], policies[index] - if policy == __DESTROY_ENTITY_POLICY then - purged_count = purged_count + __purge_fragment(fragment, __DESTROY_ENTITY_POLICY) - elseif policy == __REMOVE_FRAGMENT_POLICY then - purged_count = purged_count + __purge_fragment(fragment, __REMOVE_FRAGMENT_POLICY) + if policy == __DESTROY_POLICY_DESTROY_ENTITY then + purged_count = purged_count + __purge_fragment(fragment, __DESTROY_POLICY_DESTROY_ENTITY) + elseif policy == __DESTROY_POLICY_REMOVE_FRAGMENT then + purged_count = purged_count + __purge_fragment(fragment, __DESTROY_POLICY_REMOVE_FRAGMENT) else - __lua_print(__lua_string_format('| evolved.lua | unknown ON_DESTROY policy (%s) on (%s)', + __lua_print(__lua_string_format('| evolved.lua | unknown DESTROY_POLICY policy (%s) on (%s)', __id_name(policy), __id_name(fragment))) end end @@ -2309,8 +2309,8 @@ __chunk_destroy = function(chunk) if __minor_chunks[entity] then purging_count = purging_count + 1 - purging_policies[purging_count] = __chunk_get_components(chunk, place, __ON_DESTROY) - or __REMOVE_FRAGMENT_POLICY + purging_policies[purging_count] = __chunk_get_components(chunk, place, __DESTROY_POLICY) + or __DESTROY_POLICY_REMOVE_FRAGMENT purging_fragments[purging_count] = entity end @@ -5233,8 +5233,8 @@ __evolved_destroy = function(entity) if __minor_chunks[entity] then purging_fragment = entity - purging_policy = chunk and __chunk_get_components(chunk, place, __ON_DESTROY) - or __REMOVE_FRAGMENT_POLICY + purging_policy = chunk and __chunk_get_components(chunk, place, __DESTROY_POLICY) + or __DESTROY_POLICY_REMOVE_FRAGMENT end if chunk then @@ -6821,7 +6821,7 @@ end ---@field package __on_assign? evolved.set_hook ---@field package __on_insert? evolved.set_hook ---@field package __on_remove? evolved.remove_hook ----@field package __on_destroy? evolved.id +---@field package __destroy_policy? evolved.id ---@class evolved.fragment_builder : evolved.__fragment_builder local evolved_fragment_builder = {} @@ -6841,7 +6841,7 @@ __evolved_fragment = function() __on_assign = nil, __on_insert = nil, __on_remove = nil, - __on_destroy = nil, + __destroy_policy = nil, } ---@cast builder evolved.fragment_builder return __lua_setmetatable(builder, evolved_fragment_builder) @@ -6909,10 +6909,10 @@ function evolved_fragment_builder:on_remove(on_remove) return self end ----@param on_destroy evolved.id +---@param destroy_policy evolved.id ---@return evolved.fragment_builder builder -function evolved_fragment_builder:on_destroy(on_destroy) - self.__on_destroy = on_destroy +function evolved_fragment_builder:destroy_policy(destroy_policy) + self.__destroy_policy = destroy_policy return self end @@ -6929,7 +6929,7 @@ function evolved_fragment_builder:build() local on_assign = self.__on_assign local on_insert = self.__on_insert local on_remove = self.__on_remove - local on_destroy = self.__on_destroy + local destroy_policy = self.__destroy_policy self.__tag = false self.__name = nil @@ -6941,7 +6941,7 @@ function evolved_fragment_builder:build() self.__on_assign = nil self.__on_insert = nil self.__on_remove = nil - self.__on_destroy = nil + self.__destroy_policy = nil local fragment = __evolved_id() @@ -7003,10 +7003,10 @@ function evolved_fragment_builder:build() component_list[component_count] = on_remove end - if on_destroy then + if destroy_policy then component_count = component_count + 1 - fragment_list[component_count] = __ON_DESTROY - component_list[component_count] = on_destroy + fragment_list[component_count] = __DESTROY_POLICY + component_list[component_count] = destroy_policy end local _, is_deferred = __evolved_multi_set(fragment, fragment_list, component_list) @@ -7577,7 +7577,6 @@ __lua_assert(__evolved_insert(__ON_SET, __NAME, 'ON_SET')) __lua_assert(__evolved_insert(__ON_ASSIGN, __NAME, 'ON_ASSIGN')) __lua_assert(__evolved_insert(__ON_INSERT, __NAME, 'ON_INSERT')) __lua_assert(__evolved_insert(__ON_REMOVE, __NAME, 'ON_REMOVE')) -__lua_assert(__evolved_insert(__ON_DESTROY, __NAME, 'ON_DESTROY')) __lua_assert(__evolved_insert(__PHASE, __NAME, 'PHASE')) __lua_assert(__evolved_insert(__AFTER, __NAME, 'AFTER')) @@ -7588,8 +7587,9 @@ __lua_assert(__evolved_insert(__EXECUTE, __NAME, 'EXECUTE')) __lua_assert(__evolved_insert(__PROLOGUE, __NAME, 'PROLOGUE')) __lua_assert(__evolved_insert(__EPILOGUE, __NAME, 'EPILOGUE')) -__lua_assert(__evolved_insert(__DESTROY_ENTITY_POLICY, __NAME, 'DESTROY_ENTITY_POLICY')) -__lua_assert(__evolved_insert(__REMOVE_FRAGMENT_POLICY, __NAME, 'REMOVE_FRAGMENT_POLICY')) +__lua_assert(__evolved_insert(__DESTROY_POLICY, __NAME, 'DESTROY_POLICY')) +__lua_assert(__evolved_insert(__DESTROY_POLICY_DESTROY_ENTITY, __NAME, 'DESTROY_POLICY_DESTROY_ENTITY')) +__lua_assert(__evolved_insert(__DESTROY_POLICY_REMOVE_FRAGMENT, __NAME, 'DESTROY_POLICY_REMOVE_FRAGMENT')) --- --- @@ -7766,7 +7766,6 @@ evolved.ON_SET = __ON_SET evolved.ON_ASSIGN = __ON_ASSIGN evolved.ON_INSERT = __ON_INSERT evolved.ON_REMOVE = __ON_REMOVE -evolved.ON_DESTROY = __ON_DESTROY evolved.PHASE = __PHASE evolved.AFTER = __AFTER @@ -7777,8 +7776,9 @@ evolved.EXECUTE = __EXECUTE evolved.PROLOGUE = __PROLOGUE evolved.EPILOGUE = __EPILOGUE -evolved.DESTROY_ENTITY_POLICY = __DESTROY_ENTITY_POLICY -evolved.REMOVE_FRAGMENT_POLICY = __REMOVE_FRAGMENT_POLICY +evolved.DESTROY_POLICY = __DESTROY_POLICY +evolved.DESTROY_POLICY_DESTROY_ENTITY = __DESTROY_POLICY_DESTROY_ENTITY +evolved.DESTROY_POLICY_REMOVE_FRAGMENT = __DESTROY_POLICY_REMOVE_FRAGMENT evolved.id = __evolved_id