From 281866cf6e2bc1b5ded65884a52edb54aa5f36ff Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Tue, 23 Sep 2025 07:24:26 +0700 Subject: [PATCH] set/assign hooks are not invoked for tags on override operations anymore --- README.md | 8 ++++++-- develop/untests.lua | 14 +++++++------- evolved.lua | 22 +++------------------- 3 files changed, 16 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 3be4ddd..b77e55a 100644 --- a/README.md +++ b/README.md @@ -913,6 +913,9 @@ evolved.set(player, health, 200) -- prints "health set to 200" Use [`evolved.ON_SET`](#evolvedon_set) for callbacks on fragment insert or override, [`evolved.ON_ASSIGN`](#evolvedon_assign) for overrides, and [`evolved.ON_INSERT`](#evolvedon_insert)/[`evolved.ON_REMOVE`](#evolvedon_remove) for insertions or removals. +> [!NOTE] +> Because fragments marked with [`evolved.TAG`](#evolvedtag) (also called [Fragment Tags](#fragment-tags)) have no components, their [`evolved.ON_SET`](#evolvedon_set) hooks are invoked only when the tag is inserted, not when it is overridden, as there is nothing to override. Their [`evolved.ON_ASSIGN`](#evolvedon_assign) hooks are never invoked for such tags for the same reason. + #### Unique Fragments Some fragments should not be cloned when cloning entities. For example, `evolved.lua` has a special fragment called `evolved.PREFAB`, which marks entities used as sources for cloning. This fragment should not be present on the cloned entities. To prevent a fragment from being cloned, mark it as unique using the [`evolved.UNIQUE`](#evolvedunique) fragment trait. This ensures the fragment will not be copied when cloning entities. @@ -1114,7 +1117,7 @@ execute :: {chunk, entity[], integer} prologue :: {} epilogue :: {} -set_hook :: {entity, fragment, component, component?} +set_hook :: {entity, fragment, component, component} assign_hook :: {entity, fragment, component, component} insert_hook :: {entity, fragment, component} remove_hook :: {entity, fragment, component} @@ -1275,7 +1278,7 @@ builder_mt:include :: fragment... -> builder builder_mt:exclude :: fragment... -> builder builder_mt:require :: fragment... -> builder -builder_mt:on_set :: {entity, fragment, component, component?} -> builder +builder_mt:on_set :: {entity, fragment, component, component} -> builder builder_mt:on_assign :: {entity, fragment, component, component} -> builder builder_mt:on_insert :: {entity, fragment, component} -> builder builder_mt:on_remove :: {entity, fragment} -> builder @@ -1299,6 +1302,7 @@ builder_mt:destruction_policy :: id -> builder - Added the new [`evolved.locate`](#evolvedlocate) function - The internal garbage collector now collects more garbage - Improved system processing debugging experience with stack traces on errors +- [`SET/ASSIGN hooks`](#fragment-hooks) are not invoked for tags on override operations anymore ### v1.2.0 diff --git a/develop/untests.lua b/develop/untests.lua index b35b452..abc01f7 100644 --- a/develop/untests.lua +++ b/develop/untests.lua @@ -1525,7 +1525,7 @@ do do last_set_entity = 0 evo.set(e, f1, 41) - assert(last_set_entity == e) + assert(last_set_entity == 0) assert(evo.has(e, f1) and not evo.has(e, f2)) assert(evo.get(e, f1) == nil and evo.get(e, f2) == nil) end @@ -1539,13 +1539,13 @@ do do last_set_entity = 0 evo.set(e, f1, 42) - assert(last_set_entity == e) + assert(last_set_entity == 0) assert(evo.has(e, f1) and evo.has(e, f2)) assert(evo.get(e, f1) == nil and evo.get(e, f2) == nil) last_set_entity = 0 evo.set(e, f2, 42) - assert(last_set_entity == e) + assert(last_set_entity == 0) assert(evo.has(e, f1) and evo.has(e, f2)) assert(evo.get(e, f1) == nil and evo.get(e, f2) == nil) end @@ -1559,13 +1559,13 @@ do do last_set_entity = 0 evo.set(e, f1, 42) - assert(last_set_entity == e) + assert(last_set_entity == 0) assert(evo.has(e, f1) and evo.has(e, f2) and evo.has(e, f3)) assert(evo.get(e, f1) == nil and evo.get(e, f2) == nil and evo.get(e, f3) == 43) last_set_entity = 0 evo.set(e, f2, 42) - assert(last_set_entity == e) + assert(last_set_entity == 0) assert(evo.has(e, f1) and evo.has(e, f2) and evo.has(e, f3)) assert(evo.get(e, f1) == nil and evo.get(e, f2) == nil and evo.get(e, f3) == 43) @@ -1610,7 +1610,7 @@ do last_assign_entity = 0 evo.set(e, f1) - assert(last_assign_entity == e) + assert(last_assign_entity == 0) assert(evo.has(e, f1) and not evo.has(e, f2)) assert(evo.get(e, f1) == nil and evo.get(e, f2) == nil) end @@ -1623,7 +1623,7 @@ do last_assign_entity = 0 evo.set(e, f2, 44) - assert(last_assign_entity == e) + assert(last_assign_entity == 0) assert(evo.has(e, f1) and evo.has(e, f2)) assert(evo.get(e, f1) == nil and evo.get(e, f2) == nil) end diff --git a/evolved.lua b/evolved.lua index b8c112b..d325cb8 100644 --- a/evolved.lua +++ b/evolved.lua @@ -417,7 +417,7 @@ local function __release_id(id) local freelist_ids = __freelist_ids if freelist_ids[acquired_primary] ~= id then - __error_fmt('id is not acquired or already released') + __error_fmt('the id (%d) is not acquired or already released', id) end shifted_secondary = shifted_secondary == 2 ^ 40 - 2 ^ 20 @@ -3102,17 +3102,7 @@ function __chunk_set(old_chunk, fragment, component) end end else - for old_place = 1, old_entity_count do - local entity = old_entity_list[old_place] - - if fragment_on_set then - __defer_call_hook(fragment_on_set, entity, fragment) - end - - if fragment_on_assign then - __defer_call_hook(fragment_on_assign, entity, fragment) - end - end + -- nothing end else local old_component_index = old_component_indices[fragment] @@ -5116,13 +5106,7 @@ function __evolved_set(entity, fragment, component) __defer_call_hook(fragment_on_assign, entity, fragment, new_component, old_component) end else - if fragment_on_set then - __defer_call_hook(fragment_on_set, entity, fragment) - end - - if fragment_on_assign then - __defer_call_hook(fragment_on_assign, entity, fragment) - end + -- nothing end else local req_fragment_set