Pixel-Composer/scripts/node_iterate/node_iterate.gml

96 lines
2.3 KiB
Text
Raw Normal View History

2022-12-12 09:08:03 +01:00
enum ITERATION_STATUS {
not_ready,
loop,
complete,
}
2023-02-28 09:43:01 +01:00
function Node_Iterate(_x, _y, _group = noone) : 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
2023-02-19 13:49:20 +01:00
combine_render_time = false;
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() {
resetRender();
2022-12-12 09:08:03 +01:00
iterated = 0;
loop_start_time = get_timer();
2023-02-28 09:43:01 +01:00
var node_list = getNodeList();
2022-12-13 09:20:36 +01:00
2023-02-28 09:43:01 +01:00
for( var i = 0; i < ds_list_size(node_list); i++ ) {
var n = node_list[| i];
2022-12-13 09:20:36 +01:00
if(variable_struct_exists(n, "initLoop"))
n.initLoop();
}
LOG_LINE_IF(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;
2023-02-19 13:49:20 +01:00
if(!_in.renderActive) continue;
2023-03-26 07:13:36 +02:00
allReady &= _in.isRenderable()
2022-12-16 09:18:09 +01:00
}
2023-03-28 06:58:28 +02:00
if(!allReady) return [];
2022-12-16 09:18:09 +01:00
initLoop();
2023-03-28 06:58:28 +02:00
return __nodeLeafList(getNodeList());
2022-12-16 09:18:09 +01:00
}
2023-04-08 20:06:27 +02:00
static getIterationCount = function() {
2023-02-14 05:32:32 +01:00
var maxIter = inputs[| 0].getValue();
2023-04-08 20:06:27 +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];
if(!_o.node.rendered) return;
2022-01-23 04:08:16 +01:00
}
2023-04-08 20:06:27 +02:00
var maxIter = getIterationCount();
iterated++;
LOG_BLOCK_START();
LOG_IF(global.RENDER_LOG, "Iteration update: " + string(iterated) + "/" + string(maxIter));
if(iterated >= maxIter) {
LOG_IF(global.RENDER_LOG, "Iteration complete");
render_time = get_timer() - loop_start_time;
} else {
LOG_IF(global.RENDER_LOG, "Iteration not completed, reset render status.");
resetRender();
2022-01-23 04:08:16 +01:00
}
2023-04-08 20:06:27 +02:00
LOG_BLOCK_END();
}
static iterationStatus = function() {
if(iterated >= getIterationCount())
return ITERATION_STATUS.complete;
return ITERATION_STATUS.loop;
2022-01-23 04:08:16 +01:00
}
2023-03-08 14:59:54 +01:00
PATCH_STATIC
2022-01-23 04:08:16 +01:00
}