2022-12-12 09:08:03 +01:00
|
|
|
enum ITERATION_STATUS {
|
|
|
|
not_ready,
|
|
|
|
loop,
|
|
|
|
complete,
|
|
|
|
}
|
|
|
|
|
2022-12-13 14:11:39 +01:00
|
|
|
function Node_Iterate(_x, _y, _group = -1) : Node_Collection(_x, _y, _group) constructor {
|
2022-01-25 04:05:30 +01:00
|
|
|
name = "Loop";
|
2022-11-18 03:20:31 +01:00
|
|
|
color = COLORS.node_blend_loop;
|
|
|
|
icon = THEME.loop;
|
2022-01-23 04:08:16 +01:00
|
|
|
|
|
|
|
iterated = 0;
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
inputs[| 0] = nodeValue("Repeat", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1 );
|
2022-01-23 04:08:16 +01:00
|
|
|
|
2023-01-25 06:49:00 +01:00
|
|
|
custom_input_index = ds_list_size(inputs);
|
2022-01-25 10:58:11 +01:00
|
|
|
loop_start_time = 0;
|
2022-12-13 09:20:36 +01:00
|
|
|
ALWAYS_FULL = true;
|
2022-01-23 04:08:16 +01:00
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
if(!LOADING && !APPENDING && !CLONING) {
|
2022-12-13 09:20:36 +01:00
|
|
|
var input = nodeBuild("Node_Iterator_Input", -256, -32, self);
|
|
|
|
var output = nodeBuild("Node_Iterator_Output", 256, -32, self);
|
2022-12-12 09:08:03 +01:00
|
|
|
|
2023-01-25 06:49:00 +01:00
|
|
|
input.inputs[| 2].setValue(4);
|
2022-12-13 09:20:36 +01:00
|
|
|
output.inputs[| 2].setFrom(input.outputs[| 1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static initLoop = function() {
|
2022-12-12 09:08:03 +01:00
|
|
|
iterated = 0;
|
|
|
|
loop_start_time = get_timer();
|
2022-12-13 09:20:36 +01:00
|
|
|
|
|
|
|
for( var i = 0; i < ds_list_size(nodes); i++ ) {
|
|
|
|
var n = nodes[| i];
|
|
|
|
if(variable_struct_exists(n, "initLoop"))
|
|
|
|
n.initLoop();
|
|
|
|
}
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
printIf(global.RENDER_LOG, " > Loop begin");
|
2022-01-23 04:08:16 +01:00
|
|
|
}
|
|
|
|
|
2022-12-16 09:18:09 +01:00
|
|
|
static getNextNodes = function() {
|
|
|
|
var allReady = true;
|
|
|
|
for(var i = custom_input_index; i < ds_list_size(inputs); i++) {
|
|
|
|
var _in = inputs[| i].from;
|
|
|
|
allReady &= _in.isUpdateReady()
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!allReady) return;
|
|
|
|
|
2023-01-25 06:49:00 +01:00
|
|
|
__nodeLeafList(nodes, RENDER_QUEUE);
|
2022-12-16 09:18:09 +01:00
|
|
|
initLoop();
|
|
|
|
}
|
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
static iterationStatus = function() {
|
2022-01-23 04:08:16 +01:00
|
|
|
var iter = true;
|
2023-02-14 05:32:32 +01:00
|
|
|
var maxIter = inputs[| 0].getValue();
|
|
|
|
if(!is_real(maxIter)) maxIter = 1;
|
2022-01-23 04:08:16 +01:00
|
|
|
for( var i = 0; i < ds_list_size(outputs); i++ ) {
|
2022-12-13 09:20:36 +01:00
|
|
|
var _out = outputs[| i].from;
|
2022-01-23 04:08:16 +01:00
|
|
|
iter &= _out.rendered;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(iter) {
|
2023-01-09 03:14:20 +01:00
|
|
|
iterated++;
|
|
|
|
|
2023-02-14 11:40:24 +01:00
|
|
|
if(iterated >= maxIter) {
|
2022-01-25 10:58:11 +01:00
|
|
|
render_time = get_timer() - loop_start_time;
|
2023-02-14 11:40:24 +01:00
|
|
|
iterated = 0;
|
2022-12-12 09:08:03 +01:00
|
|
|
return ITERATION_STATUS.complete;
|
2023-02-14 11:40:24 +01:00
|
|
|
}
|
2022-01-23 04:08:16 +01:00
|
|
|
|
2022-12-13 09:20:36 +01:00
|
|
|
resetAllRenderStatus();
|
2022-12-12 09:08:03 +01:00
|
|
|
return ITERATION_STATUS.loop;
|
2022-01-23 04:08:16 +01:00
|
|
|
}
|
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
return ITERATION_STATUS.not_ready;
|
2022-01-23 04:08:16 +01:00
|
|
|
}
|
|
|
|
}
|