Fix array sort group.

This commit is contained in:
MakhamDev 2023-10-08 13:02:38 +07:00
parent 98d4a33982
commit ccc84a082b
9 changed files with 102 additions and 100 deletions

View file

@ -234,6 +234,8 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc
static setRenderStatus = function(result) { #region
LOG_BLOCK_START();
if(rendered == result) return;
LOG_IF(global.FLAG.render == 1, $"Set render status for {INAME} : {result}");
rendered = result;
@ -247,8 +249,7 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc
break;
}
if(rendered)
exitGroup();
if(rendered) exitGroup();
if(!result && group != noone)
group.setRenderStatus(result);
@ -485,18 +486,14 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc
node_list[| i].disable();
} #endregion
static resetRender = function() { #region
LOG_BLOCK_START();
LOG_IF(global.FLAG.render == 1, $"Reset Render for {INAME}");
for( var i = 0; i < ds_list_size(nodes); i++ ) {
LOG_IF(global.FLAG.render == 1, $"Reseting {nodes[| i].internalName}");
nodes[| i].resetRender();
}
static resetRender = function(_clearCache = false) { #region
LOG_LINE_IF(global.FLAG.render == 1, $"Reset Render for {INAME}");
setRenderStatus(false);
if(_clearCache) clearInputCache();
LOG_BLOCK_END();
for( var i = 0; i < ds_list_size(nodes); i++ )
nodes[| i].resetRender(_clearCache);
} #endregion
static setInstance = function(node) { #region

View file

@ -56,8 +56,10 @@ function Node_Compare(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
static update = function(frame = PROJECT.animator.current_frame) {
var mode = getInputData(0);
var a = getInputData(1);
var b = getInputData(2);
var a = getInputData(1);
var b = getInputData(2);
//print($"compare node | Comparing {mode}: {a}, {b}.");
var as = is_array(a);
var bs = is_array(b);

View file

@ -549,7 +549,11 @@ function Node(_x, _y, _group = PANEL_GRAPH.getCurrentContext()) : __Node_Base(_x
}
} #endregion
static resetRender = function() { setRenderStatus(false); }
static resetRender = function(_clearCache = false) { #region
setRenderStatus(false);
if(_clearCache) clearInputCache();
} #endregion
static isRenderActive = function() { return renderActive || (PREF_MAP[? "render_all_export"] && PROJECT.animator.rendering); }
static isRenderable = function(log = false) { #region //Check if every input is ready (updated)
@ -621,6 +625,7 @@ function Node(_x, _y, _group = PANEL_GRAPH.getCurrentContext()) : __Node_Base(_x
static setRenderStatus = function(result) { #region
gml_pragma("forceinline");
if(rendered == result) return;
LOG_LINE_IF(global.FLAG.render == 1, $"Set render status for {INAME} : {result}");
rendered = result;
@ -917,6 +922,8 @@ function Node(_x, _y, _group = PANEL_GRAPH.getCurrentContext()) : __Node_Base(_x
static getGraphPreviewSurface = function() { #region
var _node = outputs[| preview_channel];
if(!is_instanceof(_node, NodeValue)) return noone;
switch(_node.type) {
case VALUE_TYPE.surface :
case VALUE_TYPE.dynaSurface :

View file

@ -30,6 +30,7 @@ function Node_Group_Output(_x, _y, _group = noone) : Node(_x, _y, _group) constr
}
static setRenderStatus = function(result) {
if(rendered == result) return;
LOG_LINE_IF(global.FLAG.render == 1, $"Set render status for {INAME} : {result}");
rendered = result;

View file

@ -13,16 +13,16 @@ function Node_Iterate_Sort(_x, _y, _group = noone) : Node_Collection(_x, _y, _gr
topoList = ds_list_create();
custom_input_index = ds_list_size(inputs);
custom_input_index = ds_list_size(inputs);
custom_output_index = ds_list_size(inputs);
loop_start_time = 0;
ALWAYS_FULL = true;
loop_start_time = 0;
ALWAYS_FULL = true;
inputNodes = [];
inputNodes = [ noone, noone ];
outputNode = noone;
nodeValid = false;
if(!LOADING && !APPENDING && !CLONING) {
if(!LOADING && !APPENDING && !CLONING) { #region
var input0 = nodeBuild("Node_Iterator_Sort_Input", -256, -64, self);
input0.display_name = "Value 1";
@ -30,30 +30,68 @@ function Node_Iterate_Sort(_x, _y, _group = noone) : Node_Collection(_x, _y, _gr
input1.display_name = "Value 2";
var output = nodeBuild("Node_Iterator_Sort_Output", 256, -32, self);
}
} #endregion
static getNextNodes = function() {
return __nodeLeafList(getNodeList());
}
static getNextNodes = function() { return getNextNodesExternal(); }
static onStep = function() {
static onStep = function() { #region
var type = inputs[| 0].value_from == noone? VALUE_TYPE.any : inputs[| 0].value_from.type;
inputs[| 0].setType(type);
}
} #endregion
static update = function(frame = PROJECT.animator.current_frame) {
if(frame == 0) NodeListSort(topoList, nodes);
static update = function(frame = PROJECT.animator.current_frame) { #region
if(frame == 0) {
NodeListSort(topoList, nodes);
inputNodes = [ noone, noone ];
outputNode = noone;
var inputReady = 0;
initLoop();
}
for( var i = 0; i < ds_list_size(nodes); i++ ) {
if(nodes[| i].display_name == "Value 1") {
inputNodes[0] = nodes[| i].inputs[| 0];
inputNodes[0].setType(inputs[| 0].type);
inputReady++;
} else if(nodes[| i].display_name == "Value 2") {
inputNodes[1] = nodes[| i].inputs[| 0];
inputNodes[1].setType(inputs[| 0].type);
inputReady++;
} else if(nodes[| i].name == "Swap result") {
outputNode = nodes[| i].inputs[| 0];
inputReady++;
}
}
nodeValid = inputReady == 3;
if(!nodeValid) {
noti_warning("Sort: Missing inputs or output, need 2 inputs and 1 output for comparison.");
return;
}
}
if(nodeValid) sortArray();
} #endregion
static swap = function(arr, a, b) {
static swap = function(arr, a, b) { #region
var temp = arr[a];
arr[@ a] = arr[b];
arr[@ b] = temp;
}
} #endregion
static partition = function(arr, low, high) {
static compareValue = function(val1, val2) { #region
if(!nodeValid) return 0;
inputNodes[0].setValue(val1,,, false);
inputNodes[1].setValue(val2,,, false);
resetRender(true);
RenderList(topoList, false);
var res = outputNode.getValue();
LOG_IF(global.FLAG.render == 1, $"Iterating | Comparing {val1}, {val2} = {res}");
return res;
} #endregion
static partition = function(arr, low, high) { #region
var pv = arr[high];
var i = low - 1;
@ -66,63 +104,26 @@ function Node_Iterate_Sort(_x, _y, _group = noone) : Node_Collection(_x, _y, _gr
swap(arr, i + 1, high);
return i + 1;
}
} #endregion
static quickSort = function(arr, low, high) {
if(!nodeValid) return;
static quickSort = function(arr, low, high) { #region
if(low >= high) return;
var p = partition(arr, low, high);
quickSort(arr, low, p - 1);
quickSort(arr, p + 1, high);
}
} #endregion
static compareValue = function(val1, val2) {
if(!nodeValid) return 0;
inputNodes[0].setValue(val1);
inputNodes[1].setValue(val2);
RenderList(topoList);
var res = outputNode.getValue();
//print("Comparing " + string(val1) + ", " + string(val2) + ": " + string(res));
return res;
}
static initLoop = function() {
static sortArray = function() { #region
if(inputs[| 0].value_from) {
inputs[| 0].setType(inputs[| 0].value_from.type);
outputs[| 0].setType(inputs[| 0].value_from.type);
}
resetRender();
iterated = 0;
loop_start_time = get_timer();
inputNodes = [ 0, 0 ];
outputNode = noone;
var inputReady = 0;
for( var i = 0; i < ds_list_size(nodes); i++ ) {
if(nodes[| i].display_name == "Value 1") {
inputNodes[0] = nodes[| i].inputs[| 0];
inputNodes[0].setType(inputs[| 0].type);
inputReady++;
} else if(nodes[| i].display_name == "Value 2") {
inputNodes[1] = nodes[| i].inputs[| 0];
inputNodes[1].setType(inputs[| 0].type);
inputReady++;
} else if(nodes[| i].name == "Swap result") {
outputNode = nodes[| i].inputs[| 0];
inputReady++;
}
}
nodeValid = inputReady == 3;
if(!nodeValid) {
noti_warning("Sort: Missing inputs or output, need 2 inputs and 1 output for comparison.");
return;
}
var arrIn = getInputData(0);
var arrOut = outputs[| 0].getValue();
@ -134,7 +135,7 @@ function Node_Iterate_Sort(_x, _y, _group = noone) : Node_Collection(_x, _y, _gr
quickSort(arrOut, 0, array_length(arrOut) - 1);
outputs[| 0].setValue(arrOut);
}
} #endregion
PATCH_STATIC
}

View file

@ -7,13 +7,9 @@ function Node_Iterator_Sort_Output(_x, _y, _group = noone) : Node(_x, _y, _group
inputs[| 0] = nodeValue("Result", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false )
.setVisible(true, true);
static getNextNodes = function() {
return [];
}
static getNextNodes = function() { return []; }
static step = function() {}
static update = function(frame = PROJECT.animator.current_frame) {
//print(display_name + ": " + string(getInputData(0)));
}
static update = function(frame = PROJECT.animator.current_frame) {}
}

View file

@ -46,7 +46,7 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor { #regio
if(!_node) return noone;
_node.clearInputCache();
_node.doUpdate();
if(!LOADING && !APPENDING) _node.doUpdate();
return _node;
}
} #endregion
@ -429,13 +429,13 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor { #regio
addNodeObject(generator, "4 Points Gradient", s_node_gradient_4points, "Node_Gradient_Points", [1, Node_Gradient_Points],, "Create image from 4 color points.");
ds_list_add(generator, "Drawer");
addNodeObject(generator, "Line", s_node_line, "Node_Line", [1, Node_Line],, "Draw line on an image. Connect path data to it to draw line from path.");
addNodeObject(generator, "Draw Text", s_node_text_render, "Node_Text", [1, Node_Text],, "Draw text on an image.");
addNodeObject(generator, "Shape", s_node_shape, "Node_Shape", [1, Node_Shape],, "Draw simple shapes using signed distance field.");
addNodeObject(generator, "Polygon Shape", s_node_shape_polygon, "Node_Shape_Polygon", [1, Node_Shape_Polygon],, "Draw simple shapes using triangles.").setVersion(1130);
addNodeObject(generator, "Interpret Number",s_node_interpret_number,"Node_Interpret_Number",[1, Node_Interpret_Number]).setVersion(11530);
addNodeObject(generator, "Random Shape", s_node_random_shape, "Node_Random_Shape", [1, Node_Random_Shape]).setVersion(1147);
addNodeObject(generator, "Pixel Builder", s_node_pixel_builder, "Node_Pixel_Builder", [1, Node_Pixel_Builder]).setVersion(11540);
addNodeObject(generator, "Line", s_node_line, "Node_Line", [1, Node_Line],, "Draw line on an image. Connect path data to it to draw line from path.");
addNodeObject(generator, "Draw Text", s_node_text_render, "Node_Text", [1, Node_Text],, "Draw text on an image.");
addNodeObject(generator, "Shape", s_node_shape, "Node_Shape", [1, Node_Shape],, "Draw simple shapes using signed distance field.");
addNodeObject(generator, "Polygon Shape", s_node_shape_polygon, "Node_Shape_Polygon", [1, Node_Shape_Polygon],, "Draw simple shapes using triangles.").setVersion(1130);
addNodeObject(generator, "Interpret Number", s_node_interpret_number, "Node_Interpret_Number", [1, Node_Interpret_Number]).setVersion(11530);
addNodeObject(generator, "Random Shape", s_node_random_shape, "Node_Random_Shape", [1, Node_Random_Shape]).setVersion(1147);
addNodeObject(generator, "Pixel Builder", s_node_pixel_builder, "Node_Pixel_Builder", [1, Node_Pixel_Builder]).setVersion(11540);
ds_list_add(generator, "Noises");
addNodeObject(generator, "Noise", s_node_noise, "Node_Noise", [1, Node_Noise],, "Generate white noise.");
@ -469,8 +469,8 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor { #regio
addNodeObject(generator, "Region Fill", s_node_region_fill, "Node_Region_Fill", [1, Node_Region_Fill],, "Fill connected pixel with the same color.").setVersion(1147);
ds_list_add(generator, "Others");
addNodeObject(generator, "Flood Fill", s_node_flood_fill, "Node_Flood_Fill", [1, Node_Flood_Fill],, "Filled connected pixel given position and color.").setVersion(1133);
addNodeObject(generator, "Bar / Graph", s_node_bar_graph, "Node_Plot_Linear", [1, Node_Plot_Linear], ["graph", "waveform", "bar chart", "plot"], "Plot graph or bar chart from array of number.").setVersion(1144);
addNodeObject(generator, "Flood Fill", s_node_flood_fill, "Node_Flood_Fill", [1, Node_Flood_Fill],, "Filled connected pixel given position and color.").setVersion(1133);
addNodeObject(generator, "Bar / Graph", s_node_bar_graph, "Node_Plot_Linear", [1, Node_Plot_Linear], ["graph", "waveform", "bar chart", "plot"], "Plot graph or bar chart from array of number.").setVersion(1144);
#endregion
var compose = ds_list_create(); #region

View file

@ -1638,9 +1638,11 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
if(tags != VALUE_TAG.none) return true;
node.triggerRender();
if(_update) node.valueUpdate(self.index);
node.clearCacheForward();
if(_update) {
node.triggerRender();
node.valueUpdate(self.index);
node.clearCacheForward();
}
if(fullUpdate) RENDER_ALL

View file

@ -80,7 +80,6 @@ function ResetAllNodesRender() { #region
} #endregion
function NodeTopoSort() { #region
LOG_IF(global.FLAG.render == 1, $"+++++++ Topo Sort +++++++");
var _key = ds_map_find_first(PROJECT.nodeMap);
var amo = ds_map_size(PROJECT.nodeMap);
@ -93,7 +92,7 @@ function NodeTopoSort() { #region
ds_list_clear(PROJECT.nodeTopo);
__sortGraph(PROJECT.nodeTopo, PROJECT.nodes);
LOG_IF(global.FLAG.render == 1, $"+++++++ Topo Sort Completed {ds_list_size(PROJECT.nodeTopo)} nodes sorted +++++++");
LOG_IF(global.FLAG.render == 1, $"+++++++ Topo Sort Completed: {ds_list_size(PROJECT.nodeTopo)} nodes sorted +++++++");
} #endregion
function __sortGraph(_list, _nodeList) { #region
@ -272,7 +271,7 @@ function __renderListReset(list) { #region
}
} #endregion
function RenderList(list) { #region
function RenderList(list, skipInLoop = true) { #region
LOG_BLOCK_START();
LOG_IF(global.FLAG.render == 1, "=============== RENDER LIST START ===============");
var queue = ds_queue_create();
@ -306,7 +305,7 @@ function RenderList(list) { #region
if(!_node.isRenderActive()) { LOG_IF(global.FLAG.render == 1, $"Skip non-renderActive {_node.internalName}"); continue; }
if(!_node.attributes.update_graph) { LOG_IF(global.FLAG.render == 1, $"Skip non-auto update {_node.internalName}"); continue; }
if(__nodeInLoop(_node)) { LOG_IF(global.FLAG.render == 1, $"Skip in-loop {_node.internalName}"); continue; }
if(skipInLoop && __nodeInLoop(_node)) { LOG_IF(global.FLAG.render == 1, $"Skip in-loop {_node.internalName}"); continue; }
if(_node.passiveDynamic) {
_node.forwardPassiveDynamic();
@ -344,9 +343,6 @@ function RenderList(list) { #region
var nextNodes = rendering.getNextNodes();
for( var i = 0, n = array_length(nextNodes); i < n; i++ )
ds_queue_enqueue(queue, nextNodes[i]);
if(runAction && rendering.hasInspector1Update())
rendering.inspector1Update();
}
LOG_BLOCK_END();