From 9245b35c1f01c2a23f0382004ec0f69b94e81d3d Mon Sep 17 00:00:00 2001 From: MakhamDev Date: Sat, 28 Oct 2023 09:07:43 +0700 Subject: [PATCH] Cache, group IO ordering fix --- PixelComposer.resource_order | 2 +- PixelComposer.yyp | 2 +- scripts/array_functions/array_functions.gml | 4 +- .../node_VFX_renderer_output.gml | 5 +-- .../node_array_length/node_array_length.gml | 13 +++--- scripts/node_array_zip/node_array_zip.gml | 40 ++++++++++--------- scripts/node_cache/node_cache.gml | 22 +++++----- scripts/node_collection/node_collection.gml | 9 +++-- scripts/node_data/node_data.gml | 10 +++-- .../node_dynamic_surface_in.gml | 5 +-- .../node_fluid_render_output.gml | 5 +-- scripts/node_group_input/node_group_input.gml | 7 +--- .../node_group_output/node_group_output.gml | 11 +++-- .../node_path_sample.gml} | 5 ++- .../node_path_sample.yy} | 2 +- .../node_rigid_render_output.gml | 5 +-- scripts/node_value/node_value.gml | 6 +-- 17 files changed, 74 insertions(+), 79 deletions(-) rename scripts/{node_path_eval/node_path_eval.gml => node_path_sample/node_path_sample.gml} (92%) rename scripts/{node_path_eval/node_path_eval.yy => node_path_sample/node_path_sample.yy} (86%) diff --git a/PixelComposer.resource_order b/PixelComposer.resource_order index 26d5dc4c8..5e20127a2 100644 --- a/PixelComposer.resource_order +++ b/PixelComposer.resource_order @@ -1342,7 +1342,7 @@ {"name":"node_counter","order":1,"path":"scripts/node_counter/node_counter.yy",}, {"name":"s_node_shape_polygon","order":25,"path":"sprites/s_node_shape_polygon/s_node_shape_polygon.yy",}, {"name":"s_node_pb_fx_interesct","order":6,"path":"sprites/s_node_pb_fx_interesct/s_node_pb_fx_interesct.yy",}, - {"name":"node_path_eval","order":4,"path":"scripts/node_path_eval/node_path_eval.yy",}, + {"name":"node_path_sample","order":4,"path":"scripts/node_path_sample/node_path_sample.yy",}, {"name":"sh_3d_depth","order":6,"path":"shaders/sh_3d_depth/sh_3d_depth.yy",}, {"name":"__node_3d_displace","order":1,"path":"scripts/__node_3d_displace/__node_3d_displace.yy",}, {"name":"node_vector_dot","order":9,"path":"scripts/node_vector_dot/node_vector_dot.yy",}, diff --git a/PixelComposer.yyp b/PixelComposer.yyp index 3c0e14d83..397f22b43 100644 --- a/PixelComposer.yyp +++ b/PixelComposer.yyp @@ -2054,7 +2054,7 @@ {"id":{"name":"s_node_shape_polygon","path":"sprites/s_node_shape_polygon/s_node_shape_polygon.yy",},}, {"id":{"name":"sh_color_picker_hue","path":"shaders/sh_color_picker_hue/sh_color_picker_hue.yy",},}, {"id":{"name":"s_node_pb_fx_interesct","path":"sprites/s_node_pb_fx_interesct/s_node_pb_fx_interesct.yy",},}, - {"id":{"name":"node_path_eval","path":"scripts/node_path_eval/node_path_eval.yy",},}, + {"id":{"name":"node_path_sample","path":"scripts/node_path_sample/node_path_sample.yy",},}, {"id":{"name":"sh_3d_depth","path":"shaders/sh_3d_depth/sh_3d_depth.yy",},}, {"id":{"name":"__node_3d_displace","path":"scripts/__node_3d_displace/__node_3d_displace.yy",},}, {"id":{"name":"node_vector_dot","path":"scripts/node_vector_dot/node_vector_dot.yy",},}, diff --git a/scripts/array_functions/array_functions.gml b/scripts/array_functions/array_functions.gml index 5d332c595..405b22e01 100644 --- a/scripts/array_functions/array_functions.gml +++ b/scripts/array_functions/array_functions.gml @@ -219,7 +219,7 @@ function array_shape(arr, first = true, isSurface = false) { return (first? "" : " x ") + dim; } -function array_depth(arr) { +function array_get_depth(arr) { gml_pragma("forceinline"); if(!is_array(arr)) return 0; @@ -237,7 +237,7 @@ function array_depth(arr) { function array_spread(arr, _arr = [], _minDepth = 0) { gml_pragma("forceinline"); - if(array_depth(arr) == _minDepth) { + if(array_get_depth(arr) == _minDepth) { array_push(_arr, arr); return _arr; } diff --git a/scripts/node_VFX_renderer_output/node_VFX_renderer_output.gml b/scripts/node_VFX_renderer_output/node_VFX_renderer_output.gml index 9f8d0af1f..ce97f2b93 100644 --- a/scripts/node_VFX_renderer_output/node_VFX_renderer_output.gml +++ b/scripts/node_VFX_renderer_output/node_VFX_renderer_output.gml @@ -35,12 +35,9 @@ function Node_VFX_Renderer_Output(_x, _y, _group = noone) : Node_Group_Output(_x .setVisible(true, true); } if(!LOADING && !APPENDING) createNewInput(); #endregion - static createOutput = function(override_order = true) { #region + static createOutput = function() { #region if(group == noone) return; if(!is_struct(group)) return; - - if(override_order) - attributes.input_priority = ds_list_size(group.outputs); if(!is_undefined(outParent)) ds_list_remove(group.outputs, outParent); diff --git a/scripts/node_array_length/node_array_length.gml b/scripts/node_array_length/node_array_length.gml index 4c7270d8d..e3513867a 100644 --- a/scripts/node_array_length/node_array_length.gml +++ b/scripts/node_array_length/node_array_length.gml @@ -11,9 +11,12 @@ function Node_Array_Length(_x, _y, _group = noone) : Node(_x, _y, _group) constr outputs[| 0] = nodeValue("Size", self, JUNCTION_CONNECT.output, VALUE_TYPE.integer, 0); - static update = function(frame = CURRENT_FRAME) { - var _arr = getInputData(0); + static step = function() { #region inputs[| 0].setType(inputs[| 0].isLeaf()? VALUE_TYPE.any : inputs[| 0].value_from.type); + } #endregion + + static update = function(frame = CURRENT_FRAME) { #region + var _arr = getInputData(0); if(!is_array(_arr) || array_length(_arr) == 0) { outputs[| 0].setValue(0); @@ -21,14 +24,14 @@ function Node_Array_Length(_x, _y, _group = noone) : Node(_x, _y, _group) constr } outputs[| 0].setValue(array_length(_arr)); - } + } #endregion - static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { + static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text); var str = string(outputs[| 0].getValue()); var bbox = drawGetBbox(xx, yy, _s); var ss = string_scale(str, bbox.w, bbox.h); draw_text_transformed(bbox.xc, bbox.yc, str, ss, ss, 0); - } + } #endregion } \ No newline at end of file diff --git a/scripts/node_array_zip/node_array_zip.gml b/scripts/node_array_zip/node_array_zip.gml index 3b4026ff5..928340328 100644 --- a/scripts/node_array_zip/node_array_zip.gml +++ b/scripts/node_array_zip/node_array_zip.gml @@ -13,17 +13,16 @@ function Node_Array_Zip(_x, _y, _group = noone) : Node(_x, _y, _group) construct setIsDynamicInput(1); - static createNewInput = function() { + static createNewInput = function() { #region var index = ds_list_size(inputs); inputs[| index] = nodeValue("Value", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, -1 ) .setVisible(true, true); return inputs[| index]; - } - if(!LOADING && !APPENDING) createNewInput(); + } if(!LOADING && !APPENDING) createNewInput(); #endregion - static refreshDynamicInput = function() { + static refreshDynamicInput = function() { #region var _l = ds_list_create(); for( var i = 0; i < ds_list_size(inputs); i++ ) { @@ -40,33 +39,36 @@ function Node_Array_Zip(_x, _y, _group = noone) : Node(_x, _y, _group) construct inputs = _l; createNewInput(); - } + } #endregion - static onValueFromUpdate = function(index) { + static onValueFromUpdate = function(index) { #region if(LOADING || APPENDING) return; refreshDynamicInput(); - } + } #endregion - static update = function(frame = CURRENT_FRAME) { - var _arr = getInputData(0); - + static step = function() { #region if(inputs[| 0].isLeaf()) { inputs[| 0].setType(VALUE_TYPE.any); outputs[| 0].setType(VALUE_TYPE.any); - return; + } else { + inputs[| 0].setType(inputs[| 0].value_from.type); + outputs[| 0].setType(inputs[| 0].value_from.type); } - if(!is_array(_arr)) return; - var _type = inputs[| 0].value_from.type; - inputs[| 0].setType(_type); - outputs[| 0].setType(_type); + for( var i = 0; i < ds_list_size(inputs) - 1; i += data_length ) + inputs[| i].setType(inputs[| i].isLeaf()? VALUE_TYPE.any : inputs[| i].value_from.type); + } #endregion + + static update = function(frame = CURRENT_FRAME) { #region + var _arr = getInputData(0); + if(!is_array(_arr)) return; var len = 1; var val = []; for( var i = 0; i < ds_list_size(inputs) - 1; i += data_length ) { val[i] = getInputData(i); - inputs[| i].setType(inputs[| i].isLeaf()? inputs[| i].value_from.type : VALUE_TYPE.any); + if(!is_array(val[i])) { val[i] = [ val[i] ]; continue; @@ -82,10 +84,10 @@ function Node_Array_Zip(_x, _y, _group = noone) : Node(_x, _y, _group) construct } outputs[| 0].setValue(_out); - } + } #endregion - static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { + static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region var bbox = drawGetBbox(xx, yy, _s); draw_sprite_fit(s_node_array_zip, 0, bbox.xc, bbox.yc, bbox.w, bbox.h); - } + } #endregion } \ No newline at end of file diff --git a/scripts/node_cache/node_cache.gml b/scripts/node_cache/node_cache.gml index 388760876..32650fd99 100644 --- a/scripts/node_cache/node_cache.gml +++ b/scripts/node_cache/node_cache.gml @@ -18,9 +18,9 @@ function Node_Cache(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { insp2UpdateTooltip = "Clear cache"; insp2UpdateIcon = [ THEME.cache, 0, COLORS._main_icon ]; - static onInspector2Update = function() { clearCache(); } + static onInspector2Update = function() { clearCache(true); } - static step = function() { + static step = function() { #region if(cache_loading) { cached_output[cache_loading_progress] = __surface_array_deserialize(cache_content[cache_loading_progress]); cache_result[cache_loading_progress] = true; @@ -31,29 +31,29 @@ function Node_Cache(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { update(); } } - } + } #endregion - static update = function() { + static update = function() { #region if(recoverCache()) return; if(!inputs[| 0].value_from) return; var _surf = getInputData(0); cacheCurrentFrame(_surf); - } + } #endregion - static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { + static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region 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); - } + } #endregion - static doSerialize = function(_map) { + static doSerialize = function(_map) { #region _map.cache = surface_array_serialize(cached_output); - } + } #endregion - static postDeserialize = function() { + static postDeserialize = function() { #region if(!struct_has(load_map, "cache")) return; cache_content = json_try_parse(load_map.cache); cache_loading_progress = 0; cache_loading = true; - } + } #endregion } \ No newline at end of file diff --git a/scripts/node_collection/node_collection.gml b/scripts/node_collection/node_collection.gml index f4cb7c103..b7ec35ec5 100644 --- a/scripts/node_collection/node_collection.gml +++ b/scripts/node_collection/node_collection.gml @@ -396,15 +396,16 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc var _or = 0; var _ors = []; - for( var i = custom_input_index; i < ds_list_size(list); i++ ) { - var _in = list[| i]; - array_push(_ors, _in.from.attributes.input_priority); + for( var i = 0, n = ds_list_size(nodes); i < n; i++ ) { + var _n = nodes[| i]; + if(!struct_has(_n.attributes, "input_priority")) continue; + + array_push(_ors, _n.attributes.input_priority); } array_sort(_ors, true); for( var i = 0, n = array_length(_ors); i < n; i++ ) if(_or == _ors[i]) _or++; - return _or; } #endregion diff --git a/scripts/node_data/node_data.gml b/scripts/node_data/node_data.gml index 3c3c34023..a3cadd4a8 100644 --- a/scripts/node_data/node_data.gml +++ b/scripts/node_data/node_data.gml @@ -1356,12 +1356,14 @@ function Node(_x, _y, _group = PANEL_GRAPH.getCurrentContext()) : __Node_Base(_x return true; } #endregion - static clearCache = function() { #region + static clearCache = function(_force = false) { #region clearInputCache(); - if(!clearCacheOnChange) return; - if(!use_cache) return; - if(!isRenderActive()) return; + if(!_force) { + if(!use_cache) return; + if(!clearCacheOnChange) return; + if(!isRenderActive()) return; + } if(array_length(cached_output) != TOTAL_FRAMES) array_resize(cached_output, TOTAL_FRAMES); diff --git a/scripts/node_dynamic_surface_in/node_dynamic_surface_in.gml b/scripts/node_dynamic_surface_in/node_dynamic_surface_in.gml index 13c33f572..380731885 100644 --- a/scripts/node_dynamic_surface_in/node_dynamic_surface_in.gml +++ b/scripts/node_dynamic_surface_in/node_dynamic_surface_in.gml @@ -12,12 +12,9 @@ function Node_DynaSurf_In(_x, _y, _group = noone) : Node(_x, _y, _group) constru outputs[| 0] = nodeValue("Value", self, JUNCTION_CONNECT.output, VALUE_TYPE.PCXnode, noone); - static createInput = function(override_order = true) { #region + static createInput = function() { #region if(group == noone || !is_struct(group)) return noone; - if(override_order) - attributes.input_priority = ds_list_size(group.inputs); - if(!is_undefined(inParent)) ds_list_remove(group.inputs, inParent); diff --git a/scripts/node_fluid_render_output/node_fluid_render_output.gml b/scripts/node_fluid_render_output/node_fluid_render_output.gml index 5735474e7..18b3e8858 100644 --- a/scripts/node_fluid_render_output/node_fluid_render_output.gml +++ b/scripts/node_fluid_render_output/node_fluid_render_output.gml @@ -35,12 +35,9 @@ function Node_Fluid_Render_Output(_x, _y, _group = noone) : Node_Group_Output(_x static onInspector2Update = function() { clearCache(); } - static createOutput = function(override_order = true) { #region + static createOutput = function() { #region if(group == noone) return; if(!is_struct(group)) return; - - if(override_order) - attributes.input_priority = ds_list_size(group.outputs); if(!is_undefined(outParent)) ds_list_remove(group.outputs, outParent); diff --git a/scripts/node_group_input/node_group_input.gml b/scripts/node_group_input/node_group_input.gml index 9d5e6d29f..7ad61c7a5 100644 --- a/scripts/node_group_input/node_group_input.gml +++ b/scripts/node_group_input/node_group_input.gml @@ -254,12 +254,9 @@ function Node_Group_Input(_x, _y, _group = noone) : Node(_x, _y, _group) constru } } #endregion - static createInput = function(override_order = true) { #region + static createInput = function() { #region if(group == noone || !is_struct(group)) return noone; - - if(override_order) - attributes.input_priority = ds_list_size(group.inputs); - + if(!is_undefined(inParent)) ds_list_remove(group.inputs, inParent); diff --git a/scripts/node_group_output/node_group_output.gml b/scripts/node_group_output/node_group_output.gml index c27b8d30f..eea40e82a 100644 --- a/scripts/node_group_output/node_group_output.gml +++ b/scripts/node_group_output/node_group_output.gml @@ -65,13 +65,10 @@ function Node_Group_Output(_x, _y, _group = noone) : Node(_x, _y, _group) constr return nodes; } #endregion - static createOutput = function(override_order = true) { #region + static createOutput = function() { #region if(group == noone) return; if(!is_struct(group)) return; - if(override_order) - attributes.input_priority = ds_list_size(group.outputs); - if(!is_undefined(outParent)) ds_list_remove(group.outputs, outParent); @@ -142,4 +139,10 @@ function Node_Group_Output(_x, _y, _group = noone) : Node(_x, _y, _group) constr static onLoadGroup = function() { #region if(group == noone) nodeDelete(self); } #endregion + + //static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region + // var bbox = drawGetBbox(xx, yy, _s); + // draw_set_text(f_h5, fa_center, fa_center, c_white); + // draw_text(bbox.xc, bbox.yc, attributes.input_priority); + //} #endregion } \ No newline at end of file diff --git a/scripts/node_path_eval/node_path_eval.gml b/scripts/node_path_sample/node_path_sample.gml similarity index 92% rename from scripts/node_path_eval/node_path_eval.gml rename to scripts/node_path_sample/node_path_sample.gml index 0cc5f9341..ea94856e6 100644 --- a/scripts/node_path_eval/node_path_eval.gml +++ b/scripts/node_path_sample/node_path_sample.gml @@ -22,8 +22,9 @@ function Node_Path_Sample(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou var _rat = _data[1]; var _mod = _data[2]; - if(_path == noone) return [ 0, 0 ]; - if(!struct_has(_path, "getPointRatio")) return [ 0, 0 ]; + if(_path == noone) return [ 0, 0 ]; + if(!struct_has(_path, "getPointRatio")) return [ 0, 0 ]; + if(!is_real(_rat)) return [ 0, 0 ]; var inv = false; switch(_mod) { diff --git a/scripts/node_path_eval/node_path_eval.yy b/scripts/node_path_sample/node_path_sample.yy similarity index 86% rename from scripts/node_path_eval/node_path_eval.yy rename to scripts/node_path_sample/node_path_sample.yy index 438d72b48..cd53b5a28 100644 --- a/scripts/node_path_eval/node_path_eval.yy +++ b/scripts/node_path_sample/node_path_sample.yy @@ -1,7 +1,7 @@ { "resourceType": "GMScript", "resourceVersion": "1.0", - "name": "node_path_eval", + "name": "node_path_sample", "isCompatibility": false, "isDnD": false, "parent": { diff --git a/scripts/node_rigid_render_output/node_rigid_render_output.gml b/scripts/node_rigid_render_output/node_rigid_render_output.gml index 63a6c2139..200eb3323 100644 --- a/scripts/node_rigid_render_output/node_rigid_render_output.gml +++ b/scripts/node_rigid_render_output/node_rigid_render_output.gml @@ -37,12 +37,9 @@ function Node_Rigid_Render_Output(_x, _y, _group = noone) : Node_Group_Output(_x .setVisible(true, true); } if(!LOADING && !APPENDING) createNewInput(); #endregion - static createOutput = function(override_order = true) { #region + static createOutput = function() { #region if(group == noone) return; if(!is_struct(group)) return; - - if(override_order) - attributes.input_priority = ds_list_size(group.outputs); if(!is_undefined(outParent)) ds_list_remove(group.outputs, outParent); diff --git a/scripts/node_value/node_value.gml b/scripts/node_value/node_value.gml index 4b90490f3..17bbe0b35 100644 --- a/scripts/node_value/node_value.gml +++ b/scripts/node_value/node_value.gml @@ -1618,8 +1618,7 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru static isArray = function(val = undefined) { #region if(val == undefined) { - if(cache_array[0]) - return cache_array[1]; + if(cache_array[0]) return cache_array[1]; val = getValue(); } @@ -1650,8 +1649,7 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru } #endregion static arrayLength = function(val = undefined) { #region - if(val == undefined) - val = getValue(); + if(val == undefined) val = getValue(); if(!isArray(val)) return -1;