Skip to content

Commit

Permalink
Fixes scribble_refresh_everything() not refreshing long-term cached t…
Browse files Browse the repository at this point in the history
…ext elements
  • Loading branch information
JujuAdams committed Oct 20, 2024
1 parent 797b71b commit 5525bf9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions scripts/__scribble_class_element/__scribble_class_element.gml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions scripts/__scribble_system/__scribble_system.gml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ function __scribble_initialize()

__ecache_dict: {},
__ecache_array: [],
__ecache_weak_array: [],
__ecache_name_array: [],

__gc_vbuff_refs: [],
Expand Down
11 changes: 11 additions & 0 deletions scripts/__scribble_tick/__scribble_tick.gml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}

0 comments on commit 5525bf9

Please sign in to comment.