2023-12-19 14:30:34 +01:00
|
|
|
function Node_Iterate_Inline(_x, _y, _group = noone) : Node_Collection_Inline(_x, _y, _group) constructor {
|
2023-12-20 14:02:49 +01:00
|
|
|
name = "Loop";
|
|
|
|
color = COLORS.node_blend_loop;
|
|
|
|
icon = THEME.loop;
|
|
|
|
icon_24 = THEME.loop_24;
|
2023-12-19 14:30:34 +01:00
|
|
|
|
2023-12-22 04:15:04 +01:00
|
|
|
is_root = false;
|
|
|
|
|
2024-08-18 09:13:41 +02:00
|
|
|
newInput(0, nodeValue_Int("Repeat", self, 1 ))
|
2023-12-19 14:30:34 +01:00
|
|
|
.uncache();
|
|
|
|
|
|
|
|
managedRenderOrder = true;
|
|
|
|
|
|
|
|
attributes.junc_in = [ "", 0 ];
|
|
|
|
attributes.junc_out = [ "", 0 ];
|
|
|
|
|
|
|
|
junc_in = noone;
|
|
|
|
junc_out = noone;
|
|
|
|
|
|
|
|
value_buffer = undefined;
|
2024-12-07 10:35:29 +01:00
|
|
|
iteration_count = 0;
|
2023-12-19 14:30:34 +01:00
|
|
|
iterated = 0;
|
|
|
|
|
|
|
|
static getIterationCount = function() { return getInputData(0); }
|
2024-11-30 06:50:20 +01:00
|
|
|
static bypassConnection = function() { return iterated > 1 && !is_undefined(value_buffer); }
|
2024-08-08 06:57:51 +02:00
|
|
|
static bypassNextNode = function() { return iterated < getIterationCount(); }
|
2023-12-19 14:30:34 +01:00
|
|
|
|
2024-12-07 10:35:29 +01:00
|
|
|
static getNextNodes = function(checkLoop = false) {
|
2023-12-19 14:30:34 +01:00
|
|
|
LOG_BLOCK_START();
|
|
|
|
LOG_IF(global.FLAG.render == 1, "[outputNextNode] Get next node from inline iterate");
|
|
|
|
|
|
|
|
resetRender();
|
|
|
|
var _nodes = __nodeLeafList(nodes);
|
|
|
|
array_push_unique(_nodes, junc_in.node);
|
|
|
|
iterated++;
|
|
|
|
|
|
|
|
LOG_BLOCK_END();
|
2024-11-30 06:50:20 +01:00
|
|
|
logNodeDebug($"Loop restart: iteration {iterated}");
|
2023-12-19 14:30:34 +01:00
|
|
|
|
|
|
|
return _nodes;
|
2024-08-08 06:57:51 +02:00
|
|
|
}
|
2023-12-19 14:30:34 +01:00
|
|
|
|
2024-05-28 04:57:00 +02:00
|
|
|
static connectJunctions = function(jFrom, jTo) {
|
|
|
|
junc_in = jFrom.is_dummy? jFrom.dummy_get() : jFrom;
|
|
|
|
junc_out = jTo;
|
|
|
|
|
|
|
|
attributes.junc_in = [ junc_in .node.node_id, junc_in .index ];
|
|
|
|
attributes.junc_out = [ junc_out.node.node_id, junc_out.index ];
|
|
|
|
}
|
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
static scanJunc = function() {
|
2023-12-19 14:30:34 +01:00
|
|
|
var node_in = PROJECT.nodeMap[? attributes.junc_in[0]];
|
|
|
|
var node_out = PROJECT.nodeMap[? attributes.junc_out[0]];
|
|
|
|
|
2024-11-30 06:50:20 +01:00
|
|
|
junc_in = noone;
|
|
|
|
junc_out = noone;
|
|
|
|
|
|
|
|
if(node_in) junc_in = array_safe_get(node_in.inputs, attributes.junc_in[1]);
|
|
|
|
if(node_out) junc_out = array_safe_get(node_out.outputs, attributes.junc_out[1]);
|
2023-12-19 14:30:34 +01:00
|
|
|
|
|
|
|
if(junc_in) { junc_in.value_from_loop = self; addNode(junc_in.node); }
|
|
|
|
if(junc_out) { array_push(junc_out.value_to_loop, self); addNode(junc_out.node); }
|
2024-08-08 06:57:51 +02:00
|
|
|
}
|
2023-12-19 14:30:34 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
static updateValue = function() {
|
2023-12-19 14:30:34 +01:00
|
|
|
var type = junc_out.type;
|
|
|
|
var val = junc_out.getValue();
|
|
|
|
|
|
|
|
switch(type) {
|
|
|
|
case VALUE_TYPE.surface :
|
|
|
|
surface_array_free(value_buffer);
|
|
|
|
value_buffer = surface_array_clone(val);
|
|
|
|
break;
|
2024-08-08 06:57:51 +02:00
|
|
|
|
2023-12-19 14:30:34 +01:00
|
|
|
default :
|
|
|
|
value_buffer = variable_clone(val);
|
|
|
|
break;
|
|
|
|
}
|
2024-08-08 06:57:51 +02:00
|
|
|
}
|
2023-12-19 14:30:34 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
static getValue = function(arr) {
|
2024-04-01 11:10:01 +02:00
|
|
|
INLINE
|
|
|
|
|
|
|
|
arr[@ 0] = value_buffer;
|
|
|
|
arr[@ 1] = junc_out;
|
2024-08-08 06:57:51 +02:00
|
|
|
}
|
2023-12-19 14:30:34 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
static update = function() {
|
2024-12-07 10:35:29 +01:00
|
|
|
var _itc = inputs[0].getValue();
|
|
|
|
if(_itc != iteration_count) RENDER_ALL_REORDER;
|
|
|
|
|
|
|
|
iteration_count = _itc;
|
2023-12-19 14:30:34 +01:00
|
|
|
iterated = 0;
|
|
|
|
value_buffer = undefined;
|
2024-08-08 06:57:51 +02:00
|
|
|
}
|
2023-12-19 14:30:34 +01:00
|
|
|
|
2024-11-30 06:50:20 +01:00
|
|
|
static drawJunctions = function(_draw, _x, _y, _mx, _my, _s) {
|
|
|
|
var hover = noone;
|
|
|
|
|
|
|
|
gpu_set_tex_filter(true);
|
|
|
|
var jun = inputs[0];
|
|
|
|
jun.rx = junction_x;
|
|
|
|
jun.ry = junction_y;
|
|
|
|
jun.x = _x + junction_x * _s;
|
|
|
|
jun.y = _y + junction_y * _s;
|
|
|
|
|
|
|
|
if(jun.isVisible() && jun.drawJunction(_draw, _s, _mx, _my))
|
|
|
|
hover = jun;
|
|
|
|
gpu_set_tex_filter(false);
|
|
|
|
|
|
|
|
return hover;
|
|
|
|
}
|
|
|
|
|
|
|
|
static drawConnections = function(params = {}, _draw = true) {
|
|
|
|
var hovering = noone;
|
|
|
|
|
2024-09-23 13:27:31 +02:00
|
|
|
params.dashed = true; params.loop = true;
|
2024-11-30 06:50:20 +01:00
|
|
|
if(junc_out && junc_in) drawJuncConnection(junc_out, junc_in, params);
|
2024-09-23 13:27:31 +02:00
|
|
|
params.dashed = false; params.loop = false;
|
|
|
|
|
2024-11-30 06:50:20 +01:00
|
|
|
var jun = inputs[0];
|
|
|
|
var _hov = jun.drawConnections(params, _draw); if(_hov) hovering = _hov;
|
|
|
|
|
|
|
|
return hovering;
|
2024-08-08 06:57:51 +02:00
|
|
|
}
|
2023-12-19 14:30:34 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
static postDeserialize = function() {
|
2023-12-19 14:30:34 +01:00
|
|
|
refreshMember();
|
|
|
|
scanJunc();
|
2024-08-08 06:57:51 +02:00
|
|
|
}
|
2023-12-19 14:30:34 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
static onDestroy = function() {
|
2023-12-19 14:30:34 +01:00
|
|
|
if(junc_in) junc_in.value_from_loop = noone;
|
|
|
|
if(junc_out) array_remove(junc_out.value_to_loop, self);
|
2024-08-08 06:57:51 +02:00
|
|
|
}
|
2023-12-19 14:30:34 +01:00
|
|
|
}
|