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

@ -59,6 +59,8 @@ function Node_Compare(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
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);
var al = as? array_length(a) : 0;

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

@ -18,11 +18,11 @@ function Node_Iterate_Sort(_x, _y, _group = noone) : Node_Collection(_x, _y, _gr
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,78 +30,23 @@ 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);
initLoop();
}
static swap = function(arr, a, b) {
var temp = arr[a];
arr[@ a] = arr[b];
arr[@ b] = temp;
}
static partition = function(arr, low, high) {
var pv = arr[high];
var i = low - 1;
for(var j = low; j < high; j++) {
if(compareValue(arr[j], pv)) continue;
i++;
swap(arr, i, j);
}
swap(arr, i + 1, high);
return i + 1;
}
static quickSort = function(arr, low, high) {
if(!nodeValid) return;
if(low >= high) return;
var p = partition(arr, low, high);
quickSort(arr, low, p - 1);
quickSort(arr, p + 1, high);
}
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() {
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 ];
inputNodes = [ noone, noone ];
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];
@ -122,6 +67,62 @@ function Node_Iterate_Sort(_x, _y, _group = noone) : Node_Collection(_x, _y, _gr
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) { #region
var temp = arr[a];
arr[@ a] = arr[b];
arr[@ b] = temp;
} #endregion
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;
for(var j = low; j < high; j++) {
if(compareValue(arr[j], pv)) continue;
i++;
swap(arr, i, j);
}
swap(arr, i + 1, high);
return i + 1;
} #endregion
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 sortArray = function() { #region
if(inputs[| 0].value_from) {
inputs[| 0].setType(inputs[| 0].value_from.type);
outputs[| 0].setType(inputs[| 0].value_from.type);
}
iterated = 0;
loop_start_time = get_timer();
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

View file

@ -1638,9 +1638,11 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
if(tags != VALUE_TAG.none) return true;
if(_update) {
node.triggerRender();
if(_update) node.valueUpdate(self.index);
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();