2023-02-28 09:43:01 +01:00
|
|
|
function Node_Iterate_Each(_x, _y, _group = noone) : Node_Collection(_x, _y, _group) constructor {
|
2023-02-14 11:40:24 +01:00
|
|
|
name = "Loop Array";
|
|
|
|
color = COLORS.node_blend_loop;
|
|
|
|
icon = THEME.loop;
|
|
|
|
|
2023-02-19 13:49:20 +01:00
|
|
|
combine_render_time = false;
|
2023-02-14 11:40:24 +01:00
|
|
|
iterated = 0;
|
|
|
|
|
|
|
|
inputs[| 0] = nodeValue("Array", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, [] )
|
|
|
|
.setVisible(true, true);
|
|
|
|
|
|
|
|
outputs[| 0] = nodeValue("Array", self, JUNCTION_CONNECT.output, VALUE_TYPE.any, [] );
|
|
|
|
|
|
|
|
custom_input_index = ds_list_size(inputs);
|
|
|
|
custom_output_index = ds_list_size(inputs);
|
|
|
|
loop_start_time = 0;
|
|
|
|
ALWAYS_FULL = true;
|
|
|
|
|
|
|
|
if(!LOADING && !APPENDING && !CLONING) {
|
|
|
|
var input = nodeBuild("Node_Iterator_Each_Input", -256, -32, self);
|
|
|
|
var output = nodeBuild("Node_Iterator_Each_Output", 256, -32, self);
|
|
|
|
|
|
|
|
output.inputs[| 0].setFrom(input.outputs[| 0]);
|
|
|
|
}
|
|
|
|
|
2023-04-03 11:55:45 +02:00
|
|
|
static getNextNodesRaw = function() {
|
|
|
|
return __nodeLeafList(getNodeList());
|
|
|
|
}
|
|
|
|
|
2023-02-14 11:40:24 +01:00
|
|
|
static getNextNodes = function() {
|
|
|
|
initLoop();
|
2023-03-28 06:58:28 +02:00
|
|
|
return __nodeLeafList(getNodeList());
|
2023-02-14 11:40:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static onStep = function() {
|
|
|
|
var type = inputs[| 0].value_from == noone? VALUE_TYPE.any : inputs[| 0].value_from.type;
|
|
|
|
inputs[| 0].type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static initLoop = function() {
|
2023-04-03 11:55:45 +02:00
|
|
|
resetRender();
|
2023-02-14 11:40:24 +01:00
|
|
|
iterated = 0;
|
|
|
|
loop_start_time = get_timer();
|
|
|
|
|
2023-02-19 13:49:20 +01:00
|
|
|
var arrIn = inputs[| 0].getValue();
|
|
|
|
var arrOut = outputs[| 0].getValue();
|
2023-02-14 11:40:24 +01:00
|
|
|
|
2023-02-19 13:49:20 +01:00
|
|
|
if(array_length(arrOut) != array_length(arrIn)) {
|
|
|
|
surface_array_free(arrOut);
|
|
|
|
outputs[| 0].setValue([])
|
|
|
|
}
|
2023-02-14 11:40:24 +01:00
|
|
|
|
2023-05-08 19:14:30 +02:00
|
|
|
LOG_LINE_IF(global.DEBUG_FLAG.render, "Loop begin");
|
2023-02-14 11:40:24 +01:00
|
|
|
}
|
|
|
|
|
2023-04-03 11:55:45 +02:00
|
|
|
static getIterationCount = function() {
|
2023-02-14 11:40:24 +01:00
|
|
|
var arrIn = inputs[| 0].getValue();
|
|
|
|
var maxIter = is_array(arrIn)? array_length(arrIn) : 0;
|
|
|
|
if(!is_real(maxIter)) maxIter = 1;
|
|
|
|
|
2023-04-03 11:55:45 +02:00
|
|
|
return maxIter;
|
|
|
|
}
|
|
|
|
|
|
|
|
static iterationUpdate = function() {
|
|
|
|
var siz = ds_list_size(outputs); // check if every output is updated
|
|
|
|
for( var i = custom_output_index; i < siz; i++ ) {
|
|
|
|
var _o = outputs[| i];
|
2023-04-08 20:06:27 +02:00
|
|
|
if(!_o.node.rendered) return;
|
2023-04-03 11:55:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var maxIter = getIterationCount();
|
2023-02-14 11:40:24 +01:00
|
|
|
iterated++;
|
2023-04-03 11:55:45 +02:00
|
|
|
|
|
|
|
LOG_BLOCK_START();
|
2023-05-08 19:14:30 +02:00
|
|
|
LOG_IF(global.DEBUG_FLAG.render, "Iteration update: " + string(iterated) + "/" + string(maxIter));
|
2023-04-03 11:55:45 +02:00
|
|
|
|
2023-02-14 11:40:24 +01:00
|
|
|
if(iterated >= maxIter) {
|
2023-05-08 19:14:30 +02:00
|
|
|
LOG_IF(global.DEBUG_FLAG.render, "Iteration complete");
|
2023-02-14 11:40:24 +01:00
|
|
|
render_time = get_timer() - loop_start_time;
|
2023-04-03 11:55:45 +02:00
|
|
|
} else {
|
2023-05-08 19:14:30 +02:00
|
|
|
LOG_IF(global.DEBUG_FLAG.render, "Iteration not completed, reset render status.");
|
2023-04-03 11:55:45 +02:00
|
|
|
resetRender();
|
2023-02-14 11:40:24 +01:00
|
|
|
}
|
|
|
|
|
2023-04-03 11:55:45 +02:00
|
|
|
LOG_BLOCK_END();
|
|
|
|
}
|
|
|
|
|
|
|
|
static iterationStatus = function() {
|
|
|
|
if(iterated >= getIterationCount())
|
|
|
|
return ITERATION_STATUS.complete;
|
2023-02-14 11:40:24 +01:00
|
|
|
return ITERATION_STATUS.loop;
|
|
|
|
}
|
2023-03-08 14:59:54 +01:00
|
|
|
|
|
|
|
PATCH_STATIC
|
2023-02-14 11:40:24 +01:00
|
|
|
}
|