Pixel-Composer/scripts/node_iterate/node_iterate.gml

75 lines
1.7 KiB
Plaintext
Raw Normal View History

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 {
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;
inputs[| 0] = nodeValue( 0, "Repeat", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1 );
custom_input_index = 1;
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
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();
}
printIf(global.RENDER_LOG, "LOOP INIT");
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;
__nodeLeafList(nodes, RENDER_STACK);
initLoop();
}
2022-12-12 09:08:03 +01:00
static iterationStatus = function() {
2022-01-23 04:08:16 +01:00
var iter = true;
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++;
if(iterated == inputs[| 0].getValue()) {
2022-01-25 10:58:11 +01:00
render_time = get_timer() - loop_start_time;
2022-12-12 09:08:03 +01:00
return ITERATION_STATUS.complete;
2022-01-25 10:58:11 +01:00
} else if(iterated > inputs[| 0].getValue())
2022-12-12 09:08:03 +01:00
return ITERATION_STATUS.complete;
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
}
}