From 5525bf959f985e7a9592e9592a45a81a0bb8f8c6 Mon Sep 17 00:00:00 2001 From: Juju Adams Date: Sun, 20 Oct 2024 10:49:32 +0100 Subject: [PATCH] Fixes scribble_refresh_everything() not refreshing long-term cached text elements --- .../__scribble_class_element.gml | 2 ++ scripts/__scribble_system/__scribble_system.gml | 1 + scripts/__scribble_tick/__scribble_tick.gml | 11 +++++++++++ .../scribble_refresh_everything.gml | 15 ++++++++++++--- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/scripts/__scribble_class_element/__scribble_class_element.gml b/scripts/__scribble_class_element/__scribble_class_element.gml index 91ed9313..7b1fcc16 100644 --- a/scripts/__scribble_class_element/__scribble_class_element.gml +++ b/scripts/__scribble_class_element/__scribble_class_element.gml @@ -7,6 +7,7 @@ function __scribble_class_element(_string, _unique_id) constructor static __scribble_state = __scribble_initialize().__state; static __ecache_array = __scribble_initialize().__cache_state.__ecache_array; static __ecache_dict = __scribble_initialize().__cache_state.__ecache_dict; + static __ecache_weak_array = __scribble_initialize().__cache_state.__ecache_weak_array; static __ecache_name_array = __scribble_initialize().__cache_state.__ecache_name_array; __text = _string; @@ -26,6 +27,7 @@ function __scribble_class_element(_string, _unique_id) constructor //Add this text element to the global cache __ecache_dict[$ __cache_name] = weak_ref_create(self); array_push(__ecache_array, self); + array_push(__ecache_weak_array, weak_ref_create(self)); array_push(__ecache_name_array, __cache_name); __flushed = false; diff --git a/scripts/__scribble_system/__scribble_system.gml b/scripts/__scribble_system/__scribble_system.gml index 878d3e8a..b2d0d994 100644 --- a/scripts/__scribble_system/__scribble_system.gml +++ b/scripts/__scribble_system/__scribble_system.gml @@ -99,6 +99,7 @@ function __scribble_initialize() __ecache_dict: {}, __ecache_array: [], + __ecache_weak_array: [], __ecache_name_array: [], __gc_vbuff_refs: [], diff --git a/scripts/__scribble_tick/__scribble_tick.gml b/scripts/__scribble_tick/__scribble_tick.gml index e4709338..f931a878 100644 --- a/scripts/__scribble_tick/__scribble_tick.gml +++ b/scripts/__scribble_tick/__scribble_tick.gml @@ -5,9 +5,11 @@ function __scribble_tick() static _cache_state = __scribble_initialize().__cache_state; static _ecache_list_index = 0; + static _ecache_weak_index = 0; static _ecache_name_index = 0; static _ecache_array = _cache_state.__ecache_array; static _ecache_dict = _cache_state.__ecache_dict; + static _ecache_weak_array = _cache_state.__ecache_weak_array; static _ecache_name_array = _cache_state.__ecache_name_array; static _mcache_name_index = 0; @@ -73,6 +75,15 @@ function __scribble_tick() } } + if (array_length(_ecache_weak_array) > 0) + { + _ecache_weak_index = (_ecache_weak_index + 1) mod array_length(_ecache_weak_array); + if (not weak_ref_alive(_ecache_weak_array[_ecache_weak_index])) + { + array_delete(_ecache_weak_array, _ecache_weak_index, 1); + } + } + #endregion diff --git a/scripts/scribble_refresh_everything/scribble_refresh_everything.gml b/scripts/scribble_refresh_everything/scribble_refresh_everything.gml index 19b7c13e..9995b8d7 100644 --- a/scripts/scribble_refresh_everything/scribble_refresh_everything.gml +++ b/scripts/scribble_refresh_everything/scribble_refresh_everything.gml @@ -5,11 +5,20 @@ function scribble_refresh_everything() with(__scribble_initialize().__cache_state) { + var _array = __ecache_weak_array; var _i = 0; - repeat(array_length(__ecache_array)) + repeat(array_length(_array)) { - __ecache_array[_i].refresh(); - ++_i; + var _weak_ref = _array[_i]; + if (weak_ref_alive(_weak_ref)) + { + _weak_ref.ref.refresh(); + ++_i; + } + else + { + array_delete(_array, _i, 1); + } } } }