Pixel-Composer/scripts/node_cache/node_cache.gml

70 lines
1.9 KiB
Plaintext
Raw Normal View History

2023-11-02 12:43:00 +01:00
function Node_Cache(_x, _y, _group = noone) : __Node_Cache(_x, _y, _group) constructor {
2023-11-02 14:37:13 +01:00
name = "Cache";
use_cache = CACHE_USE.auto;
2023-03-02 07:59:14 +01:00
2024-03-14 14:35:19 +01:00
inputs[| 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone);
2023-03-02 07:59:14 +01:00
2024-03-14 14:35:19 +01:00
outputs[| 0] = nodeValue("Cache surface", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
2023-03-02 07:59:14 +01:00
input_display_list = [
["Surfaces", true], 0,
2023-03-02 07:59:14 +01:00
];
cache_loading = false;
cache_content = "";
cache_loading_progress = 0;
2023-03-08 07:35:51 +01:00
insp2UpdateTooltip = "Clear cache";
insp2UpdateIcon = [ THEME.cache, 0, COLORS._main_icon ];
static onInspector2Update = function() {
clearCache(true);
enableNodeGroup();
}
2023-03-08 07:35:51 +01:00
2023-10-28 04:07:43 +02:00
static step = function() { #region
2023-03-02 07:59:14 +01:00
if(cache_loading) {
2023-07-17 19:58:33 +02:00
cached_output[cache_loading_progress] = __surface_array_deserialize(cache_content[cache_loading_progress]);
cache_result[cache_loading_progress] = true;
2023-03-02 07:59:14 +01:00
cache_loading_progress++;
2023-10-09 16:07:33 +02:00
if(cache_loading_progress == TOTAL_FRAMES) {
2023-03-02 07:59:14 +01:00
cache_loading = false;
update();
}
}
2023-10-28 04:07:43 +02:00
} #endregion
2023-03-02 07:59:14 +01:00
2023-10-28 04:07:43 +02:00
static update = function() { #region
2024-04-30 10:49:12 +02:00
if(recoverCache() || cache_loading) return;
2023-12-22 14:46:54 +01:00
2023-03-02 07:59:14 +01:00
if(!inputs[| 0].value_from) return;
2023-12-22 14:46:54 +01:00
if(!inputs[| 0].value_from.node.renderActive) {
enableNodeGroup();
return;
}
2023-03-02 07:59:14 +01:00
var _surf = getInputData(0);
2023-03-02 07:59:14 +01:00
cacheCurrentFrame(_surf);
2023-11-02 14:37:13 +01:00
disableNodeGroup();
2023-10-28 04:07:43 +02:00
} #endregion
2023-03-02 07:59:14 +01:00
2023-10-28 04:07:43 +02:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region
2023-03-02 07:59:14 +01:00
if(cache_loading)
draw_sprite_ui(THEME.loading, 0, xx + w * _s / 2, yy + h * _s / 2, _s, _s, current_time / 2, COLORS._main_icon, 1);
2023-10-28 04:07:43 +02:00
} #endregion
2023-03-02 07:59:14 +01:00
2023-10-28 04:07:43 +02:00
static doSerialize = function(_map) { #region
2023-07-17 19:58:33 +02:00
_map.cache = surface_array_serialize(cached_output);
2023-10-28 04:07:43 +02:00
} #endregion
2023-03-02 07:59:14 +01:00
2023-10-28 04:07:43 +02:00
static postDeserialize = function() { #region
2023-11-05 04:19:19 +01:00
refreshCacheGroup();
2023-06-13 14:42:06 +02:00
if(!struct_has(load_map, "cache")) return;
2023-07-17 19:58:33 +02:00
cache_content = json_try_parse(load_map.cache);
2023-06-13 14:42:06 +02:00
cache_loading_progress = 0;
2023-03-02 07:59:14 +01:00
cache_loading = true;
2023-10-28 04:07:43 +02:00
} #endregion
2023-03-02 07:59:14 +01:00
}