Pixel-Composer/scripts/node_data/node_data.gml

2028 lines
55 KiB
Text
Raw Normal View History

2023-02-14 13:44:46 +01:00
global.loop_nodes = [ "Node_Iterate", "Node_Iterate_Each" ];
#macro INAME internalName == ""? name : internalName
2023-10-02 14:41:44 +02:00
enum CACHE_USE {
none,
manual,
auto
}
2023-10-18 14:58:55 +02:00
enum DYNA_INPUT_COND {
connection = 1 << 0,
zero = 1 << 1,
}
2023-03-07 14:29:47 +01:00
function Node(_x, _y, _group = PANEL_GRAPH.getCurrentContext()) : __Node_Base(_x, _y) constructor {
2023-08-16 20:16:31 +02:00
#region ---- main & active ----
2023-12-18 08:27:31 +01:00
active = true;
2023-08-16 20:16:31 +02:00
renderActive = true;
2023-03-24 09:32:08 +01:00
2023-08-16 20:16:31 +02:00
node_id = UUID_generate();
group = _group;
2023-09-11 16:08:58 +02:00
manual_deletable = true;
manual_ungroupable = true;
2023-08-16 20:16:31 +02:00
destroy_when_upgroup = false;
ds_list_add(PANEL_GRAPH.getNodeList(_group), self);
2023-11-08 08:38:04 +01:00
2023-08-16 20:16:31 +02:00
active_index = -1;
2023-10-09 16:07:33 +02:00
active_range = [ 0, TOTAL_FRAMES - 1 ];
2023-11-08 08:38:04 +01:00
array_push(PROJECT.nodeArray, self);
2023-12-18 08:27:31 +01:00
inline_context = noone;
2023-08-16 20:16:31 +02:00
#endregion
2022-01-13 05:24:03 +01:00
2023-08-16 20:16:31 +02:00
static resetInternalName = function() { #region
2023-06-17 18:59:20 +02:00
var str = string_replace_all(name, " ", "_");
str = string_replace_all(str, "/", "");
str = string_replace_all(str, "-", "");
ds_map_delete(PROJECT.nodeNameMap, internalName);
2023-06-17 18:59:20 +02:00
internalName = str + string(irandom_range(10000, 99999));
2023-07-06 19:49:16 +02:00
PROJECT.nodeNameMap[? internalName] = self;
2023-08-16 20:16:31 +02:00
} #endregion
2023-06-17 18:59:20 +02:00
2023-08-16 20:16:31 +02:00
if(!LOADING && !APPENDING) { #region
2022-01-13 05:24:03 +01:00
recordAction(ACTION_TYPE.node_added, self);
2023-07-06 19:49:16 +02:00
PROJECT.nodeMap[? node_id] = self;
PROJECT.modified = true;
2023-07-25 20:12:40 +02:00
2023-05-16 21:28:16 +02:00
run_in(1, function() {
2023-06-17 18:59:20 +02:00
resetInternalName();
2023-11-23 13:39:35 +01:00
if(renamed) return;
display_name = __txt_node_name(instanceof(self), name);
if(!LOCALE_DEF || TESTING) renamed = true;
2023-05-16 21:28:16 +02:00
});
2023-10-08 04:14:35 +02:00
RENDER_ALL_REORDER
2023-08-16 20:16:31 +02:00
} #endregion
2023-05-07 20:55:13 +02:00
2023-08-16 20:16:31 +02:00
#region ---- display ----
color = c_white;
icon = noone;
2023-12-20 14:02:49 +01:00
icon_24 = noone;
2023-08-16 20:16:31 +02:00
bg_spr = THEME.node_bg;
bg_sel_spr = THEME.node_active;
2022-01-13 05:24:03 +01:00
2023-08-16 20:16:31 +02:00
name = "";
display_name = "";
internalName = "";
2023-10-01 06:17:39 +02:00
onSetDisplayName = noone;
renamed = false;
2023-12-19 14:30:34 +01:00
2023-08-16 20:16:31 +02:00
tooltip = "";
x = _x;
y = _y;
2023-01-04 02:30:04 +01:00
2023-08-16 20:16:31 +02:00
w = 128;
h = 128;
2023-11-20 05:10:55 +01:00
min_w = 0;
2023-08-16 20:16:31 +02:00
min_h = 0;
2023-11-20 05:10:55 +01:00
will_setHeight = false;
2023-12-19 14:30:34 +01:00
selectable = true;
2023-08-16 20:16:31 +02:00
draw_padding = 4;
auto_height = true;
display_parameter = {};
draw_name = true;
draggable = true;
draw_graph_culled = false;
badgePreview = 0;
badgeInspect = 0;
active_draw_index = -1;
draw_droppable = false;
2023-09-11 16:08:58 +02:00
junction_draw_pad_y = 32;
2023-10-12 07:07:24 +02:00
branch_drawing = false;
2023-08-16 20:16:31 +02:00
#endregion
2023-03-28 06:58:28 +02:00
2023-08-16 20:16:31 +02:00
#region ---- junctions ----
inputs = ds_list_create();
outputs = ds_list_create();
inputMap = ds_map_create();
outputMap = ds_map_create();
2023-10-12 14:14:08 +02:00
input_value_map = {};
use_display_list = true;
2023-08-16 20:16:31 +02:00
input_display_list = -1;
output_display_list = -1;
inspector_display_list = -1;
is_dynamic_output = false;
inspectInput1 = nodeValue("Toggle execution", self, JUNCTION_CONNECT.input, VALUE_TYPE.action, false).setVisible(true, true);
inspectInput2 = nodeValue("Toggle execution", self, JUNCTION_CONNECT.input, VALUE_TYPE.action, false).setVisible(true, true);
2023-10-07 16:23:40 +02:00
inspectInput1.index = -1;
inspectInput2.index = -1;
2023-09-28 13:15:29 +02:00
autoUpdatedTrigger = true;
2023-10-06 11:51:11 +02:00
updatedInTrigger = nodeValue("Update", self, JUNCTION_CONNECT.input, VALUE_TYPE.trigger, false).setVisible(true, true);
updatedOutTrigger = nodeValue("Updated", self, JUNCTION_CONNECT.output, VALUE_TYPE.trigger, false).setVisible(true, true);
2023-10-07 16:23:40 +02:00
updatedInTrigger.index = -1;
updatedOutTrigger.index = -1;
2023-10-06 11:51:11 +02:00
updatedInTrigger.tags = VALUE_TAG.updateInTrigger;
updatedOutTrigger.tags = VALUE_TAG.updateOutTrigger;
2023-09-28 13:15:29 +02:00
2023-11-04 13:22:52 +01:00
insp1UpdateActive = true;
2023-08-16 20:16:31 +02:00
insp1UpdateTooltip = __txtx("panel_inspector_execute", "Execute node");
insp1UpdateIcon = [ THEME.sequence_control, 1, COLORS._main_value_positive ];
2023-11-04 13:22:52 +01:00
insp2UpdateActive = true;
2023-08-16 20:16:31 +02:00
insp2UpdateTooltip = __txtx("panel_inspector_execute", "Execute node");
insp2UpdateIcon = [ THEME.sequence_control, 1, COLORS._main_value_positive ];
is_dynamic_input = false;
auto_input = false;
2023-08-16 20:16:31 +02:00
input_display_len = 0;
input_fix_len = 0;
data_length = 1;
inputs_data = [];
input_hash = "";
2023-10-02 14:41:44 +02:00
input_hash_raw = "";
2023-11-30 03:18:25 +01:00
inputs_amount = 0;
in_cache_len = 0;
inputs_index = [];
outputs_amount = 0;
outputs_index = [];
out_cache_len = 0;
2023-08-16 20:16:31 +02:00
#endregion
2023-04-16 11:53:46 +02:00
2023-08-16 20:16:31 +02:00
#region --- attributes ----
2023-11-20 05:10:55 +01:00
attributes.node_width = 0;
attributes.node_height = 0;
2023-09-28 13:15:29 +02:00
attributeEditors = [
2023-10-06 11:51:11 +02:00
"Node update",
["Auto update", function() { return attributes.update_graph; }, new checkBox(function() { attributes.update_graph = !attributes.update_graph; }) ],
["Update trigger", function() { return attributes.show_update_trigger; }, new checkBox(function() { attributes.show_update_trigger = !attributes.show_update_trigger; }) ],
2023-09-28 13:15:29 +02:00
];
2023-08-16 20:16:31 +02:00
#endregion
2022-01-13 05:24:03 +01:00
2023-08-16 20:16:31 +02:00
#region ---- preview ----
show_input_name = false;
show_output_name = false;
inspecting = false;
previewing = 0;
2023-12-04 12:09:31 +01:00
2023-08-16 20:16:31 +02:00
preview_surface = noone;
preview_amount = 0;
previewable = true;
2023-12-04 12:09:31 +01:00
preview_draw = true;
2023-08-16 20:16:31 +02:00
preview_speed = 0;
preview_index = 0;
preview_channel = 0;
preview_alpha = 1;
preview_x = 0;
preview_y = 0;
2023-08-16 20:16:31 +02:00
preview_mx = 0;
preview_my = 0;
2023-10-09 16:07:33 +02:00
graph_preview_alpha = 1;
2023-10-09 16:07:33 +02:00
getPreviewingNode = noone;
2023-11-27 11:40:28 +01:00
preview_value = 0;
preview_array = "";
2023-08-16 20:16:31 +02:00
#endregion
2022-01-13 05:24:03 +01:00
2023-08-16 20:16:31 +02:00
#region ---- rendering ----
rendered = false;
update_on_frame = false;
render_time = 0;
2023-10-02 14:41:44 +02:00
render_cached = false;
2023-08-16 20:16:31 +02:00
auto_render_time = true;
updated = false;
2023-10-07 16:23:40 +02:00
passiveDynamic = false;
topoSorted = false;
2023-11-29 03:04:28 +01:00
temp_surface = [];
2023-12-10 14:55:05 +01:00
force_requeue = false;
2023-11-29 03:04:28 +01:00
2023-12-22 04:15:04 +01:00
in_VFX = false;
2023-11-29 03:04:28 +01:00
is_group_io = false;
2023-08-16 20:16:31 +02:00
#endregion
2023-03-26 07:13:36 +02:00
2023-08-16 20:16:31 +02:00
#region ---- timeline ----
2023-10-14 08:00:35 +02:00
timeline_item = new timelineItemNode(self);
anim_priority = ds_map_size(PROJECT.nodeMap);
is_anim_timeline = false;
2023-08-16 20:16:31 +02:00
#endregion
2023-03-26 07:13:36 +02:00
2023-08-16 20:16:31 +02:00
#region ---- notification ----
value_validation = array_create(3);
2022-01-13 05:24:03 +01:00
2023-08-16 20:16:31 +02:00
error_noti_update = noone;
error_update_enabled = false;
manual_updated = false;
#endregion
2022-01-13 05:24:03 +01:00
2023-08-16 20:16:31 +02:00
#region ---- tools ----
tools = -1;
isTool = false;
tool_settings = [];
tool_attribute = {};
#endregion
2022-01-13 05:24:03 +01:00
2023-08-16 20:16:31 +02:00
#region ---- 3d ----
is_3D = false;
#endregion
2022-01-13 05:24:03 +01:00
2023-11-02 14:37:13 +01:00
#region ---- cache ----
use_cache = CACHE_USE.none;
cached_manual = false;
cached_output = [];
cache_result = [];
cache_group = noone;
clearCacheOnChange = true;
2023-11-02 14:37:13 +01:00
#endregion
2023-12-10 14:55:05 +01:00
#region ---- log ----
messages = [];
#endregion
2023-08-05 14:00:33 +02:00
static createNewInput = noone;
2023-08-16 20:16:31 +02:00
static initTooltip = function() { #region
2023-08-08 11:42:01 +02:00
var type_self/*:string*/ = instanceof(self);
if(!struct_has(global.NODE_GUIDE, type_self)) return;
2023-03-05 07:16:44 +01:00
2023-08-08 11:42:01 +02:00
var _n = global.NODE_GUIDE[$ type_self];
2023-03-05 07:16:44 +01:00
var _ins = _n.inputs;
var _ots = _n.outputs;
var amo = min(ds_list_size(inputs), array_length(_ins));
for( var i = 0; i < amo; i++ ) {
inputs[| i].name = _ins[i].name;
inputs[| i].tooltip = _ins[i].tooltip;
}
var amo = min(ds_list_size(outputs), array_length(_ots));
for( var i = 0; i < amo; i++ ) {
outputs[| i].name = _ots[i].name;
outputs[| i].tooltip = _ots[i].tooltip;
}
2023-08-16 20:16:31 +02:00
} #endregion
2023-03-05 07:16:44 +01:00
run_in(1, initTooltip);
2023-08-16 20:16:31 +02:00
static resetDefault = function() { #region
2023-02-14 02:51:14 +01:00
var folder = instanceof(self);
if(!ds_map_exists(global.PRESETS_MAP, folder)) return;
var pres = global.PRESETS_MAP[? folder];
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(pres); i < n; i++ ) {
2023-02-14 02:51:14 +01:00
var preset = pres[i];
if(preset.name != "_default") continue;
deserialize(preset.content, true, true);
applyDeserialize(true);
}
doUpdate();
2023-08-16 20:16:31 +02:00
} #endregion
2023-08-06 16:00:59 +02:00
if(!APPENDING && !LOADING)
run_in(1, method(self, resetDefault));
2022-09-27 06:37:28 +02:00
2023-08-16 20:16:31 +02:00
static getInputJunctionIndex = function(index) { #region
if(input_display_list == -1 || !use_display_list)
2022-09-27 06:37:28 +02:00
return index;
var jun_list_arr = input_display_list[index];
if(is_array(jun_list_arr)) return noone;
if(is_struct(jun_list_arr)) return noone;
return jun_list_arr;
2023-08-16 20:16:31 +02:00
} #endregion
2023-08-16 20:16:31 +02:00
static getOutputJunctionIndex = function(index) { #region
2022-12-13 09:20:36 +01:00
if(output_display_list == -1)
return index;
return output_display_list[index];
2023-08-16 20:16:31 +02:00
} #endregion
2022-12-13 09:20:36 +01:00
2023-11-30 03:18:25 +01:00
static updateIO = function() { #region
inputs_amount = (input_display_list == -1 || !use_display_list)? ds_list_size(inputs) : array_length(input_display_list);
inputs_index = array_create(inputs_amount);
var _i = 0;
for( var i = 0; i < inputs_amount; i++ ) {
var _input = getInputJunctionIndex(i);
if(_input == noone) continue;
inputs_index[_i++] = _input;
}
inputs_amount = _i;
array_resize(inputs_index, inputs_amount);
outputs_amount = output_display_list == -1? ds_list_size(outputs) : array_length(output_display_list);
outputs_index = array_create_ext(outputs_amount, function(index) { return getOutputJunctionIndex(index); });
} #endregion
2023-08-16 20:16:31 +02:00
static setHeight = function() { #region
2023-11-08 08:38:04 +01:00
if(!auto_height) return;
2023-09-11 16:08:58 +02:00
var _hi = ui(junction_draw_pad_y);
var _ho = ui(junction_draw_pad_y);
2023-12-05 04:28:49 +01:00
var _prev_surf = previewable && preview_draw && (preview_channel < ds_list_size(outputs) && outputs[| preview_channel].type == VALUE_TYPE.surface);
2023-01-25 06:49:00 +01:00
2023-10-27 13:55:31 +02:00
for( var i = 0; i < ds_list_size(inputs); i++ ) {
var _inp = inputs[| i];
if(is_instanceof(_inp, NodeValue) && _inp.isVisible()) _hi += 24;
if(is_instanceof(_inp, NodeModule)) {
for( var j = 0, m = ds_list_size(_inp.inputs); j < m; j++ )
if(_inp.inputs[| j].isVisible()) _hi += 24;
}
}
2022-11-01 03:06:03 +01:00
2023-09-09 13:52:16 +02:00
for( var i = 0; i < ds_list_size(outputs); i++ )
2022-01-13 05:24:03 +01:00
if(outputs[| i].isVisible()) _ho += 24;
2023-11-20 05:10:55 +01:00
h = max(min_h, _prev_surf * 128, _hi, _ho, attributes.node_height);
2023-11-08 08:38:04 +01:00
} run_in(1, function() { setHeight(); }); #endregion
2023-02-14 02:51:14 +01:00
2023-08-16 20:16:31 +02:00
static setDisplayName = function(_name) { #region
2023-10-01 06:17:39 +02:00
renamed = true;
2023-04-15 14:48:29 +02:00
display_name = _name;
internalName = string_replace_all(display_name, " ", "_");
refreshNodeMap();
2023-06-13 14:42:06 +02:00
if(onSetDisplayName != noone)
onSetDisplayName();
2023-09-11 16:08:58 +02:00
return self;
2023-08-16 20:16:31 +02:00
} #endregion
2023-04-15 14:48:29 +02:00
2023-10-18 14:58:55 +02:00
static setIsDynamicInput = function(_data_length = 1, _auto_input = true, _dynamic_input_cond = DYNA_INPUT_COND.connection) { #region
is_dynamic_input = true;
auto_input = _auto_input;
2023-08-05 14:00:33 +02:00
input_display_len = input_display_list == -1? 0 : array_length(input_display_list);
input_fix_len = ds_list_size(inputs);
data_length = _data_length;
2023-10-18 14:58:55 +02:00
dynamic_input_cond = _dynamic_input_cond;
} #endregion
static createNewInput = -1;
static refreshDynamicInput = function() { #region
var _in = ds_list_create();
for( var i = 0; i < input_fix_len; i++ )
ds_list_add(_in, inputs[| i]);
array_resize(input_display_list, input_display_len);
for( var i = input_fix_len; i < ds_list_size(inputs); i += data_length ) {
var _active = false;
if(dynamic_input_cond & DYNA_INPUT_COND.connection)
_active |= inputs[| i].value_from != noone;
if(dynamic_input_cond & DYNA_INPUT_COND.zero) {
var _val = inputs[| i].getValue();
_active |= _val != 0 || _val != "";
}
if(_active) {
for( var j = 0; j < data_length; j++ ) {
ds_list_add(_in, inputs[| i + j]);
array_push(input_display_list, i + j);
}
} else {
for( var j = 0; j < data_length; j++ )
delete inputs[| i + j];
}
}
for( var i = 0; i < ds_list_size(_in); i++ )
_in[| i].index = i;
ds_list_destroy(inputs);
inputs = _in;
createNewInput();
2023-08-16 20:16:31 +02:00
} #endregion
2023-08-05 14:00:33 +02:00
2023-08-16 20:16:31 +02:00
static getOutput = function(junc = noone) { #region
2023-02-14 02:51:14 +01:00
for( var i = 0; i < ds_list_size(outputs); i++ ) {
if(!outputs[| i].visible) continue;
if(junc != noone && !junc.isConnectable(outputs[| i], true)) continue;
return outputs[| i];
}
return noone;
2023-08-16 20:16:31 +02:00
} #endregion
2022-01-13 05:24:03 +01:00
2023-10-27 13:55:31 +02:00
static getInput = function(junc = noone, shift = input_fix_len) { #region
for( var i = shift; i < ds_list_size(inputs); i++ ) {
2023-01-25 06:49:00 +01:00
if(!inputs[| i].visible) continue;
if(inputs[| i].value_from != noone) continue;
if(junc != noone && !inputs[| i].isConnectable(junc, true)) continue;
return inputs[| i];
}
return noone;
2023-08-16 20:16:31 +02:00
} #endregion
2023-01-25 06:49:00 +01:00
2023-08-16 20:16:31 +02:00
static getFullName = function() { #region
INLINE
return renamed? "[" + name + "] " + display_name : name;
2023-08-16 20:16:31 +02:00
} #endregion
2023-02-14 02:51:14 +01:00
2023-10-27 13:55:31 +02:00
static addInput = function(junctionFrom, shift = input_fix_len) { #region
var targ = getInput(junctionFrom, shift);
2023-01-25 06:49:00 +01:00
if(targ == noone) return;
targ.setFrom(junctionFrom);
2023-08-16 20:16:31 +02:00
} #endregion
2023-01-25 06:49:00 +01:00
2023-11-17 06:24:31 +01:00
static isActiveDynamic = function(frame = CURRENT_FRAME) { #region
if(update_on_frame) return true;
2023-11-19 14:34:56 +01:00
if(!rendered) return true;
2023-12-10 14:55:05 +01:00
force_requeue = false;
for(var i = 0; i < ds_list_size(inputs); i++)
2023-11-17 06:24:31 +01:00
if(inputs[| i].isActiveDynamic(frame)) return true;
2023-01-25 06:49:00 +01:00
return false;
2023-08-16 20:16:31 +02:00
} #endregion
2023-01-25 06:49:00 +01:00
2023-08-16 20:16:31 +02:00
static isInLoop = function() { #region
2023-02-14 13:44:46 +01:00
return array_exists(global.loop_nodes, instanceof(group));
2023-08-16 20:16:31 +02:00
} #endregion
2023-02-14 13:44:46 +01:00
2023-10-15 15:04:42 +02:00
static move = function(_x, _y, _s) { #region
2023-02-23 07:02:19 +01:00
if(x == _x && y == _y) return;
2022-01-13 05:24:03 +01:00
x = _x;
2023-08-08 18:45:00 +02:00
y = _y;
2023-07-06 19:49:16 +02:00
if(!LOADING) PROJECT.modified = true;
2023-08-16 20:16:31 +02:00
} #endregion
2023-02-14 02:51:14 +01:00
2023-08-16 20:16:31 +02:00
#region ++++ inspector update ++++
2023-03-28 06:58:28 +02:00
static inspector1Update = function() {
2023-02-14 02:51:14 +01:00
if(error_update_enabled && error_noti_update != noone)
noti_remove(error_noti_update);
error_noti_update = noone;
2023-03-28 06:58:28 +02:00
onInspector1Update();
2023-02-14 02:51:14 +01:00
}
2023-03-28 06:58:28 +02:00
static onInspector1Update = noone;
static hasInspector1Update = function() { return onInspector1Update != noone; }
2023-02-14 02:51:14 +01:00
2023-02-23 07:02:19 +01:00
static inspector2Update = function() { onInspector2Update(); }
2023-02-14 02:51:14 +01:00
static onInspector2Update = noone;
static hasInspector2Update = function() { return onInspector2Update != noone; }
2023-08-16 20:16:31 +02:00
#endregion
2022-12-23 04:45:52 +01:00
2023-08-16 20:16:31 +02:00
static stepBegin = function() { #region
2023-03-28 06:58:28 +02:00
if(use_cache) cacheArrayCheck();
2022-12-16 09:18:09 +01:00
doStepBegin();
2023-03-28 06:58:28 +02:00
if(hasInspector1Update()) inspectInput1.name = insp1UpdateTooltip;
if(hasInspector2Update()) inspectInput2.name = insp2UpdateTooltip;
2023-09-28 13:15:29 +02:00
2023-11-08 08:38:04 +01:00
if(attributes.show_update_trigger) {
if(updatedInTrigger.getValue()) {
getInputs();
update();
2023-10-06 11:51:11 +02:00
2023-11-08 08:38:04 +01:00
updatedInTrigger.setValue(false);
}
updatedOutTrigger.setValue(false);
2023-10-06 11:51:11 +02:00
}
2023-11-20 05:10:55 +01:00
if(will_setHeight) {
setHeight();
will_setHeight = false;
}
2023-08-16 20:16:31 +02:00
} #endregion
2022-12-16 09:18:09 +01:00
static doStepBegin = function() {}
2023-08-16 20:16:31 +02:00
static triggerCheck = function() { _triggerCheck(); }
2023-06-13 14:42:06 +02:00
2023-08-16 20:16:31 +02:00
static _triggerCheck = function() { #region
2023-06-04 18:28:29 +02:00
for( var i = 0; i < ds_list_size(inputs); i++ ) {
2023-10-27 13:55:31 +02:00
var _in = inputs[| i];
if(!is_instanceof(_in, NodeValue)) continue;
2023-06-04 18:28:29 +02:00
2023-10-27 13:55:31 +02:00
if(_in.type != VALUE_TYPE.trigger) continue;
if(!is_instanceof(_in.editWidget, buttonClass)) continue;
var trig = _in.getValue();
if(trig && !_in.display_data.output) {
_in.editWidget.onClick();
_in.setValue(false);
2023-06-13 14:42:06 +02:00
}
}
if(hasInspector1Update()) {
var trig = inspectInput1.getValue();
if(trig) {
2023-08-19 12:42:50 +02:00
onInspector1Update();
2023-06-13 14:42:06 +02:00
inspectInput1.setValue(false);
}
}
if(hasInspector2Update()) {
var trig = inspectInput2.getValue();
if(trig) {
2023-08-19 12:42:50 +02:00
onInspector2Update();
2023-06-13 14:42:06 +02:00
inspectInput2.setValue(false);
}
2023-06-04 18:28:29 +02:00
}
2023-08-16 20:16:31 +02:00
} #endregion
2023-06-04 18:28:29 +02:00
2022-01-13 05:24:03 +01:00
static step = function() {}
static focusStep = function() {}
2023-07-25 20:12:40 +02:00
static inspectorStep = function() {}
2022-01-13 05:24:03 +01:00
2023-10-02 10:45:30 +02:00
static getInputData = function(index, def = 0) { #region
2023-11-08 08:38:04 +01:00
INLINE
2023-10-02 10:45:30 +02:00
return array_safe_get(inputs_data, index, def);
} #endregion
2023-10-12 14:14:08 +02:00
static setInputData = function(index, value) { #region
2023-11-08 08:38:04 +01:00
INLINE
2023-10-12 14:14:08 +02:00
inputs_data[index] = value;
input_value_map[$ inputs[| index].internalName] = value;
} #endregion
2023-10-09 16:07:33 +02:00
static getInputs = function(frame = CURRENT_FRAME) { #region
inputs_data = array_verify(inputs_data, ds_list_size(inputs));
2023-10-18 14:58:55 +02:00
for(var i = 0; i < ds_list_size(inputs); i++) {
if(!is_instanceof(inputs[| i], NodeValue)) continue;
2023-10-12 14:14:08 +02:00
setInputData(i, inputs[| i].getValue(frame,,, false));
2023-10-18 14:58:55 +02:00
}
2023-10-02 14:41:44 +02:00
} #endregion
static forceUpdate = function() { #region
input_hash = "";
doUpdate();
} #endregion
static postUpdate = function(frame = CURRENT_FRAME) {}
2023-10-10 07:12:42 +02:00
static doUpdate = function(frame = CURRENT_FRAME) { #region
2023-11-01 08:10:25 +01:00
if(PROJECT.safeMode) return;
if(NODE_EXTRACT) return;
2023-10-02 14:41:44 +02:00
var render_timer = get_timer();
2023-10-03 07:14:28 +02:00
if(cached_manual || (use_cache == CACHE_USE.auto && recoverCache())) {
2023-10-02 14:41:44 +02:00
render_cached = true;
if(!is_instanceof(self, Node_Collection)) setRenderStatus(true);
2023-10-02 14:41:44 +02:00
} else {
render_cached = false;
2023-10-10 07:12:42 +02:00
getInputs(frame);
2023-10-02 14:41:44 +02:00
LOG_BLOCK_START();
2023-10-07 16:23:40 +02:00
LOG_IF(global.FLAG.render == 1, $">>>>>>>>>> DoUpdate called from {INAME} <<<<<<<<<<");
if(!is_instanceof(self, Node_Collection)) setRenderStatus(true);
var sBase = surface_get_target();
2023-10-02 14:41:44 +02:00
try {
update(frame);
2023-10-02 14:41:44 +02:00
} catch(exception) {
var sCurr = surface_get_target();
while(surface_get_target() != sBase)
surface_reset_target();
2023-02-14 02:51:14 +01:00
2023-10-02 14:41:44 +02:00
log_warning("RENDER", exception_print(exception), self);
}
2023-02-14 02:51:14 +01:00
}
2023-03-28 06:58:28 +02:00
postUpdate(frame);
2023-10-03 07:14:28 +02:00
cached_manual = false;
2023-10-02 10:45:30 +02:00
2023-10-03 11:27:36 +02:00
if(!use_cache && PROJECT.onion_skin.enabled) {
2023-07-08 20:29:23 +02:00
for( var i = 0; i < ds_list_size(outputs); i++ ) {
if(outputs[| i].type != VALUE_TYPE.surface) continue;
cacheCurrentFrame(outputs[| i].getValue());
break;
}
}
2023-03-28 06:58:28 +02:00
if(hasInspector1Update()) {
var trigger = inspectInput1.getValue();
if(trigger) onInspector1Update();
}
if(hasInspector2Update()) {
var trigger = inspectInput2.getValue();
if(trigger) onInspector2Update();
}
2023-09-28 13:15:29 +02:00
2023-10-06 11:51:11 +02:00
updatedOutTrigger.setValue(true);
2023-10-03 07:14:28 +02:00
if(!is_instanceof(self, Node_Collection))
2023-10-03 07:14:28 +02:00
render_time = get_timer() - render_timer;
2023-12-03 05:02:04 +01:00
setHeight();
LOG_BLOCK_END();
2023-08-16 20:16:31 +02:00
} #endregion
2023-02-14 02:51:14 +01:00
static cacheCheck = function() { #region
INLINE
if(cache_group) cache_group.enableNodeGroup();
if(group != noone) group.cacheCheck();
} #endregion
2023-08-16 20:16:31 +02:00
static valueUpdate = function(index) { #region
2023-02-14 02:51:14 +01:00
if(error_update_enabled && error_noti_update == noone)
error_noti_update = noti_error(getFullName() + " node require manual execution.",, self);
onValueUpdate(index);
2023-11-20 05:10:55 +01:00
if(is_dynamic_input) will_setHeight = true;
cacheCheck();
2023-11-02 14:37:13 +01:00
} #endregion
static valueFromUpdate = function(index) { #region
onValueFromUpdate(index);
2023-11-20 05:10:55 +01:00
if(is_dynamic_input) will_setHeight = true;
cacheCheck();
2023-08-16 20:16:31 +02:00
} #endregion
2022-01-13 05:24:03 +01:00
2023-02-14 02:51:14 +01:00
static onValueUpdate = function(index = 0) {}
2023-01-09 03:14:20 +01:00
static onValueFromUpdate = function(index) {}
2022-01-13 05:24:03 +01:00
2023-08-16 20:16:31 +02:00
static triggerRender = function() { #region
LOG_BLOCK_START();
LOG_IF(global.FLAG.render == 1, $"Trigger render for {INAME}");
2023-03-28 06:58:28 +02:00
2023-03-26 07:13:36 +02:00
setRenderStatus(false);
2023-10-08 04:14:35 +02:00
RENDER_PARTIAL
2023-03-26 07:13:36 +02:00
2023-06-01 10:32:21 +02:00
if(is_instanceof(group, Node_Collection) && group.reset_all_child) {
group.resetRender();
} else {
resetRender();
var nodes = getNextNodesRaw();
for(var i = 0; i < array_length(nodes); i++)
nodes[i].triggerRender();
}
LOG_BLOCK_END();
2023-08-16 20:16:31 +02:00
} #endregion
2023-06-01 10:32:21 +02:00
2023-12-22 04:15:04 +01:00
static clearTopoSorted = function() { INLINE topoSorted = false; }
2023-10-07 16:23:40 +02:00
static forwardPassiveDynamic = function() { #region
2023-12-22 04:15:04 +01:00
rendered = false;
for( var i = 0, n = ds_list_size(outputs); i < n; i++ ) {
var _outp = outputs[| i];
2023-12-19 14:30:34 +01:00
for(var j = 0; j < array_length(_outp.value_to); j++) {
var _to = _outp.value_to[j];
2023-10-07 16:23:40 +02:00
if(!_to.node.active || _to.value_from != _outp) continue;
2023-10-07 16:23:40 +02:00
_to.node.passiveDynamic = true;
2023-12-22 04:15:04 +01:00
_to.node.rendered = false;
}
}
2023-10-06 11:51:11 +02:00
} #endregion
2023-10-08 08:02:38 +02:00
static resetRender = function(_clearCache = false) { #region
setRenderStatus(false);
if(_clearCache) clearInputCache();
} #endregion
2023-12-22 04:15:04 +01:00
static isLeaf = function(list = noone) { #region
2023-10-27 13:55:31 +02:00
for( var i = 0, n = ds_list_size(inputs); i < n; i++ ) {
var _inp = inputs[| i];
2023-12-22 04:15:04 +01:00
if(!_inp.isLeaf(list)) return false;
2023-10-27 13:55:31 +02:00
}
return true;
} #endregion
2023-11-04 13:22:52 +01:00
static isRenderActive = function() { return renderActive || (PREFERENCES.render_all_export && IS_RENDERING); }
2023-06-01 10:32:21 +02:00
2023-08-16 20:16:31 +02:00
static isRenderable = function(log = false) { #region //Check if every input is ready (updated)
2023-03-26 07:13:36 +02:00
if(!active) return false;
2023-06-17 14:30:49 +02:00
if(!isRenderActive()) return false;
2022-01-24 02:21:25 +01:00
2023-10-27 13:55:31 +02:00
for(var j = 0; j < ds_list_size(inputs); j++)
if(!inputs[| j].isRendered()) return false;
2022-01-24 02:21:25 +01:00
return true;
2023-08-16 20:16:31 +02:00
} #endregion
2022-01-24 02:21:25 +01:00
2023-12-22 04:15:04 +01:00
static getPreviousNodes = function() { #region
var prev = [];
for( var i = 0, n = ds_list_size(inputs); i < n; i++ ) {
var _in = inputs[| i];
if(_in.value_from != noone) {
if(in_VFX && !_in.value_from.node.in_VFX) {
array_push(in_VFX.prev_nodes, _in.value_from.node);
array_push(prev, in_VFX);
continue;
}
array_push_unique(prev, _in.value_from.node);
}
if(_in.value_from_loop != noone)
array_push_unique(prev, _in.value_from_loop);
}
onGetPreviousNodes(prev);
return prev;
} #endregion
static onGetPreviousNodes = function(arr) {}
2023-08-16 20:16:31 +02:00
static getNextNodes = function() { #region
2023-03-28 06:58:28 +02:00
var nodes = [];
2023-06-01 10:32:21 +02:00
var nodeNames = [];
2023-03-28 06:58:28 +02:00
LOG_BLOCK_START();
LOG_IF(global.FLAG.render == 1, $"→→→→→ Call get next node from: {INAME}");
LOG_BLOCK_START();
2022-01-13 05:24:03 +01:00
for(var i = 0; i < ds_list_size(outputs); i++) {
2023-03-26 07:13:36 +02:00
var _ot = outputs[| i];
2023-12-22 04:15:04 +01:00
if(!_ot.forward) continue;
2023-03-26 07:13:36 +02:00
2023-12-19 14:30:34 +01:00
for( var j = 0, n = array_length(_ot.value_to_loop); j < n; j++ ) {
var _to = _ot.value_to_loop[j];
if(!_to.active) continue;
if(!_to.bypassNextNode()) continue;
LOG_BLOCK_END();
LOG_BLOCK_END();
return _to.getNextNodes();
}
2023-06-01 10:32:21 +02:00
var _tos = _ot.getJunctionTo();
for( var j = 0; j < array_length(_tos); j++ ) {
var _to = _tos[j];
2023-03-26 07:13:36 +02:00
2023-03-28 06:58:28 +02:00
array_push(nodes, _to.node);
2023-06-01 10:32:21 +02:00
array_push(nodeNames, _to.node.internalName);
//LOG_IF(global.FLAG.render == 1, $"→→ Check output: {_ot.name} connect to node {_to.node.internalName}");
2022-01-13 05:24:03 +01:00
}
2023-03-26 07:13:36 +02:00
}
2023-03-28 06:58:28 +02:00
LOG_IF(global.FLAG.render == 1, $"→→ Push {nodeNames} to queue.");
2023-06-01 10:32:21 +02:00
LOG_BLOCK_END();
LOG_BLOCK_END();
2023-03-28 06:58:28 +02:00
return nodes;
2023-08-16 20:16:31 +02:00
} #endregion
2022-01-13 05:24:03 +01:00
2023-10-19 11:34:29 +02:00
static getNextNodesRaw = function() { #region
var nodes = [];
for(var i = 0; i < ds_list_size(outputs); i++) {
var _ot = outputs[| i];
if(!_ot.forward) continue;
if(_ot.type == VALUE_TYPE.node) continue;
2023-12-19 14:30:34 +01:00
for( var j = 0, n = array_length(_ot.value_to_loop); j < n; j++ ) {
var _to = _ot.value_to_loop[j];
if(!_to.active) continue;
if(!_to.bypassNextNode()) continue;
return _to.getNextNodes();
}
2023-10-19 11:34:29 +02:00
var _tos = _ot.getJunctionTo();
for( var j = 0; j < array_length(_tos); j++ )
array_push(nodes, _tos[j].node);
}
return nodes;
} #endregion
2023-08-16 20:16:31 +02:00
static isTerminal = function() { #region
2023-07-21 12:40:20 +02:00
for( var i = 0; i < ds_list_size(outputs); i++ ) {
var _to = outputs[| i].getJunctionTo();
if(array_length(_to)) return false;
}
return true;
2023-08-16 20:16:31 +02:00
} #endregion
2023-07-21 12:40:20 +02:00
2022-09-23 13:28:42 +02:00
static onInspect = function() {}
2023-08-16 20:16:31 +02:00
static setRenderStatus = function(result) { #region
2023-11-08 08:38:04 +01:00
INLINE
2023-10-08 08:02:38 +02:00
if(rendered == result) return;
LOG_LINE_IF(global.FLAG.render == 1, $"Set render status for {INAME} : {result}");
2022-12-12 09:08:03 +01:00
rendered = result;
2023-08-16 20:16:31 +02:00
} #endregion
2022-01-23 04:08:16 +01:00
2023-08-16 20:16:31 +02:00
static pointIn = function(_x, _y, _mx, _my, _s) { #region
2022-11-01 03:06:03 +01:00
var xx = x * _s + _x;
var yy = y * _s + _y;
2022-01-13 05:24:03 +01:00
2022-11-01 03:06:03 +01:00
return point_in_rectangle(_mx, _my, xx, yy, xx + w * _s, yy + h * _s);
2023-08-16 20:16:31 +02:00
} #endregion
2022-01-13 05:24:03 +01:00
2023-08-16 20:16:31 +02:00
static cullCheck = function(_x, _y, _s, minx, miny, maxx, maxy) { #region
2023-06-17 14:30:49 +02:00
var x0 = x * _s + _x;
var y0 = y * _s + _y;
var x1 = (x + w) * _s + _x;
var y1 = (y + h) * _s + _y;
draw_graph_culled = !rectangle_in_rectangle(minx, miny, maxx, maxy, x0, y0, x1, y1);
2023-08-16 20:16:31 +02:00
} #endregion
2023-06-17 14:30:49 +02:00
2023-08-16 20:16:31 +02:00
static preDraw = function(_x, _y, _s) { #region
2022-01-26 06:57:34 +01:00
var xx = x * _s + _x;
var yy = y * _s + _y;
2022-09-21 06:09:40 +02:00
var jun;
2022-12-13 09:20:36 +01:00
2023-03-28 06:58:28 +02:00
var inspCount = hasInspector1Update() + hasInspector2Update();
var ind = 1;
if(hasInspector1Update()) {
inspectInput1.x = xx + w * _s * ind / (inspCount + 1);
inspectInput1.y = yy;
ind++;
}
if(hasInspector2Update()) {
inspectInput2.x = xx + w * _s * ind / (inspCount + 1);
inspectInput2.y = yy;
ind++;
}
2023-10-06 11:51:11 +02:00
updatedInTrigger.x = xx;
updatedInTrigger.y = yy + 10;
updatedOutTrigger.x = xx + w * _s;
updatedOutTrigger.y = yy + 10;
2023-09-28 13:15:29 +02:00
2023-11-30 03:18:25 +01:00
if(in_cache_len != ds_list_size(inputs) || out_cache_len != ds_list_size(outputs)) {
updateIO();
in_cache_len = ds_list_size(inputs);
out_cache_len = ds_list_size(outputs);
}
2023-10-07 09:09:18 +02:00
var _iny = yy + ui(junction_draw_pad_y) * _s;
2023-11-30 03:18:25 +01:00
for(var i = 0; i < inputs_amount; i++) {
var idx = inputs_index[i];
jun = inputs[| idx];
2022-01-26 06:57:34 +01:00
jun.x = xx;
2023-10-07 09:09:18 +02:00
jun.y = _iny;
_iny += 24 * _s * jun.isVisible();
}
2023-11-30 03:18:25 +01:00
xx = xx + w * _s;
2023-10-07 09:09:18 +02:00
var _outy = yy + ui(junction_draw_pad_y) * _s;
2023-11-30 03:18:25 +01:00
for(var i = 0; i < outputs_amount; i++) {
var idx = outputs_index[i];
2022-12-13 09:20:36 +01:00
jun = outputs[| idx];
2022-01-26 06:57:34 +01:00
jun.x = xx;
2023-10-07 09:09:18 +02:00
jun.y = _outy;
_outy += 24 * _s * jun.isVisible();
}
2023-10-07 09:09:18 +02:00
onPreDraw(_x, _y, _s, _iny, _outy);
2023-08-16 20:16:31 +02:00
} #endregion
2023-10-07 09:09:18 +02:00
static onPreDraw = function(_x, _y, _s, _iny, _outy) {}
2023-10-12 07:07:24 +02:00
static isHighlightingInGraph = function() { #region
2023-11-27 11:40:28 +01:00
var high = struct_try_get(display_parameter, "highlight", 0);
2023-10-12 07:07:24 +02:00
var _selc = active_draw_index == 0 || branch_drawing;
return !high || _selc;
} #endregion
2023-10-16 07:25:22 +02:00
static getColor = function() { #region
2023-11-08 08:38:04 +01:00
INLINE
return attributes.color == -1? color : attributes.color;
2023-10-16 07:25:22 +02:00
} #endregion
2023-08-16 20:16:31 +02:00
static drawNodeBase = function(xx, yy, _s) { #region
2023-06-17 14:30:49 +02:00
if(draw_graph_culled) return;
2023-02-14 02:51:14 +01:00
if(!active) return;
2023-10-12 07:07:24 +02:00
2023-02-19 13:49:20 +01:00
var aa = 0.25 + 0.5 * renderActive;
2023-10-12 07:07:24 +02:00
if(!isHighlightingInGraph()) aa *= 0.25;
2023-10-16 07:25:22 +02:00
var cc = getColor();
2023-10-12 07:07:24 +02:00
2023-10-15 15:04:42 +02:00
draw_sprite_stretched_ext(bg_spr, 0, xx, yy, w * _s, h * _s, cc, aa);
2023-08-16 20:16:31 +02:00
} #endregion
2022-01-13 05:24:03 +01:00
2023-08-16 20:16:31 +02:00
static drawGetBbox = function(xx, yy, _s) { #region
var pad_label = draw_name && display_parameter.avoid_label;
var _w = w;
var _h = h;
2023-08-16 20:16:31 +02:00
_w *= display_parameter.preview_scale / 100 * _s;
_h *= display_parameter.preview_scale / 100 * _s;
_w -= draw_padding * 2;
_h -= draw_padding * 2 + 20 * pad_label;
2023-08-16 20:16:31 +02:00
var _xc = xx + w * _s / 2;
var _yc = yy + (h * _s + 20 * pad_label) / 2;
var x0 = _xc - _w / 2;
var x1 = _xc + _w / 2;
var y0 = _yc - _h / 2;
var y1 = _yc + _h / 2;
2023-01-04 02:30:04 +01:00
2023-06-13 14:42:06 +02:00
return BBOX().fromPoints(x0, y0, x1, y1);
2023-08-16 20:16:31 +02:00
} #endregion
2023-01-04 02:30:04 +01:00
2023-08-16 20:16:31 +02:00
static drawNodeName = function(xx, yy, _s) { #region
2023-06-17 14:30:49 +02:00
if(draw_graph_culled) return;
2023-02-14 02:51:14 +01:00
if(!active) return;
2023-02-19 13:49:20 +01:00
2023-01-04 02:30:04 +01:00
draw_name = false;
var _name = renamed? display_name : name;
2023-02-14 02:51:14 +01:00
if(_name == "") return;
2023-01-25 06:49:00 +01:00
if(_s < 0.75) return;
2023-01-04 02:30:04 +01:00
draw_name = true;
2022-12-10 05:06:01 +01:00
2023-02-19 13:49:20 +01:00
var aa = 0.25 + 0.5 * renderActive;
2023-10-12 07:07:24 +02:00
if(!isHighlightingInGraph()) aa *= 0.25;
2023-10-16 07:25:22 +02:00
var cc = getColor();
2023-10-12 07:07:24 +02:00
2023-10-15 15:04:42 +02:00
draw_sprite_stretched_ext(THEME.node_bg_name, 0, xx, yy, w * _s, ui(20), cc, aa);
2022-12-10 05:06:01 +01:00
var cc = COLORS._main_text;
2023-10-31 05:30:42 +01:00
if(PREFERENCES.node_show_render_status && !rendered)
2023-03-26 07:13:36 +02:00
cc = isRenderable()? COLORS._main_value_positive : COLORS._main_value_negative;
2022-12-12 09:08:03 +01:00
2022-12-10 05:06:01 +01:00
draw_set_text(f_p1, fa_left, fa_center, cc);
2023-12-29 14:30:54 +01:00
if(hasInspector1Update()) icon = THEME.refresh_16;
2022-12-12 09:08:03 +01:00
var ts = clamp(power(_s, 0.5), 0.5, 1);
2023-01-04 02:30:04 +01:00
2023-02-19 13:49:20 +01:00
var aa = 0.5 + 0.5 * renderActive;
2023-10-12 07:07:24 +02:00
if(!isHighlightingInGraph()) aa *= 0.25;
2023-02-19 13:49:20 +01:00
draw_set_alpha(aa);
2023-01-04 02:30:04 +01:00
if(icon && _s > 0.75) {
2023-02-19 13:49:20 +01:00
draw_sprite_ui_uniform(icon, 0, xx + ui(12), yy + ui(10),,, aa);
2023-11-20 13:21:50 +01:00
draw_text_cut(round(xx + ui(24)), round(yy + ui(10)), _name, w * _s - ui(24), ts);
2023-01-04 02:30:04 +01:00
} else
2023-11-20 13:21:50 +01:00
draw_text_cut(round(xx + ui(8)), round(yy + ui(10)), _name, w * _s - ui(8), ts);
2023-02-19 13:49:20 +01:00
draw_set_alpha(1);
2023-08-16 20:16:31 +02:00
} #endregion
2022-01-13 05:24:03 +01:00
2023-08-16 20:16:31 +02:00
static drawJunctions = function(_x, _y, _mx, _my, _s) { #region
2023-02-14 02:51:14 +01:00
if(!active) return;
2022-01-13 05:24:03 +01:00
var hover = noone;
2022-09-23 13:28:42 +02:00
var amo = input_display_list == -1? ds_list_size(inputs) : array_length(input_display_list);
2022-09-21 06:09:40 +02:00
var jun;
2023-11-17 06:24:31 +01:00
gpu_set_texfilter(true);
2022-01-13 05:24:03 +01:00
for(var i = 0; i < amo; i++) {
2022-09-27 06:37:28 +02:00
var ind = getInputJunctionIndex(i);
if(ind == noone) continue;
jun = ds_list_get(inputs, ind, noone);
2023-02-14 02:51:14 +01:00
if(jun == noone || is_undefined(jun)) continue;
2022-01-13 05:24:03 +01:00
2022-09-27 06:37:28 +02:00
if(jun.drawJunction(_s, _mx, _my))
2022-01-26 06:57:34 +01:00
hover = jun;
2022-01-13 05:24:03 +01:00
}
for(var i = 0; i < ds_list_size(outputs); i++) {
2022-09-21 06:09:40 +02:00
jun = outputs[| i];
2022-01-13 05:24:03 +01:00
2022-09-27 06:37:28 +02:00
if(jun.drawJunction(_s, _mx, _my))
2022-01-26 06:57:34 +01:00
hover = jun;
2022-01-13 05:24:03 +01:00
}
2023-03-28 06:58:28 +02:00
if(hasInspector1Update() && inspectInput1.drawJunction(_s, _mx, _my))
hover = inspectInput1;
if(hasInspector2Update() && inspectInput2.drawJunction(_s, _mx, _my))
hover = inspectInput2;
2023-10-06 11:51:11 +02:00
if(attributes.show_update_trigger) {
if(updatedInTrigger.drawJunction(_s, _mx, _my)) hover = updatedInTrigger;
if(updatedOutTrigger.drawJunction(_s, _mx, _my)) hover = updatedOutTrigger;
}
2023-09-28 13:15:29 +02:00
2023-10-07 09:09:18 +02:00
onDrawJunctions(_x, _y, _mx, _my, _s);
2023-11-17 06:24:31 +01:00
gpu_set_texfilter(false);
2022-01-13 05:24:03 +01:00
return hover;
2023-08-16 20:16:31 +02:00
} #endregion
2022-01-13 05:24:03 +01:00
2023-10-07 09:09:18 +02:00
static onDrawJunctions = function(_x, _y, _mx, _my, _s) {}
2023-08-16 20:16:31 +02:00
static drawJunctionNames = function(_x, _y, _mx, _my, _s) { #region
2023-06-17 14:30:49 +02:00
if(draw_graph_culled) return;
2023-02-14 02:51:14 +01:00
if(!active) return;
2023-10-15 15:04:42 +02:00
2022-09-27 06:37:28 +02:00
var amo = input_display_list == -1? ds_list_size(inputs) : array_length(input_display_list);
var jun;
var xx = x * _s + _x;
var yy = y * _s + _y;
2023-10-15 15:04:42 +02:00
var _hov = PANEL_GRAPH.pHOVER && (PANEL_GRAPH.node_hovering == noone || PANEL_GRAPH.node_hovering == self);
show_input_name = _hov && point_in_rectangle(_mx, _my, xx - 8 * _s, yy + 20 * _s, xx + 8 * _s, yy + h * _s);
show_output_name = _hov && point_in_rectangle(_mx, _my, xx + (w - 8) * _s, yy + 20 * _s, xx + (w + 8) * _s, yy + h * _s);
2022-09-27 06:37:28 +02:00
if(show_input_name) {
for(var i = 0; i < amo; i++) {
var ind = getInputJunctionIndex(i);
if(ind == noone) continue;
2023-03-07 14:29:47 +01:00
if(!inputs[| ind]) continue;
2022-09-27 06:37:28 +02:00
inputs[| ind].drawNameBG(_s);
}
for(var i = 0; i < amo; i++) {
var ind = getInputJunctionIndex(i);
if(ind == noone) continue;
2023-03-07 14:29:47 +01:00
if(!inputs[| ind]) continue;
2022-09-27 06:37:28 +02:00
inputs[| ind].drawName(_s, _mx, _my);
}
}
if(show_output_name) {
2023-02-23 07:02:19 +01:00
for(var i = 0; i < ds_list_size(outputs); i++)
2022-09-27 06:37:28 +02:00
outputs[| i].drawNameBG(_s);
2023-02-23 07:02:19 +01:00
for(var i = 0; i < ds_list_size(outputs); i++)
2022-09-27 06:37:28 +02:00
outputs[| i].drawName(_s, _mx, _my);
}
2023-03-28 06:58:28 +02:00
if(hasInspector1Update() && PANEL_GRAPH.pHOVER && point_in_circle(_mx, _my, inspectInput1.x, inspectInput1.y, 10)) {
inspectInput1.drawNameBG(_s);
inspectInput1.drawName(_s, _mx, _my);
}
if(hasInspector2Update() && PANEL_GRAPH.pHOVER && point_in_circle(_mx, _my, inspectInput2.x, inspectInput2.y, 10)) {
inspectInput2.drawNameBG(_s);
inspectInput2.drawName(_s, _mx, _my);
}
2023-08-16 20:16:31 +02:00
} #endregion
2022-09-27 06:37:28 +02:00
2023-08-31 18:49:57 +02:00
static drawConnections = function(params = {}) { #region
2023-02-14 02:51:14 +01:00
if(!active) return;
var hovering = noone;
2023-03-05 07:16:44 +01:00
var drawLineIndex = 1;
2023-11-27 11:40:28 +01:00
var high = struct_try_get(params, "highlight", 0);
var bg = struct_try_get(params, "bg", c_black);
2023-11-30 03:18:25 +01:00
2023-03-05 07:16:44 +01:00
for(var i = 0; i < ds_list_size(outputs); i++) {
var jun = outputs[| i];
var connected = false;
2023-12-19 14:30:34 +01:00
for( var j = 0; j < array_length(jun.value_to); j++ ) {
if(jun.value_to[j].value_from == jun)
2023-03-05 07:16:44 +01:00
connected = true;
}
if(connected) {
jun.drawLineIndex = drawLineIndex;
drawLineIndex += 0.5;
}
2023-11-27 11:40:28 +01:00
if(high) {
jun.draw_blend_color = bg;
jun.draw_blend = PREFERENCES.connection_line_highlight_fade;
2023-12-01 05:49:44 +01:00
} else {
jun.draw_blend_color = bg;
jun.draw_blend = -1;
2023-11-27 11:40:28 +01:00
}
2023-03-05 07:16:44 +01:00
}
2023-03-28 06:58:28 +02:00
var st = 0;
2023-06-17 14:30:49 +02:00
if(hasInspector1Update()) st = -1;
2023-03-28 06:58:28 +02:00
if(hasInspector2Update()) st = -2;
2023-11-30 03:18:25 +01:00
var _inputs = array_create(ds_list_size(inputs));
var _len = 0;
2023-03-05 07:16:44 +01:00
var drawLineIndex = 1;
2023-06-17 14:30:49 +02:00
for(var i = st; i < ds_list_size(inputs); i++) {
var jun;
if(i == -1) jun = inspectInput1;
else if(i == -2) jun = inspectInput2;
else jun = inputs[| i];
2023-11-27 11:40:28 +01:00
if(high) {
jun.draw_blend_color = bg;
jun.draw_blend = PREFERENCES.connection_line_highlight_fade;
2023-12-01 05:49:44 +01:00
} else {
jun.draw_blend_color = bg;
jun.draw_blend = -1;
2023-11-27 11:40:28 +01:00
}
2023-10-27 13:55:31 +02:00
if(is_instanceof(jun, NodeModule)) {
jun.drawConnections(params, _inputs);
continue;
}
if(jun.isLeaf()) continue;
2023-06-17 14:30:49 +02:00
if(!jun.value_from.node.active) continue;
if(!jun.isVisible()) continue;
2023-11-30 03:18:25 +01:00
if(i >= 0) _inputs[_len++] = jun;
2023-06-17 14:30:49 +02:00
}
2023-11-30 03:18:25 +01:00
for( var i = 0; i < _len; i++ ) {
2023-10-27 13:55:31 +02:00
var jun = _inputs[i];
2023-03-28 06:58:28 +02:00
2023-11-30 03:18:25 +01:00
jun.drawLineIndex = 1 + (i > _len / 2? (_len - 1 - i) : i) * 0.5;
2023-08-31 18:49:57 +02:00
var hov = jun.drawConnections(params);
2023-07-25 20:12:40 +02:00
if(hov) hovering = hov;
2022-01-13 05:24:03 +01:00
}
2023-10-06 11:51:11 +02:00
if(attributes.show_update_trigger) {
if(updatedInTrigger.drawConnections(params)) hovering = updatedInTrigger;
if(updatedOutTrigger.drawConnections(params)) hovering = updatedOutTrigger;
}
return hovering;
2023-08-16 20:16:31 +02:00
} #endregion
2022-01-13 05:24:03 +01:00
2023-08-16 20:16:31 +02:00
static getGraphPreviewSurface = function() { #region
2023-08-10 11:51:16 +02:00
var _node = outputs[| preview_channel];
2023-10-08 08:02:38 +02:00
if(!is_instanceof(_node, NodeValue)) return noone;
2023-09-09 13:52:16 +02:00
switch(_node.type) {
case VALUE_TYPE.surface :
case VALUE_TYPE.dynaSurface :
2023-12-06 10:37:05 +01:00
var val = _node.getValue();
return val;
2023-09-09 13:52:16 +02:00
}
return noone;
2023-08-16 20:16:31 +02:00
} #endregion
2023-08-10 11:51:16 +02:00
2023-08-16 20:16:31 +02:00
static drawPreview = function(xx, yy, _s) { #region
2023-06-17 14:30:49 +02:00
if(draw_graph_culled) return;
2023-02-14 02:51:14 +01:00
if(!active) return;
2023-02-20 10:16:31 +01:00
2023-08-10 11:51:16 +02:00
var surf = getGraphPreviewSurface();
if(surf == noone) return;
2023-02-20 10:16:31 +01:00
2023-01-25 06:49:00 +01:00
preview_amount = 0;
2022-01-13 05:24:03 +01:00
if(is_array(surf)) {
if(array_length(surf) == 0) return;
2023-01-25 06:49:00 +01:00
preview_amount = array_length(surf);
2022-01-13 05:24:03 +01:00
if(preview_speed != 0) {
preview_index += preview_speed;
if(preview_index <= 0)
preview_index = array_length(surf) - 1;
}
if(floor(preview_index) > array_length(surf) - 1) preview_index = 0;
surf = surf[preview_index];
2022-01-13 05:24:03 +01:00
}
2023-02-14 02:51:14 +01:00
preview_surface = is_surface(surf)? surf : noone;
2023-03-26 07:13:36 +02:00
if(preview_surface == noone) return;
2022-11-03 11:44:49 +01:00
2023-08-16 20:16:31 +02:00
var bbox = drawGetBbox(xx, yy, _s);
var aa = 0.5 + 0.5 * renderActive;
2023-11-27 11:40:28 +01:00
if(!isHighlightingInGraph()) aa *= 0.25;
2023-02-19 13:49:20 +01:00
draw_surface_bbox(preview_surface, bbox, c_white, aa * graph_preview_alpha);
2023-08-16 20:16:31 +02:00
} #endregion
2023-01-25 06:49:00 +01:00
2023-08-16 20:16:31 +02:00
static getNodeDimension = function(showFormat = true) { #region
2023-11-27 11:40:28 +01:00
if(!is_surface(preview_surface))
return preview_array;
2023-01-25 06:49:00 +01:00
2023-09-08 21:37:36 +02:00
var pw = surface_get_width_safe(preview_surface);
var ph = surface_get_height_safe(preview_surface);
2023-03-19 09:17:39 +01:00
var format = surface_get_format(preview_surface);
2023-11-27 11:40:28 +01:00
var txt = $"[{pw} x {ph} ";
if(preview_amount) txt = $"{preview_amount} x {txt}";
2023-03-19 09:17:39 +01:00
switch(format) {
2023-04-05 20:13:27 +02:00
case surface_rgba4unorm : txt += showFormat? "4RGBA" : "4R"; break;
case surface_rgba8unorm : txt += showFormat? "8RGBA" : "8R"; break;
case surface_rgba16float : txt += showFormat? "16RGBA" : "16R"; break;
case surface_rgba32float : txt += showFormat? "32RGBA" : "32R"; break;
case surface_r8unorm : txt += showFormat? "8BW" : "8B"; break;
case surface_r16float : txt += showFormat? "16BW" : "16B"; break;
case surface_r32float : txt += showFormat? "32BW" : "32B"; break;
2023-03-19 09:17:39 +01:00
}
2023-04-05 20:13:27 +02:00
2023-03-19 09:17:39 +01:00
txt += "]";
2023-01-25 06:49:00 +01:00
return txt;
2023-08-16 20:16:31 +02:00
} #endregion
2023-01-25 06:49:00 +01:00
2023-08-16 20:16:31 +02:00
static drawDimension = function(xx, yy, _s) { #region
2023-06-17 14:30:49 +02:00
if(draw_graph_culled) return;
2023-02-14 02:51:14 +01:00
if(!active) return;
2023-01-25 06:49:00 +01:00
if(_s * w < 64) return;
2023-07-23 20:21:35 +02:00
draw_set_text(f_p2, fa_center, fa_top, COLORS.panel_graph_node_dimension);
2023-01-25 06:49:00 +01:00
var tx = xx + w * _s / 2;
2023-07-23 20:21:35 +02:00
var ty = yy + (h + 4) * _s - 2;
2023-01-25 06:49:00 +01:00
if(struct_get(display_parameter, "show_dimension")) {
2023-04-05 20:13:27 +02:00
var txt = string(getNodeDimension(_s > 0.65));
2023-01-25 06:49:00 +01:00
draw_text(round(tx), round(ty), txt);
2023-07-23 20:21:35 +02:00
ty += string_height(txt) - 2;
2023-01-25 06:49:00 +01:00
}
2023-07-23 20:21:35 +02:00
draw_set_font(f_p3);
if(struct_get(display_parameter, "show_compute")) {
2023-10-02 14:41:44 +02:00
var rt = 0, unit = "";
if(render_time == 0) {
draw_set_color(COLORS._main_text_sub);
unit = "us";
} else if(render_time < 1000) {
2023-01-25 06:49:00 +01:00
rt = round(render_time / 10) * 10;
unit = "us";
draw_set_color(COLORS.speed[2]);
} else if(render_time < 1000000) {
rt = string_format(render_time / 1000, -1, 2);
unit = "ms";
draw_set_color(COLORS.speed[1]);
} else {
rt = string_format(render_time / 1000000, -1, 2);
unit = "s";
draw_set_color(COLORS.speed[0]);
}
2023-10-02 14:41:44 +02:00
2023-10-07 16:23:40 +02:00
if(render_cached) draw_set_color(COLORS._main_text_sub);
2023-10-02 14:41:44 +02:00
2023-01-25 06:49:00 +01:00
draw_text(round(tx), round(ty), string(rt) + " " + unit);
2022-01-13 05:24:03 +01:00
}
2023-08-16 20:16:31 +02:00
} #endregion
2022-01-13 05:24:03 +01:00
static groupCheck = function(_x, _y, _s, _mx, _my) {}
2023-11-16 02:49:52 +01:00
static drawNodeBG = function(_x, _y, _mx, _my, _s, display_parameter = noone) { return false; }
2023-11-02 12:43:00 +01:00
2023-09-28 13:15:29 +02:00
static drawNode = function(_x, _y, _mx, _my, _s, display_parameter = noone) { #region
2023-06-17 14:30:49 +02:00
if(draw_graph_culled) return;
2023-02-14 02:51:14 +01:00
if(!active) return;
2023-09-28 13:15:29 +02:00
if(display_parameter != noone)
self.display_parameter = display_parameter;
2022-01-13 05:24:03 +01:00
var xx = x * _s + _x;
var yy = y * _s + _y;
2023-03-26 07:13:36 +02:00
preview_mx = _mx;
preview_my = _my;
2023-02-14 02:51:14 +01:00
if(value_validation[VALIDATION.error] || error_noti_update != noone)
2023-01-01 02:06:02 +01:00
draw_sprite_stretched_ext(THEME.node_glow, 0, xx - 9, yy - 9, w * _s + 18, h * _s + 18, COLORS._main_value_negative, 1);
2022-01-13 05:24:03 +01:00
drawNodeBase(xx, yy, _s);
2023-01-25 06:49:00 +01:00
drawDimension(xx, yy, _s);
2023-01-01 02:06:02 +01:00
2023-12-03 05:02:04 +01:00
if(previewable) {
2023-12-04 12:09:31 +01:00
if(preview_draw) drawPreview(xx, yy, _s);
2023-12-10 02:48:10 +01:00
try {
onDrawNode(xx, yy, _mx, _my, _s, PANEL_GRAPH.node_hovering == self, PANEL_GRAPH.getFocusingNode() == self);
} catch(e) {
log_warning("NODE onDRAW", exception_print(e));
}
2023-12-03 05:02:04 +01:00
} else {
var bbox = drawGetBbox(xx, yy, _s);
draw_sprite_ext(THEME.preview_hide, 0, bbox.xc, bbox.yc, _s, _s, 0, c_white, 0.25);
}
2022-12-16 09:18:09 +01:00
drawNodeName(xx, yy, _s);
2023-03-05 07:16:44 +01:00
2022-01-13 05:24:03 +01:00
if(active_draw_index > -1) {
2023-01-25 06:49:00 +01:00
draw_sprite_stretched_ext(bg_sel_spr, 0, xx, yy, round(w * _s), round(h * _s), active_draw_index > 1? COLORS.node_border_file_drop : COLORS._main_accent, 1);
2022-01-13 05:24:03 +01:00
active_draw_index = -1;
}
2023-11-27 11:40:28 +01:00
if(draw_droppable) {
2023-03-26 07:13:36 +02:00
draw_sprite_stretched_ext(THEME.ui_panel_active, 0, xx, yy, w * _s, h * _s, COLORS._main_value_positive, 1);
2023-11-27 11:40:28 +01:00
draw_droppable = false;
}
2023-03-26 07:13:36 +02:00
2022-09-21 06:09:40 +02:00
return drawJunctions(xx, yy, _mx, _my, _s);
2023-08-16 20:16:31 +02:00
} #endregion
2023-03-28 06:58:28 +02:00
2023-01-25 06:49:00 +01:00
static onDrawNodeBehind = function(_x, _y, _mx, _my, _s) {}
2023-03-28 06:58:28 +02:00
2023-03-05 07:16:44 +01:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover = false, _focus = false) {}
2022-01-13 05:24:03 +01:00
static onDrawHover = function(_x, _y, _mx, _my, _s) {}
2023-08-16 20:16:31 +02:00
static drawBadge = function(_x, _y, _s) { #region
2023-02-14 02:51:14 +01:00
if(!active) return;
2022-01-13 05:24:03 +01:00
var xx = x * _s + _x + w * _s;
var yy = y * _s + _y;
2023-03-28 06:58:28 +02:00
badgePreview = lerp_float(badgePreview, !!previewing, 2);
badgeInspect = lerp_float(badgeInspect, inspecting, 2);
if(badgePreview > 0) {
2023-11-21 02:53:15 +01:00
draw_sprite_ext(THEME.node_state, is_3D? 3 : 0, xx, yy, badgePreview, badgePreview, 0, c_white, 1);
2023-03-28 06:58:28 +02:00
xx -= 28 * badgePreview;
2022-01-13 05:24:03 +01:00
}
2023-03-28 06:58:28 +02:00
if(badgeInspect > 0) {
draw_sprite_ext(THEME.node_state, 1, xx, yy, badgeInspect, badgeInspect, 0, c_white, 1);
xx -= 28 * badgeInspect;
2022-01-13 05:24:03 +01:00
}
2023-07-17 19:58:33 +02:00
if(isTool) {
draw_sprite_ext(THEME.node_state, 2, xx, yy, 1, 1, 0, c_white, 1);
xx -= 28 * 2;
}
2022-01-13 05:24:03 +01:00
inspecting = false;
previewing = 0;
2023-08-16 20:16:31 +02:00
} #endregion
2022-01-13 05:24:03 +01:00
2023-11-27 11:40:28 +01:00
static drawBranch = function(_depth = 0) { #region
2023-10-12 07:07:24 +02:00
if(branch_drawing) return;
branch_drawing = true;
2023-11-27 11:40:28 +01:00
if(!PREFERENCES.connection_line_highlight_all && _depth == 1) return;
2023-10-12 07:07:24 +02:00
for( var i = 0, n = ds_list_size(inputs); i < n; i++ ) {
2023-10-27 13:55:31 +02:00
if(inputs[| i].isLeaf()) continue;
2023-11-27 11:40:28 +01:00
inputs[| i].value_from.node.drawBranch(_depth + 1);
2023-10-12 07:07:24 +02:00
}
} #endregion
static drawActive = function(_x, _y, _s, ind = 0) { #region
active_draw_index = ind;
2023-11-27 11:40:28 +01:00
var high = struct_try_get(display_parameter, "highlight", 0);
if(high) drawBranch();
2023-10-12 07:07:24 +02:00
} #endregion
2022-01-13 05:24:03 +01:00
2022-12-19 13:35:30 +01:00
static drawOverlay = function(active, _x, _y, _s, _mx, _my, _snx, _sny) {}
2022-01-13 05:24:03 +01:00
2023-10-18 14:58:55 +02:00
static drawPreviewToolOverlay = function(active, _mx, _my, _panel) { return false; }
2023-05-22 20:31:55 +02:00
static drawAnimationTimeline = function(_w, _h, _s) {}
2023-10-07 16:23:40 +02:00
static getAnimationCacheExist = function(frame) { return cacheExist(frame); }
static enable = function() { INLINE active = true; timeline_item.active = true; }
static disable = function() { INLINE active = false; timeline_item.active = false; }
2023-07-08 20:29:23 +02:00
2023-08-16 20:16:31 +02:00
static destroy = function(_merge = false) { #region
2023-02-14 02:51:14 +01:00
if(!active) return;
disable();
if(PANEL_GRAPH.node_hover == self) PANEL_GRAPH.node_hover = noone;
PANEL_GRAPH.nodes_selecting = [];
if(PANEL_INSPECTOR.inspecting == self) PANEL_INSPECTOR.inspecting = noone;
2023-07-17 19:58:33 +02:00
PANEL_PREVIEW.removeNodePreview(self);
2022-01-13 05:24:03 +01:00
for(var i = 0; i < ds_list_size(outputs); i++) {
var jun = outputs[| i];
2022-01-26 06:57:34 +01:00
2023-12-19 14:30:34 +01:00
for(var j = 0; j < array_length(jun.value_to); j++) {
var _vt = jun.value_to[j];
2023-10-27 13:55:31 +02:00
if(_vt.isLeaf()) break;
2023-02-14 02:51:14 +01:00
if(_vt.value_from.node != self) break;
2022-01-26 06:57:34 +01:00
_vt.removeFrom(false);
2023-02-14 02:51:14 +01:00
if(!_merge) continue;
for( var k = 0; k < ds_list_size(inputs); k++ ) {
2023-10-27 13:55:31 +02:00
if(inputs[| k].isLeaf()) continue;
2023-02-14 02:51:14 +01:00
if(_vt.setFrom(inputs[| k].value_from)) break;
2022-01-26 06:57:34 +01:00
}
2022-01-13 05:24:03 +01:00
}
2022-01-26 06:57:34 +01:00
2023-12-19 14:30:34 +01:00
jun.value_to = [];
2022-01-13 05:24:03 +01:00
}
2023-02-23 07:02:19 +01:00
for( var i = 0; i < ds_list_size(inputs); i++ )
inputs[| i].destroy();
for( var i = 0; i < ds_list_size(outputs); i++ )
outputs[| i].destroy();
2022-01-13 05:24:03 +01:00
onDestroy();
2023-10-02 10:45:30 +02:00
RENDER_ALL_REORDER
2023-08-16 20:16:31 +02:00
} #endregion
2023-02-14 02:51:14 +01:00
2023-08-16 20:16:31 +02:00
static restore = function() { #region
2023-02-14 02:51:14 +01:00
if(active) return;
enable();
2023-07-06 19:49:16 +02:00
ds_list_add(group == noone? PROJECT.nodes : group.getNodeList(), self);
2023-08-16 20:16:31 +02:00
} #endregion
2023-02-14 02:51:14 +01:00
2023-08-16 20:16:31 +02:00
static onValidate = function() { #region
2022-11-03 11:44:49 +01:00
value_validation[VALIDATION.pass] = 0;
value_validation[VALIDATION.warning] = 0;
value_validation[VALIDATION.error] = 0;
for( var i = 0; i < ds_list_size(inputs); i++ ) {
var jun = inputs[| i];
if(jun.value_validation)
2022-11-03 11:44:49 +01:00
value_validation[jun.value_validation]++;
}
2023-08-16 20:16:31 +02:00
} #endregion
2022-01-13 05:24:03 +01:00
static onDestroy = function() {}
2023-08-16 20:16:31 +02:00
static clearInputCache = function() { #region
2023-02-17 11:31:33 +01:00
for( var i = 0; i < ds_list_size(inputs); i++ )
2023-02-14 02:51:14 +01:00
inputs[| i].cache_value[0] = false;
2023-08-16 20:16:31 +02:00
} #endregion
2023-02-14 02:51:14 +01:00
2023-08-16 20:16:31 +02:00
static cacheArrayCheck = function() { #region
cached_output = array_verify(cached_output, TOTAL_FRAMES);
cache_result = array_verify(cache_result, TOTAL_FRAMES);
2023-08-16 20:16:31 +02:00
} #endregion
2022-12-10 05:06:01 +01:00
2023-08-16 20:16:31 +02:00
static cacheCurrentFrame = function(_frame) { #region
2022-12-10 05:06:01 +01:00
cacheArrayCheck();
2023-10-09 16:07:33 +02:00
if(CURRENT_FRAME < 0) return;
if(CURRENT_FRAME >= array_length(cached_output)) return;
2022-01-13 05:24:03 +01:00
2023-10-09 16:07:33 +02:00
surface_array_free(cached_output[CURRENT_FRAME]);
cached_output[CURRENT_FRAME] = surface_array_clone(_frame);
2022-12-10 05:06:01 +01:00
2023-10-09 16:07:33 +02:00
array_safe_set(cache_result, CURRENT_FRAME, true);
2023-05-03 21:42:17 +02:00
2023-10-09 16:07:33 +02:00
return cached_output[CURRENT_FRAME];
2023-08-16 20:16:31 +02:00
} #endregion
2023-02-19 13:49:20 +01:00
2023-10-09 16:07:33 +02:00
static cacheExist = function(frame = CURRENT_FRAME) { #region
2023-03-02 07:59:14 +01:00
if(frame < 0) return false;
2022-12-10 05:06:01 +01:00
if(frame >= array_length(cached_output)) return false;
if(frame >= array_length(cache_result)) return false;
2023-02-23 07:02:19 +01:00
if(!array_safe_get(cache_result, frame, false)) return false;
2023-05-03 21:42:17 +02:00
var s = array_safe_get(cached_output, frame);
return is_array(s) || surface_exists(s);
2023-08-16 20:16:31 +02:00
} #endregion
2022-12-10 05:06:01 +01:00
2023-10-09 16:07:33 +02:00
static getCacheFrame = function(frame = CURRENT_FRAME) { #region
2023-03-02 07:59:14 +01:00
if(frame < 0) return false;
2023-02-19 13:49:20 +01:00
if(!cacheExist(frame)) return noone;
var surf = array_safe_get(cached_output, frame);
return surf;
2023-08-16 20:16:31 +02:00
} #endregion
2023-02-19 13:49:20 +01:00
2023-10-09 16:07:33 +02:00
static recoverCache = function(frame = CURRENT_FRAME) { #region
2022-12-10 05:06:01 +01:00
if(!cacheExist(frame)) return false;
2023-10-09 16:07:33 +02:00
var _s = cached_output[CURRENT_FRAME];
2023-03-02 07:59:14 +01:00
outputs[| 0].setValue(_s);
2022-11-22 14:25:39 +01:00
return true;
2023-08-16 20:16:31 +02:00
} #endregion
2023-10-28 04:07:43 +02:00
static clearCache = function(_force = false) { #region
2023-07-25 20:12:40 +02:00
clearInputCache();
2023-10-28 04:07:43 +02:00
if(!_force) {
if(!use_cache) return;
if(!clearCacheOnChange) return;
if(!isRenderActive()) return;
}
2023-02-19 13:49:20 +01:00
2023-10-09 16:07:33 +02:00
if(array_length(cached_output) != TOTAL_FRAMES)
array_resize(cached_output, TOTAL_FRAMES);
2022-01-13 05:24:03 +01:00
for(var i = 0; i < array_length(cached_output); i++) {
var _s = cached_output[i];
2022-11-22 14:25:39 +01:00
if(is_surface(_s))
2022-01-13 05:24:03 +01:00
surface_free(_s);
cached_output[i] = 0;
2022-12-10 05:06:01 +01:00
cache_result[i] = false;
2022-01-13 05:24:03 +01:00
}
2023-08-16 20:16:31 +02:00
} #endregion
2023-07-08 20:29:23 +02:00
2023-10-19 11:34:29 +02:00
static clearCacheForward = function() { #region
_clearCacheForward();
} #endregion
2023-07-08 20:29:23 +02:00
2023-08-16 20:16:31 +02:00
static _clearCacheForward = function() { #region
2023-06-17 14:30:49 +02:00
if(!isRenderActive()) return;
2023-03-08 07:35:51 +01:00
2023-02-23 07:02:19 +01:00
clearCache();
2023-07-25 20:12:40 +02:00
var arr = getNextNodesRaw();
for( var i = 0, n = array_length(arr); i < n; i++ )
arr[i]._clearCacheForward();
2023-08-16 20:16:31 +02:00
} #endregion
2023-07-25 20:12:40 +02:00
2023-10-27 15:42:17 +02:00
static cachedPropagate = function(_group = group) { #region
if(group != _group) return;
setRenderStatus(true);
for( var i = 0, n = ds_list_size(inputs); i < n; i++ ) {
var _input = inputs[| i];
if(_input.isLeaf()) continue;
_input.value_from.node.cachedPropagate(_group);
}
} #endregion
2023-08-16 20:16:31 +02:00
static clearInputCache = function() { #region
2023-10-18 14:58:55 +02:00
for( var i = 0; i < ds_list_size(inputs); i++ ) {
if(!is_instanceof(inputs[| i], NodeValue)) continue;
2023-07-25 20:12:40 +02:00
inputs[| i].resetCache();
2023-10-18 14:58:55 +02:00
}
2023-08-16 20:16:31 +02:00
} #endregion
2022-01-13 05:24:03 +01:00
2023-08-16 20:16:31 +02:00
static checkConnectGroup = function(_type = "group") { #region
2022-12-23 04:45:52 +01:00
var _y = y;
2023-02-14 02:51:14 +01:00
var nodes = [];
2022-01-13 05:24:03 +01:00
for(var i = 0; i < ds_list_size(inputs); i++) {
var _in = inputs[| i];
2023-10-27 13:55:31 +02:00
if(_in.isLeaf()) continue;
2022-12-23 04:45:52 +01:00
if(_in.value_from.node.group == group) continue;
var input_node = noone;
2023-02-14 02:51:14 +01:00
2022-12-23 04:45:52 +01:00
switch(_type) {
case "group" : input_node = new Node_Group_Input(x - w - 64, _y, group); break;
case "loop" : input_node = new Node_Iterator_Input(x - w - 64, _y, group); break;
case "feedback" : input_node = new Node_Feedback_Input(x - w - 64, _y, group); break;
}
2022-01-13 05:24:03 +01:00
2022-12-23 04:45:52 +01:00
if(input_node == noone) continue;
2023-02-14 02:51:14 +01:00
array_push(nodes, input_node);
2022-12-23 04:45:52 +01:00
input_node.inputs[| 2].setValue(_in.type);
input_node.inParent.setFrom(_in.value_from);
input_node.onValueUpdate(0);
_in.setFrom(input_node.outputs[| 0]);
_y += 64;
}
2022-01-13 05:24:03 +01:00
for(var i = 0; i < ds_list_size(outputs); i++) {
var _ou = outputs[| i];
2023-12-19 14:30:34 +01:00
for(var j = 0; j < array_length(_ou.value_to); j++) {
var _to = _ou.value_to[j];
2022-12-12 09:08:03 +01:00
if(_to.value_from != _ou) continue;
if(!_to.node.active) continue;
if(_to.node.group == group) continue;
var output_node = noone;
2023-02-14 02:51:14 +01:00
2022-12-12 09:08:03 +01:00
switch(_type) {
2022-12-23 04:45:52 +01:00
case "group" : output_node = new Node_Group_Output(x + w + 64, y, group); break;
case "loop" : output_node = new Node_Iterator_Output(x + w + 64, y, group); break;
case "feedback" : output_node = new Node_Feedback_Output(x + w + 64, y, group); break;
2022-12-12 09:08:03 +01:00
}
2022-01-25 10:58:11 +01:00
2022-12-12 09:08:03 +01:00
if(output_node == noone) continue;
2022-12-23 04:45:52 +01:00
2023-02-14 02:51:14 +01:00
array_push(nodes, output_node);
2022-12-12 09:08:03 +01:00
_to.setFrom(output_node.outParent);
output_node.inputs[| 0].setFrom(_ou);
2022-01-13 05:24:03 +01:00
}
}
2023-02-14 02:51:14 +01:00
return nodes;
2023-08-16 20:16:31 +02:00
} #endregion
2022-01-13 05:24:03 +01:00
2023-08-16 20:16:31 +02:00
static isNotUsingTool = function() { return PANEL_PREVIEW.tool_current == noone; }
2023-03-11 01:40:17 +01:00
2023-08-16 20:16:31 +02:00
static isUsingTool = function(index = undefined, subtool = noone) { #region
2023-03-11 01:40:17 +01:00
if(tools == -1)
return false;
2023-07-15 20:01:29 +02:00
var _tool = PANEL_PREVIEW.tool_current;
if(_tool == noone) //not using any tool
2023-07-15 20:01:29 +02:00
return false;
if(index == undefined) //using any tool
2023-08-16 20:16:31 +02:00
return true;
2023-07-15 20:01:29 +02:00
if(is_real(index) && _tool != tools[index])
2023-03-11 01:40:17 +01:00
return false;
2023-07-15 20:01:29 +02:00
if(is_string(index) && _tool.getName(_tool.selecting) != index)
return false;
2023-03-11 01:40:17 +01:00
if(subtool == noone)
return true;
2023-07-15 20:01:29 +02:00
return _tool.selecting == subtool;
2023-08-16 20:16:31 +02:00
} #endregion
2023-03-11 01:40:17 +01:00
2023-08-16 20:16:31 +02:00
static clone = function(target = PANEL_GRAPH.getCurrentContext()) { #region
2023-01-17 08:11:55 +01:00
CLONING = true;
2022-12-12 09:08:03 +01:00
var _type = instanceof(self);
2023-02-14 02:51:14 +01:00
var _node = nodeBuild(_type, x, y, target);
2023-01-17 08:11:55 +01:00
CLONING = false;
2023-03-07 14:29:47 +01:00
2023-07-06 19:49:16 +02:00
PROJECT.version = SAVE_VERSION;
2023-01-17 08:11:55 +01:00
if(!_node) return;
2023-03-07 14:29:47 +01:00
CLONING = true;
2022-12-21 02:30:23 +01:00
var _nid = _node.node_id;
2023-02-14 02:51:14 +01:00
_node.deserialize(serialize());
_node.postDeserialize();
2022-12-21 02:30:23 +01:00
_node.applyDeserialize();
_node.node_id = _nid;
2022-12-18 03:20:38 +01:00
2023-07-06 19:49:16 +02:00
PROJECT.nodeMap[? node_id] = self;
PROJECT.nodeMap[? _nid] = _node;
2023-03-07 14:29:47 +01:00
CLONING = false;
2023-10-14 08:00:35 +02:00
refreshTimeline();
2022-12-12 09:08:03 +01:00
2023-02-28 09:43:01 +01:00
onClone(_node, target);
2023-01-25 06:49:00 +01:00
2022-12-12 09:08:03 +01:00
return _node;
2023-08-16 20:16:31 +02:00
} #endregion
2022-12-12 09:08:03 +01:00
2023-02-28 09:43:01 +01:00
static onClone = function(_NewNode, target = PANEL_GRAPH.getCurrentContext()) {}
2023-01-25 06:49:00 +01:00
2023-08-16 20:16:31 +02:00
static droppable = function(dragObj) { #region
2023-03-26 07:13:36 +02:00
for( var i = 0; i < ds_list_size(inputs); i++ ) {
if(dragObj.type == inputs[| i].drop_key)
return true;
}
return false;
2023-08-16 20:16:31 +02:00
} #endregion
2023-03-26 07:13:36 +02:00
2023-09-28 13:15:29 +02:00
on_drop_file = noone;
2023-08-16 20:16:31 +02:00
static onDrop = function(dragObj) { #region
2023-09-28 13:15:29 +02:00
if(dragObj.type == "Asset" && is_callable(on_drop_file)) {
on_drop_file(dragObj.data.path);
return;
}
2023-03-26 07:13:36 +02:00
for( var i = 0; i < ds_list_size(inputs); i++ ) {
if(dragObj.type == inputs[| i].drop_key) {
inputs[| i].setValue(dragObj.data);
return;
}
}
2023-08-16 20:16:31 +02:00
} #endregion
2023-03-25 12:27:04 +01:00
2023-08-17 16:56:54 +02:00
static getPreviewValues = function() { #region
2023-08-31 18:49:57 +02:00
if(preview_channel >= ds_list_size(outputs)) return noone;
2023-09-09 13:52:16 +02:00
switch(outputs[| preview_channel].type) {
case VALUE_TYPE.surface :
case VALUE_TYPE.dynaSurface :
2023-09-09 13:52:16 +02:00
break;
default :
2023-12-06 05:09:39 +01:00
return noone;
2023-09-09 13:52:16 +02:00
}
2023-08-31 18:49:57 +02:00
2023-08-17 16:56:54 +02:00
return outputs[| preview_channel].getValue();
2023-08-16 20:16:31 +02:00
} #endregion
2023-07-21 12:40:20 +02:00
2023-08-16 20:16:31 +02:00
static getPreviewBoundingBox = function() { #region
2023-08-17 16:56:54 +02:00
var _surf = getPreviewValues();
2023-07-10 20:14:10 +02:00
if(is_array(_surf))
_surf = array_safe_get(_surf, preview_index, noone);
if(!is_surface(_surf)) return noone;
2023-09-08 21:37:36 +02:00
return BBOX().fromWH(preview_x, preview_y, surface_get_width_safe(_surf), surface_get_height_safe(_surf));
2023-08-16 20:16:31 +02:00
} #endregion
2023-07-10 20:14:10 +02:00
2023-08-16 20:16:31 +02:00
static getTool = function() { return self; }
2023-07-17 19:58:33 +02:00
2023-08-19 12:42:50 +02:00
static getToolSettings = function() { return tool_settings; }
2023-08-16 20:16:31 +02:00
static setTool = function(tool) { #region
2023-07-17 19:58:33 +02:00
if(!tool) {
isTool = false;
return;
}
for( var i = 0; i < ds_list_size(group.nodes); i++ )
group.nodes[| i].isTool = false;
isTool = true;
2023-08-16 20:16:31 +02:00
} #endregion
2023-07-17 19:58:33 +02:00
2023-08-29 19:26:18 +02:00
static serialize = function(scale = false, preset = false) { #region
if(!active) return;
2023-06-13 14:42:06 +02:00
var _map = {};
2023-03-11 01:40:17 +01:00
//print(" > Serializing: " + name);
2022-01-13 05:24:03 +01:00
2022-12-10 05:06:01 +01:00
if(!preset) {
2023-06-13 14:42:06 +02:00
_map.id = node_id;
_map.render = renderActive;
_map.name = display_name;
_map.iname = internalName;
_map.x = x;
_map.y = y;
_map.type = instanceof(self);
_map.group = group == noone? group : group.node_id;
2023-07-17 19:58:33 +02:00
_map.tool = isTool;
2023-12-03 05:02:04 +01:00
_map.previewable = previewable;
2022-12-10 05:06:01 +01:00
}
2022-01-13 05:24:03 +01:00
2023-08-05 14:00:33 +02:00
_map.attri = attributeSerialize();
if(is_dynamic_input) {
_map.input_fix_len = input_fix_len;
_map.data_length = data_length;
}
2022-01-13 05:24:03 +01:00
2023-06-13 14:42:06 +02:00
var _inputs = [];
2023-02-17 04:48:54 +01:00
for(var i = 0; i < ds_list_size(inputs); i++)
2023-06-13 14:42:06 +02:00
array_push(_inputs, inputs[| i].serialize(scale, preset));
_map.inputs = _inputs;
2022-01-13 05:24:03 +01:00
2023-06-13 14:42:06 +02:00
var _outputs = [];
2023-04-07 21:25:27 +02:00
for(var i = 0; i < ds_list_size(outputs); i++)
2023-06-13 14:42:06 +02:00
array_push(_outputs, outputs[| i].serialize(scale, preset));
_map.outputs = _outputs;
2023-04-07 21:25:27 +02:00
2023-06-13 14:42:06 +02:00
var _trigger = [];
array_push(_trigger, inspectInput1.serialize(scale, preset));
array_push(_trigger, inspectInput2.serialize(scale, preset));
2023-10-06 11:51:11 +02:00
array_push(_trigger, updatedInTrigger.serialize(scale, preset));
array_push(_trigger, updatedOutTrigger.serialize(scale, preset));
2023-11-23 13:39:35 +01:00
2023-06-13 14:42:06 +02:00
_map.inspectInputs = _trigger;
2023-11-23 13:39:35 +01:00
_map.renamed = renamed;
2023-03-28 06:58:28 +02:00
2022-01-13 05:24:03 +01:00
doSerialize(_map);
2023-02-28 09:43:01 +01:00
processSerialize(_map);
2022-01-13 05:24:03 +01:00
return _map;
2023-08-29 19:26:18 +02:00
} #endregion
2022-01-13 05:24:03 +01:00
2023-06-13 14:42:06 +02:00
static attributeSerialize = function() { return attributes; }
2022-01-13 05:24:03 +01:00
static doSerialize = function(_map) {}
2023-02-28 09:43:01 +01:00
static processSerialize = function(_map) {}
2022-01-13 05:24:03 +01:00
2022-12-12 09:08:03 +01:00
load_scale = false;
2022-01-18 05:31:19 +01:00
load_map = -1;
2023-08-29 19:26:18 +02:00
static deserialize = function(_map, scale = false, preset = false) { #region
2023-11-25 08:54:35 +01:00
load_map = _map;
2022-12-12 09:08:03 +01:00
load_scale = scale;
2023-11-25 08:54:35 +01:00
renamed = struct_try_get(load_map, "renamed", false);
2022-01-19 03:05:13 +01:00
2022-12-10 05:06:01 +01:00
if(!preset) {
2023-06-13 14:42:06 +02:00
if(APPENDING) APPEND_MAP[? load_map.id] = node_id;
else node_id = load_map.id;
2023-07-06 19:49:16 +02:00
PROJECT.nodeMap[? node_id] = self;
2023-11-05 04:19:19 +01:00
//print($"Adding node {node_id} to {PROJECT.path} [{ds_map_size(PROJECT.nodeMap)}]");
2023-03-30 07:54:25 +02:00
2023-06-13 14:42:06 +02:00
if(struct_has(load_map, "name"))
setDisplayName(load_map.name);
2023-05-16 21:28:16 +02:00
2023-06-13 14:42:06 +02:00
internalName = struct_try_get(load_map, "iname", internalName);
2023-06-17 18:59:20 +02:00
if(internalName == "")
resetInternalName();
2023-06-13 14:42:06 +02:00
_group = struct_try_get(load_map, "group", noone);
2023-03-02 07:59:14 +01:00
if(_group == -1) _group = noone;
2023-03-30 07:54:25 +02:00
2023-06-13 14:42:06 +02:00
x = struct_try_get(load_map, "x");
y = struct_try_get(load_map, "y");
renderActive = struct_try_get(load_map, "render", true);
2023-12-03 05:02:04 +01:00
previewable = struct_try_get(load_map, "previewable", previewable);
2023-07-17 19:58:33 +02:00
isTool = struct_try_get(load_map, "tool");
2022-12-10 05:06:01 +01:00
}
2022-01-13 05:24:03 +01:00
2023-06-13 14:42:06 +02:00
if(struct_has(load_map, "attri"))
attributeDeserialize(load_map.attri);
2022-01-13 05:24:03 +01:00
2023-08-05 14:00:33 +02:00
if(is_dynamic_input) {
inputBalance();
inputGenerate();
}
2023-02-28 09:43:01 +01:00
processDeserialize();
2023-04-22 16:23:51 +02:00
if(preset) {
postDeserialize();
applyDeserialize();
triggerRender();
}
2023-08-29 19:26:18 +02:00
} #endregion
2023-03-28 06:58:28 +02:00
2023-08-29 19:26:18 +02:00
static inputBalance = function() { #region //Cross version compatibility for dynamic input nodes
2023-08-05 14:00:33 +02:00
if(!struct_has(load_map, "data_length"))
return;
var _input_fix_len = load_map.input_fix_len;
var _data_length = load_map.data_length;
2023-08-08 18:45:00 +02:00
//print($"Balancing IO: {input_fix_len} => {load_map.input_fix_len} : {data_length} => {load_map.data_length}");
//print($"IO size before: {array_length(load_map.inputs)}");
//for( var i = 0, n = array_length(load_map.inputs); i < n; i++ )
// print($"{i}: {load_map.inputs[i].name}");
2023-08-05 14:00:33 +02:00
var _dynamic_inputs = (array_length(load_map.inputs) - _input_fix_len) / _data_length;
if(frac(_dynamic_inputs) != 0) {
noti_warning("LOAD: Uneven dynamic input.");
_dynamic_inputs = ceil(_dynamic_inputs);
}
2023-08-08 18:45:00 +02:00
2023-08-05 14:00:33 +02:00
if(_input_fix_len == input_fix_len && _data_length == data_length)
return;
var _pad_dyna = data_length - _data_length;
2023-08-08 18:45:00 +02:00
for( var i = _dynamic_inputs; i >= 1; i-- ) {
2023-08-05 14:00:33 +02:00
var _ind = _input_fix_len + i * _data_length;
2023-08-08 20:33:17 +02:00
if(_pad_dyna > 0)
repeat(_pad_dyna) array_insert(load_map.inputs, _ind, noone);
else
array_delete(load_map.inputs, _ind + _pad_dyna, -_pad_dyna);
2023-08-05 14:00:33 +02:00
}
var _pad_fix = input_fix_len - _input_fix_len;
repeat(_pad_fix)
array_insert(load_map.inputs, _input_fix_len, noone);
2023-08-08 18:45:00 +02:00
//print($"IO size after: {array_length(load_map.inputs)}");
//for( var i = 0, n = array_length(load_map.inputs); i < n; i++ )
// print($"{i}: {load_map.inputs[i] == noone? "noone" : load_map.inputs[i].name}");
2023-08-29 19:26:18 +02:00
} #endregion
2023-08-05 14:00:33 +02:00
2023-08-29 19:26:18 +02:00
static inputGenerate = function() { #region //Generate input for dynamic input nodes
2023-08-05 14:00:33 +02:00
if(createNewInput == noone)
return;
var _dynamic_inputs = (array_length(load_map.inputs) - input_fix_len) / data_length;
2023-08-08 18:45:00 +02:00
//print($"Node {name} create {_dynamic_inputs} inputs for data length {data_length}");
2023-08-05 14:00:33 +02:00
repeat(_dynamic_inputs)
createNewInput();
2023-08-29 19:26:18 +02:00
} #endregion
2022-01-13 05:24:03 +01:00
static attributeDeserialize = function(attr) { #region
if(struct_has(attributes, "use_project_dimension") && !struct_has(attr, "use_project_dimension"))
attributes.use_project_dimension = false;
struct_override(attributes, attr);
} #endregion
2022-01-13 05:24:03 +01:00
static postDeserialize = function() {}
2023-02-28 09:43:01 +01:00
static processDeserialize = function() {}
2023-03-11 01:40:17 +01:00
2023-08-29 19:26:18 +02:00
static applyDeserialize = function(preset = false) { #region
2023-06-13 14:42:06 +02:00
var _inputs = load_map.inputs;
var amo = min(ds_list_size(inputs), array_length(_inputs));
2022-12-22 03:09:55 +01:00
2023-10-18 14:58:55 +02:00
//print($"Applying deserialzie for {name}");
2023-03-11 01:40:17 +01:00
for(var i = 0; i < amo; i++) {
2023-07-14 20:34:35 +02:00
if(inputs[| i] == noone || _inputs[i] == noone) continue;
2023-10-18 14:58:55 +02:00
//print($" Apply {i} : {inputs[| i].name}");
2023-06-13 14:42:06 +02:00
inputs[| i].applyDeserialize(_inputs[i], load_scale, preset);
2023-03-11 01:40:17 +01:00
}
2023-01-01 02:06:02 +01:00
2023-06-13 14:42:06 +02:00
if(struct_has(load_map, "outputs")) {
var _outputs = load_map.outputs;
2023-06-17 14:30:49 +02:00
var amo = min(ds_list_size(outputs), array_length(_outputs));
for(var i = 0; i < amo; i++) {
2023-04-07 21:25:27 +02:00
if(outputs[| i] == noone) continue;
2023-06-13 14:42:06 +02:00
outputs[| i].applyDeserialize(_outputs[i], load_scale, preset);
2023-04-07 21:25:27 +02:00
}
}
2023-06-13 14:42:06 +02:00
if(struct_has(load_map, "inspectInputs")) {
var insInp = load_map.inspectInputs;
inspectInput1.applyDeserialize(insInp[0], load_scale, preset);
inspectInput2.applyDeserialize(insInp[1], load_scale, preset);
2023-09-28 13:15:29 +02:00
2023-10-06 11:51:11 +02:00
if(array_length(insInp) > 2) updatedInTrigger.applyDeserialize(insInp[2], load_scale, preset);
if(array_length(insInp) > 3) updatedOutTrigger.applyDeserialize(insInp[3], load_scale, preset);
2023-03-28 06:58:28 +02:00
}
2023-01-09 03:14:20 +01:00
2023-10-18 14:58:55 +02:00
//print($"Applying deserialzie for {name} complete");
2023-01-09 03:14:20 +01:00
doApplyDeserialize();
2023-08-29 19:26:18 +02:00
} #endregion
2022-12-21 02:30:23 +01:00
2023-01-09 03:14:20 +01:00
static doApplyDeserialize = function() {}
2023-08-29 19:26:18 +02:00
static loadGroup = function(context = PANEL_GRAPH.getCurrentContext()) { #region
2023-02-28 09:43:01 +01:00
if(_group == noone) {
2023-11-08 08:38:04 +01:00
if(context != noone) context.add(self);
2022-01-13 05:24:03 +01:00
} else {
2022-01-19 03:05:13 +01:00
if(APPENDING) _group = GetAppendID(_group);
2023-07-06 19:49:16 +02:00
if(ds_map_exists(PROJECT.nodeMap, _group)) {
2023-07-21 12:40:20 +02:00
if(struct_has(PROJECT.nodeMap[? _group], "add"))
PROJECT.nodeMap[? _group].add(self);
else {
var txt = $"Group load failed. Node ID {_group} is not a group.";
throw(txt);
}
2022-01-19 03:05:13 +01:00
} else {
2023-07-21 12:40:20 +02:00
var txt = $"Group load failed. Can't find node ID {_group}";
throw(txt);
2022-01-18 05:31:19 +01:00
}
2022-01-13 05:24:03 +01:00
}
2023-10-18 14:58:55 +02:00
onLoadGroup();
2023-08-29 19:26:18 +02:00
} #endregion
2022-01-18 05:31:19 +01:00
2023-10-18 14:58:55 +02:00
static onLoadGroup = function() {}
2023-08-29 19:26:18 +02:00
static connect = function(log = false) { #region
2022-01-13 05:24:03 +01:00
var connected = true;
2023-03-28 06:58:28 +02:00
for(var i = 0; i < ds_list_size(inputs); i++)
2022-09-21 06:09:40 +02:00
connected &= inputs[| i].connect(log);
2023-03-28 06:58:28 +02:00
2023-10-06 11:51:11 +02:00
inspectInput1.connect(log);
inspectInput2.connect(log);
updatedInTrigger.connect(log);
2023-03-28 06:58:28 +02:00
2022-01-13 05:24:03 +01:00
if(!connected) ds_queue_enqueue(CONNECTION_CONFLICT, self);
2023-10-14 08:00:35 +02:00
refreshTimeline();
2022-09-21 06:09:40 +02:00
return connected;
2023-08-29 19:26:18 +02:00
} #endregion
2022-01-13 05:24:03 +01:00
static preConnect = function() {}
2022-01-18 05:31:19 +01:00
static postConnect = function() {}
2022-01-19 06:11:17 +01:00
2023-10-07 16:23:40 +02:00
static postLoad = function() {}
2023-04-10 20:02:59 +02:00
static resetAnimation = function() {}
2023-08-16 20:16:31 +02:00
static cleanUp = function() { #region
2023-02-23 07:02:19 +01:00
for( var i = 0; i < ds_list_size(inputs); i++ )
2022-01-19 06:11:17 +01:00
inputs[| i].cleanUp();
2023-02-23 07:02:19 +01:00
for( var i = 0; i < ds_list_size(outputs); i++ )
2022-01-19 06:11:17 +01:00
outputs[| i].cleanUp();
ds_list_destroy(inputs);
ds_list_destroy(outputs);
2023-04-15 14:48:29 +02:00
ds_map_destroy(inputMap);
ds_map_destroy(outputMap);
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(temp_surface); i < n; i++ )
2023-02-23 07:02:19 +01:00
surface_free(temp_surface[i]);
2023-04-14 12:23:25 +02:00
onCleanUp();
2023-08-16 20:16:31 +02:00
} #endregion
2023-02-23 07:02:19 +01:00
static onCleanUp = function() {}
2023-03-19 09:17:39 +01:00
// helper function
2023-08-16 20:16:31 +02:00
static attrDepth = function() { #region
2023-06-13 14:42:06 +02:00
if(struct_has(attributes, "color_depth")) {
var form = attributes.color_depth;
2023-03-19 09:17:39 +01:00
if(inputs[| 0].type == VALUE_TYPE.surface)
form--;
if(form >= 0)
return array_safe_get(global.SURFACE_FORMAT, form, surface_rgba8unorm);
}
var _s = getInputData(0);
2023-03-19 09:17:39 +01:00
while(is_array(_s) && array_length(_s)) _s = _s[0];
if(!is_surface(_s))
return surface_rgba8unorm;
return surface_get_format(_s);
2023-08-16 20:16:31 +02:00
} #endregion
2023-10-02 10:45:30 +02:00
2023-10-09 16:07:33 +02:00
static toString = function() { return $"PixelComposerNode [{internalName}]: {node_id}"; }
2022-01-13 05:24:03 +01:00
}