2023-11-02 12:43:00 +01:00
|
|
|
function Node_Cache_Array(_x, _y, _group = noone) : __Node_Cache(_x, _y, _group) constructor {
|
2023-11-02 14:37:13 +01:00
|
|
|
name = "Cache Array";
|
|
|
|
use_cache = CACHE_USE.manual;
|
2023-02-19 13:49:20 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(0, nodeValue_Surface("Surface in", self));
|
2023-02-19 13:49:20 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(1, nodeValue_Int("Start frame", self, -1, "Frame index to start caching, set to -1 to start at the first frame."));
|
2023-03-07 14:29:47 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(2, nodeValue_Int("Stop frame", self, -1, "Frame index to stop caching (inclusive), set to -1 to stop at the last frame."));
|
2023-03-07 14:29:47 +01:00
|
|
|
|
2024-08-18 06:16:20 +02:00
|
|
|
newInput(3, nodeValue_Int("Step", self, 1, "Cache every N frames, set to 1 to cache every frame."));
|
2023-03-07 14:29:47 +01:00
|
|
|
|
2024-09-04 03:57:11 +02:00
|
|
|
newOutput(0, nodeValue_Output("Cache array", self, VALUE_TYPE.surface, []));
|
2023-02-19 13:49:20 +01:00
|
|
|
|
|
|
|
input_display_list = [
|
2023-11-08 14:37:51 +01:00
|
|
|
["Surfaces", true], 0,
|
|
|
|
["Range", false], 1, 2, 3,
|
2023-02-19 13:49:20 +01:00
|
|
|
];
|
|
|
|
|
2023-03-02 07:59:14 +01:00
|
|
|
cache_loading = false;
|
|
|
|
cache_content = "";
|
2023-11-02 14:37:13 +01:00
|
|
|
cache_loading_progress = 0;
|
2023-03-02 07:59:14 +01:00
|
|
|
|
2024-11-26 05:52:57 +01:00
|
|
|
setTrigger(2, "Clear cache", [ THEME.cache, 0, COLORS._main_icon ], function() /*=>*/ { clearCache(); enableNodeGroup(); });
|
2023-03-08 07:35:51 +01:00
|
|
|
|
2024-08-30 11:08:30 +02:00
|
|
|
static step = function() {
|
2023-07-30 13:56:22 +02:00
|
|
|
if(!cache_loading) return;
|
|
|
|
|
|
|
|
var _content = cache_content[cache_loading_progress];
|
2023-07-23 20:21:35 +02:00
|
|
|
|
2023-07-30 13:56:22 +02:00
|
|
|
cached_output[cache_loading_progress] = __surface_array_deserialize(_content);
|
|
|
|
cache_result[cache_loading_progress] = true;
|
|
|
|
cache_loading_progress++;
|
2023-03-02 07:59:14 +01:00
|
|
|
|
2023-07-30 13:56:22 +02:00
|
|
|
if(cache_loading_progress == array_length(cache_content)) {
|
|
|
|
cache_loading = false;
|
|
|
|
update();
|
2023-03-02 07:59:14 +01:00
|
|
|
}
|
2024-08-30 11:08:30 +02:00
|
|
|
}
|
2023-03-02 07:59:14 +01:00
|
|
|
|
2024-08-30 11:08:30 +02:00
|
|
|
static update = function() {
|
2024-04-30 10:49:12 +02:00
|
|
|
if(cache_loading) return;
|
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
if(!inputs[0].value_from) return;
|
|
|
|
if(!inputs[0].value_from.node.renderActive) {
|
2023-12-22 14:46:54 +01:00
|
|
|
if(!cacheExist(CURRENT_FRAME))
|
|
|
|
enableNodeGroup();
|
|
|
|
return;
|
|
|
|
}
|
2023-11-07 06:01:38 +01:00
|
|
|
|
2023-03-07 14:29:47 +01:00
|
|
|
var ss = [];
|
2023-10-02 08:57:44 +02:00
|
|
|
var str = getInputData(1);
|
|
|
|
var lst = getInputData(2);
|
|
|
|
var stp = getInputData(3);
|
2023-03-07 14:29:47 +01:00
|
|
|
|
2023-07-21 12:40:20 +02:00
|
|
|
if(str < 0) str = 1;
|
2023-10-09 16:07:33 +02:00
|
|
|
if(lst < 0) lst = TOTAL_FRAMES;
|
2023-07-21 12:40:20 +02:00
|
|
|
|
|
|
|
str -= 1;
|
|
|
|
lst -= 1;
|
2023-03-07 14:29:47 +01:00
|
|
|
|
2023-10-09 16:07:33 +02:00
|
|
|
if(CURRENT_FRAME < str) return;
|
|
|
|
if(CURRENT_FRAME > lst) return;
|
2023-07-17 19:58:33 +02:00
|
|
|
|
2023-11-01 08:10:25 +01:00
|
|
|
cacheCurrentFrame(getInputData(0));
|
2023-03-02 07:59:14 +01:00
|
|
|
|
2023-11-01 08:10:25 +01:00
|
|
|
if(lst > str && stp > 0)
|
|
|
|
for( var i = str; i <= lst; i += stp )
|
|
|
|
if(cacheExist(i)) array_push(ss, cached_output[i]);
|
2023-02-19 13:49:20 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
outputs[0].setValue(ss);
|
2023-11-02 14:37:13 +01:00
|
|
|
|
|
|
|
disableNodeGroup();
|
2024-08-30 11:08:30 +02:00
|
|
|
}
|
2023-03-02 07:59:14 +01:00
|
|
|
|
2024-08-30 11:08:30 +02:00
|
|
|
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
|
2023-11-01 08:10:25 +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);
|
2024-08-30 11:08:30 +02:00
|
|
|
}
|
2023-03-02 07:59:14 +01:00
|
|
|
|
2024-08-30 11:08:30 +02:00
|
|
|
static doSerialize = function(_map) {
|
2023-07-17 19:58:33 +02:00
|
|
|
_map.cache = surface_array_serialize(cached_output);
|
2024-08-30 11:08:30 +02:00
|
|
|
}
|
2023-03-02 07:59:14 +01:00
|
|
|
|
2024-08-30 11:08:30 +02:00
|
|
|
static postDeserialize = function() {
|
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-03-02 07:59:14 +01:00
|
|
|
cache_loading_progress = 0;
|
|
|
|
cache_loading = true;
|
2024-08-30 11:08:30 +02:00
|
|
|
}
|
2023-02-19 13:49:20 +01:00
|
|
|
}
|