Pixel-Composer/scripts/node_data/node_data.gml

2972 lines
82 KiB
Text
Raw Normal View History

2024-08-08 06:57:51 +02:00
#region global
global.loop_nodes = [ "Node_Iterate", "Node_Iterate_Each" ];
#macro INAME internalName == ""? name : internalName
#macro SHOW_PARAM (show_parameter && previewable)
enum CACHE_USE {
none,
manual,
auto
}
enum DYNA_INPUT_COND {
connection = 1 << 0,
zero = 1 << 1,
}
enum NODE_3D {
none,
polygon,
sdf,
}
#endregion
2024-06-15 08:02:10 +02:00
2024-02-12 10:25:23 +01:00
function Node(_x, _y, _group = noone) : __Node_Base(_x, _y) constructor {
2024-03-31 11:10:14 +02:00
2023-08-16 20:16:31 +02:00
#region ---- main & active ----
project = PROJECT;
2023-12-18 08:27:31 +01:00
active = true;
2023-08-16 20:16:31 +02:00
renderActive = true;
2024-04-11 05:51:13 +02:00
2024-11-23 12:08:44 +01: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;
2024-02-12 10:25:23 +01:00
2024-11-24 11:39:17 +01:00
if(NOT_LOAD) array_push(_group == noone? project.nodes : _group.getNodeList(), 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.allNodes, self);
2023-12-18 08:27:31 +01:00
inline_context = noone;
2024-04-11 05:51:13 +02:00
inline_parent_object = "";
2024-06-11 05:06:42 +02:00
search_match = -9999;
2024-06-11 11:26:00 +02:00
onDoubleClick = -1;
is_controller = false;
2023-08-16 20:16:31 +02:00
#endregion
2022-01-13 05:24:03 +01:00
static resetInternalName = function() {
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-06-17 18:59:20 +02:00
if(!LOADING && !APPENDING) {
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
2024-11-23 12:08:44 +01: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;
2024-11-23 12:08:44 +01:00
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-05-07 20:55:13 +02:00
2023-08-16 20:16:31 +02:00
#region ---- display ----
2024-11-23 12:08:44 +01:00
color = c_white;
icon = noone;
icon_24 = noone;
2024-12-07 10:35:29 +01:00
icon_blend = c_white;
2024-11-23 12:08:44 +01:00
bg_spr = THEME.node_bg;
bg_spr_add = 0.1;
bg_spr_add_clr = c_white;
2022-01-13 05:24:03 +01:00
2024-11-23 12:08:44 +01:00
name = "";
display_name = "";
internalName = "";
2023-10-01 06:17:39 +02:00
onSetDisplayName = noone;
2024-11-23 12:08:44 +01:00
renamed = false;
tooltip = "";
2023-12-19 14:30:34 +01:00
2023-08-16 20:16:31 +02:00
x = _x;
y = _y;
2024-11-23 12:08:44 +01:00
w = 128;
h = 128;
min_w = w;
con_h = 128;
h_param = h;
name_height = ui(16);
2024-11-30 06:50:20 +01:00
custom_grid = 0;
2024-11-01 05:57:42 +01:00
preserve_height_for_preview = false;
2023-11-20 05:10:55 +01:00
2023-12-19 14:30:34 +01:00
selectable = true;
2024-04-11 05:51:13 +02:00
clonable = true;
2023-08-16 20:16:31 +02:00
auto_height = true;
2024-05-02 12:13:35 +02:00
draw_padding = 4;
draw_pad_w = 0;
draw_pad_h = 0;
2023-08-16 20:16:31 +02:00
display_parameter = new connectionParameter();
2023-08-16 20:16:31 +02:00
draw_name = true;
draggable = true;
2024-03-29 05:20:49 +01:00
draw_boundary = [ 0, 0, 0, 0 ];
2023-08-16 20:16:31 +02:00
draw_graph_culled = false;
badgePreview = 0;
badgeInspect = 0;
active_draw_index = -1;
active_draw_anchor = false;
2023-08-16 20:16:31 +02:00
draw_droppable = false;
2023-09-11 16:08:58 +02:00
junction_draw_pad_y = 32;
2024-03-28 14:18:02 +01:00
junction_draw_hei_y = 24;
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 ----
2024-08-14 09:55:53 +02:00
inputs = [];
outputs = [];
input_bypass = [];
2024-11-23 12:08:44 +01:00
inputMap = {};
outputMap = {};
2024-08-14 09:55:53 +02:00
input_value_map = {};
2023-10-12 14:14:08 +02:00
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;
2024-08-20 10:15:53 +02:00
inspectInput1 = nodeValue("Toggle execution", self, CONNECT_TYPE.input, VALUE_TYPE.action, false).setVisible(true, true);
2024-08-14 09:55:53 +02:00
inspectInput1.index = -1;
2023-08-16 20:16:31 +02:00
2024-08-20 10:15:53 +02:00
inspectInput2 = nodeValue("Toggle execution", self, CONNECT_TYPE.input, VALUE_TYPE.action, false).setVisible(true, true);
2024-08-14 09:55:53 +02:00
inspectInput2.index = -1;
2023-10-06 11:51:11 +02:00
2024-08-20 10:15:53 +02:00
updatedInTrigger = nodeValue("Update", self, CONNECT_TYPE.input, VALUE_TYPE.trigger, false).setVisible(true, true);
2023-10-07 16:23:40 +02:00
updatedInTrigger.index = -1;
2024-08-14 09:55:53 +02:00
updatedInTrigger.tags = VALUE_TAG.updateInTrigger;
2023-10-07 16:23:40 +02:00
2024-08-14 09:55:53 +02:00
updatedOutTrigger = nodeValue_Output("Updated", self, VALUE_TYPE.trigger, false).setVisible(true, true);
updatedOutTrigger.index = -1;
updatedOutTrigger.tags = VALUE_TAG.updateOutTrigger;
2023-09-28 13:15:29 +02:00
2024-08-14 09:55:53 +02:00
insp1UpdateActive = true;
insp1UpdateTooltip = __txtx("panel_inspector_execute", "Execute node");
insp1UpdateIcon = [ THEME.sequence_control, 1, COLORS._main_value_positive ];
2023-11-04 13:22:52 +01:00
2024-08-14 09:55:53 +02:00
insp2UpdateActive = true;
insp2UpdateTooltip = __txtx("panel_inspector_execute", "Execute node");
insp2UpdateIcon = [ THEME.sequence_control, 1, COLORS._main_value_positive ];
2023-08-16 20:16:31 +02:00
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
2024-03-31 05:36:11 +02:00
inputs_amount = 0;
in_cache_len = 0;
inputDisplayList = [];
2024-03-29 05:20:49 +01:00
2023-11-30 03:18:25 +01:00
outputs_index = [];
out_cache_len = 0;
input_buttons = [];
input_button_length = 0;
toRefreshNodeDisplay = false;
run_in(1, function() {
2024-08-08 06:57:51 +02:00
input_buttons = [];
2024-08-18 13:13:40 +02:00
for( var i = 0; i < array_length(inputs); i++ ) {
2024-08-08 06:57:51 +02:00
var _in = inputs[i];
if(!is_instanceof(_in, NodeValue)) continue;
if(_in.type != VALUE_TYPE.trigger) continue;
2024-04-08 07:13:46 +02:00
if(_in.runInUI) array_push(input_buttons, _in);
}
input_button_length = array_length(input_buttons);
});
2024-05-23 10:59:39 +02:00
junc_meta = [
nodeValue_Output("Name", self, VALUE_TYPE.text, ""),
nodeValue_Output("Position", self, VALUE_TYPE.float, [ 0, 0 ])
.setDisplay(VALUE_DISPLAY.vector),
];
for( var i = 0, n = array_length(junc_meta); i < n; i++ ) {
junc_meta[i].index = i;
junc_meta[i].tags = VALUE_TAG.matadata;
}
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 ----
2024-03-31 05:36:11 +02:00
attributes.node_param_width = PREFERENCES.node_param_width;
2023-11-20 05:10:55 +01:00
attributes.node_width = 0;
attributes.node_height = 0;
attributes.outp_meta = false;
2023-09-28 13:15:29 +02:00
2024-11-26 05:52:57 +01:00
attributes.annotation = "";
attributes.annotation_size = .4;
attributes.annotation_color = COLORS._main_text_sub;
2023-09-28 13:15:29 +02:00
attributeEditors = [
2024-03-31 05:36:11 +02:00
"Display",
["Annotation", function() /*=>*/ {return attributes.annotation}, new textArea(TEXTBOX_INPUT.text, function(val) /*=>*/ { attributes.annotation = val; }) ],
["Params Width", function() /*=>*/ {return attributes.node_param_width}, new textBox(TEXTBOX_INPUT.number, function(val) /*=>*/ { attributes.node_param_width = val; refreshNodeDisplay(); }) ],
2024-03-31 05:36:11 +02:00
"Node",
["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; }) ],
["Output metadata", function() /*=>*/ {return attributes.outp_meta}, new checkBox(function() /*=>*/ { attributes.outp_meta = !attributes.outp_meta; setHeight(); }) ],
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 ----
2024-03-31 05:36:11 +02:00
show_parameter = PREFERENCES.node_param_show;
2024-03-28 14:18:02 +01:00
2023-08-16 20:16:31 +02:00
show_input_name = false;
show_output_name = false;
2024-11-23 12:08:44 +01:00
inspecting = false;
previewing = 0;
2023-12-04 12:09:31 +01:00
2024-11-23 12:08:44 +01:00
preview_surface = noone;
preview_amount = 0;
previewable = true;
preview_draw = true;
preview_speed = 0;
preview_index = 0;
preview_channel = 0;
preview_alpha = 1;
2024-11-23 12:08:44 +01:00
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;
getPreviewingNode = function() /*=>*/ {return self};
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;
2024-12-07 10:35:29 +01:00
render_timer = 0;
2023-08-16 20:16:31 +02:00
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
2024-11-23 12:08:44 +01:00
is_simulation = false;
is_group_io = false;
in_VFX = false;
2023-12-22 04:15:04 +01:00
2024-11-26 05:52:57 +01:00
use_trigger = 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 = array_length(PROJECT.allNodes);
2023-10-14 08:00:35 +02:00
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);
2024-11-23 12:08:44 +01:00
manual_updated = false;
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 ---- tools ----
tools = -1;
2024-04-12 11:45:21 +02:00
rightTools = -1;
2023-08-16 20:16:31 +02:00
isTool = false;
2024-12-12 04:49:09 +01:00
isGizmoGlobal = false;
2023-08-16 20:16:31 +02:00
tool_settings = [];
tool_attribute = {};
#endregion
2022-01-13 05:24:03 +01:00
2023-08-16 20:16:31 +02:00
#region ---- 3d ----
2024-06-15 08:02:10 +02:00
is_3D = NODE_3D.none;
2023-08-16 20:16:31 +02:00
#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 ----
2024-11-30 06:50:20 +01:00
messages = [];
2024-06-26 06:38:57 +02:00
messages_bub = false;
2024-11-30 06:50:20 +01:00
messages_dbg = [];
2024-06-26 06:38:57 +02:00
2024-11-30 06:50:20 +01:00
static logNode = function(text, noti = 0) {
2024-06-26 06:38:57 +02:00
var _time = $"{string_lead_zero(current_hour, 2)}:{string_lead_zero(current_minute, 2)}.{string_lead_zero(current_second, 2)}";
messages_bub = true;
array_push(messages, [ _time, text ]);
2024-11-30 06:50:20 +01:00
switch(noti) {
case 1 : noti_status(text,, self); break;
case 2 : noti_warning(text,, self); break;
}
}
static logNodeDebug = function(text, level = 1) {
LOG_IF(global.FLAG.render >= level, text);
if(PROFILER_STAT == 0) return;
_report = {};
_report.type = "message";
_report.node = self;
_report.text = text;
_report.level = level;
array_push(PROFILER_DATA, _report);
2024-06-26 06:38:57 +02:00
}
2023-12-10 14:55:05 +01:00
#endregion
2024-04-11 05:51:13 +02:00
#region ---- serialization ----
load_scale = false;
load_map = -1;
load_group = noone;
#endregion
2024-12-11 04:29:11 +01:00
////- NAME
2023-08-05 14:00:33 +02:00
static initTooltip = function() {
2024-02-12 13:59:43 +01:00
if(IS_CMD) return;
var type_self = instanceof(self);
2023-08-08 11:42:01 +02:00
if(!struct_has(global.NODE_GUIDE, type_self)) return;
2023-03-05 07:16:44 +01:00
2024-08-08 06:57:51 +02: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;
2024-08-18 13:13:40 +02:00
var amo = min(array_length(inputs), array_length(_ins));
2023-03-05 07:16:44 +01:00
for( var i = 0; i < amo; i++ ) {
2024-08-08 06:57:51 +02:00
inputs[i].name = _ins[i].name;
inputs[i].tooltip = _ins[i].tooltip;
2023-03-05 07:16:44 +01:00
}
2024-08-18 13:13:40 +02:00
var amo = min(array_length(outputs), array_length(_ots));
2023-03-05 07:16:44 +01:00
for( var i = 0; i < amo; i++ ) {
2024-08-08 06:57:51 +02:00
outputs[i].name = _ots[i].name;
outputs[i].tooltip = _ots[i].tooltip;
2023-03-05 07:16:44 +01:00
}
2024-08-08 06:57:51 +02:00
} run_in(1, function() /*=>*/ {return initTooltip});
2024-08-08 06:57:51 +02:00
static setDisplayName = function(_name) {
renamed = true;
display_name = _name;
internalName = string_replace_all(display_name, " ", "_");
refreshNodeMap();
if(onSetDisplayName != noone)
onSetDisplayName();
return self;
2024-08-08 06:57:51 +02:00
}
2023-03-05 07:16:44 +01:00
2024-07-10 13:13:51 +02:00
static getFullName = function() { return renamed? $"[{name}] " + display_name : name; }
static getDisplayName = function() { return renamed? display_name : name; }
2024-12-11 04:29:11 +01:00
////- DYNAMIC IO
2024-11-01 05:57:42 +01:00
dummy_input = noone;
auto_input = false;
dyna_input_check_shift = 0;
2024-10-10 13:13:21 +02:00
input_display_dynamic = -1;
2024-11-01 05:57:42 +01:00
dynamic_input_inspecting = 0;
2024-10-03 08:09:27 +02:00
static createNewInput = -1;
2024-12-11 12:44:48 +01:00
static setDynamicInput = function(_data_length = 1, _auto_input = true, _dummy_type = VALUE_TYPE.any, _dynamic_input_cond = DYNA_INPUT_COND.connection) {
is_dynamic_input = true;
auto_input = _auto_input;
dummy_type = _dummy_type;
2023-02-14 02:51:14 +01:00
input_display_list_raw = array_clone(input_display_list, 1);
input_display_len = input_display_list == -1? 0 : array_length(input_display_list);
2024-08-08 06:57:51 +02:00
input_fix_len = array_length(inputs);
data_length = _data_length;
dynamic_input_cond = _dynamic_input_cond;
if(auto_input) {
2024-08-20 10:15:53 +02:00
dummy_input = nodeValue("Add value", self, CONNECT_TYPE.input, dummy_type, 0)
.setDummy(function() /*=>*/ {return createNewInput()})
.setVisible(false, true);
}
attributes.size = 0;
2024-07-10 13:13:51 +02:00
}
2024-07-10 13:13:51 +02:00
static refreshDynamicInput = function() {
if(LOADING || APPENDING) return;
2024-08-08 06:57:51 +02:00
var _in = [];
for( var i = 0; i < input_fix_len; i++ )
2024-08-08 06:57:51 +02:00
array_push(_in, inputs[i]);
input_display_list = array_clone(input_display_list_raw, 1);
var sep = false;
2024-08-18 13:13:40 +02:00
for( var i = input_fix_len; i < array_length(inputs); i += data_length ) {
var _active = false;
2024-08-08 06:57:51 +02:00
var _inp = inputs[i + dyna_input_check_shift];
if(dynamic_input_cond & DYNA_INPUT_COND.connection)
_active |= _inp.hasJunctionFrom();
if(dynamic_input_cond & DYNA_INPUT_COND.zero) {
var _val = _inp.getValue();
_active |= _val != 0 || _val != "";
}
2023-02-14 02:51:14 +01:00
if(_active) {
if(sep && data_length > 1) array_push(input_display_list, new Inspector_Spacer(20, true));
sep = true;
for( var j = 0; j < data_length; j++ ) {
var _ind = i + j;
if(input_display_list != -1)
2024-08-08 06:57:51 +02:00
array_push(input_display_list, array_length(_in));
array_push(_in, inputs[_ind]);
}
} else {
for( var j = 0; j < data_length; j++ )
2024-08-08 06:57:51 +02:00
delete inputs[i + j];
}
2023-02-14 02:51:14 +01:00
}
2024-08-08 06:57:51 +02:00
var _ina = array_length(_in);
for( var i = 0; i < _ina; i++ )
2024-08-14 09:55:53 +02:00
_in[i].index = i;
if(dummy_input) dummy_input.index = _ina;
inputs = _in;
2024-11-24 11:39:17 +01:00
refreshNodeDisplay();
2024-07-10 13:13:51 +02:00
}
2024-10-03 08:09:27 +02:00
static refreshDynamicDisplay = function() {
2024-10-10 13:13:21 +02:00
if(input_display_dynamic == -1) return;
2024-10-03 08:09:27 +02:00
array_resize(input_display_list, array_length(input_display_list_raw));
var _amo = getInputAmount();
if(_amo == 0) {
dynamic_input_inspecting = 0;
return;
}
dynamic_input_inspecting = clamp(dynamic_input_inspecting, 0, getInputAmount() - 1);
var _ind = input_fix_len + dynamic_input_inspecting * data_length;
for( var i = 0, n = array_length(input_display_dynamic); i < n; i++ ) {
var v = input_display_dynamic[i];
if(is_real(v)) v += _ind;
array_push(input_display_list, v);
}
}
2024-08-18 13:13:40 +02:00
static getInputAmount = function() { return (array_length(inputs) - input_fix_len) / data_length; }
function onInputResize() { refreshDynamicInput(); triggerRender(); }
2024-07-02 13:25:59 +02:00
static getOutput = function(_y, junc = noone) {
var _targ = noone;
var _dy = 9999;
2024-08-18 13:13:40 +02:00
for( var i = 0; i < array_length(outputs); i++ ) {
2024-08-08 06:57:51 +02:00
if(!outputs[i].isVisible()) continue;
if(junc != noone && !junc.isConnectable(outputs[i], true)) continue;
2024-08-08 06:57:51 +02:00
var _ddy = abs(outputs[i].y - _y);
2024-07-02 13:25:59 +02:00
if(_ddy < _dy) {
2024-08-08 06:57:51 +02:00
_targ = outputs[i];
2024-07-02 13:25:59 +02:00
_dy = _ddy;
}
}
2024-07-02 13:25:59 +02:00
return _targ;
}
2024-07-02 13:25:59 +02:00
static getInput = function(_y = 0, junc = noone, shift = input_fix_len) {
2024-08-08 06:57:51 +02:00
2024-07-02 13:25:59 +02:00
var _targ = noone;
var _dy = 9999;
2024-08-18 13:13:40 +02:00
for( var i = shift; i < array_length(inputs); i++ ) {
2024-08-08 06:57:51 +02:00
var _inp = inputs[i];
if(!_inp.isVisible()) continue;
if(_inp.value_from != noone) continue;
if(junc != noone && (value_bit(junc.type) & value_bit(_inp.type)) == 0) continue;
2024-07-02 13:25:59 +02:00
var _ddy = abs(_inp.y - _y);
if(_ddy < _dy) {
_targ = _inp;
_dy = _ddy;
}
}
2024-07-02 13:25:59 +02:00
if(dummy_input) {
var _ddy = abs(dummy_input.y - _y);
if(_ddy < _dy)
_targ = dummy_input;
}
return _targ;
}
2024-10-03 08:09:27 +02:00
static deleteDynamicInput = function(index) {
var _ind = input_fix_len + index * data_length;
array_delete(inputs, _ind, data_length);
dynamic_input_inspecting = clamp(dynamic_input_inspecting, 0, getInputAmount() - 1);
refreshDynamicDisplay();
triggerRender();
}
2024-12-11 04:29:11 +01:00
////- INSPECTOR
static onInspector1Update = noone;
static inspector1Update = function() { INLINE onInspector1Update(); }
static hasInspector1Update = function() { INLINE return onInspector1Update != noone; }
static onInspector2Update = noone;
static inspector2Update = function() { INLINE onInspector2Update(); }
static hasInspector2Update = function() { INLINE return onInspector2Update != noone; }
2024-12-11 04:29:11 +01:00
////- STEP
static stepBegin = function() {
2024-08-08 06:57:51 +02:00
if(use_cache) cacheArrayCheck();
doStepBegin();
if(attributes.show_update_trigger) {
if(updatedInTrigger.getValue()) {
getInputs();
update();
updatedInTrigger.setValue(false);
}
updatedOutTrigger.setValue(false);
}
2024-06-15 08:02:10 +02:00
if(is_3D == NODE_3D.polygon) USE_DEPTH = true;
if(is_simulation) PROJECT.animator.is_simulating = true;
2024-10-18 04:47:55 +02:00
if(attributes.outp_meta) {
junc_meta[0].setValue(getDisplayName());
junc_meta[1].setValue([ x, y ]);
}
if(toRefreshNodeDisplay) {
refreshNodeDisplay();
toRefreshNodeDisplay = false;
}
}
static doStepBegin = function() {}
2024-11-26 05:52:57 +01:00
static setTrigger = function(index, tooltip = __txtx("panel_inspector_execute", "Execute"), icon = [ THEME.sequence_control, 1, COLORS._main_value_positive ], _function = undefined) {
use_trigger = true;
2024-11-26 05:52:57 +01:00
if(index == 1) {
insp1UpdateTooltip = tooltip;
insp1UpdateIcon = icon;
if(!is_undefined(_function)) onInspector1Update = _function;
2024-11-26 05:52:57 +01:00
} else if(index == 2) {
insp2UpdateTooltip = tooltip;
insp2UpdateIcon = icon;
if(!is_undefined(_function)) onInspector2Update = _function;
}
}
static triggerCheck = function() {
if(input_button_length) {
var i = 0;
repeat( input_button_length ) {
var _in = input_buttons[i++];
if(_in.getStaticValue()) {
_in.editWidget.onClick();
_in.setValue(false);
}
}
}
2024-11-26 05:52:57 +01:00
if(!use_trigger) return;
if(hasInspector1Update()) {
inspectInput1.name = insp1UpdateTooltip;
if(inspectInput1.getStaticValue()) {
onInspector1Update();
inspectInput1.setValue(false);
}
}
2024-11-26 05:52:57 +01:00
if(hasInspector2Update()) {
inspectInput2.name = insp2UpdateTooltip;
if(inspectInput2.getStaticValue()) {
onInspector2Update();
inspectInput2.setValue(false);
}
}
2024-07-10 13:13:51 +02:00
}
static step = function() {}
static focusStep = function() {}
static inspectorStep = function() {}
2024-12-11 04:29:11 +01:00
////- JUNCTIONS
2022-09-27 06:37:28 +02:00
2024-09-04 03:57:11 +02:00
static newInput = function(index, junction) { inputs[index] = junction; return junction; }
static newOutput = function(index, junction) { outputs[index] = junction; return junction; }
2024-08-18 05:10:39 +02:00
2024-10-06 03:25:07 +02:00
static getInputJunctionAmount = function() { return (input_display_list == -1 || !use_display_list)? array_length(inputs) : array_length(input_display_list); }
2024-10-06 03:55:16 +02:00
static getInputJunctionIndex = function(index) {
2024-03-29 05:20:49 +01:00
INLINE
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];
2024-03-29 05:20:49 +01:00
if(is_array(jun_list_arr)) return noone;
2022-09-27 06:37:28 +02:00
if(is_struct(jun_list_arr)) return noone;
2024-03-29 05:20:49 +01:00
2022-09-27 06:37:28 +02:00
return jun_list_arr;
2024-07-10 13:13:51 +02:00
}
2024-08-18 13:13:40 +02:00
static getOutputJunctionAmount = function() { return output_display_list == -1? array_length(outputs) : array_length(output_display_list); }
static getOutputJunctionIndex = function(index) { return output_display_list == -1? index : output_display_list[index]; }
2022-12-13 09:20:36 +01:00
static updateIO = function() {
2024-03-29 05:20:49 +01:00
2024-08-18 13:13:40 +02:00
for( var i = 0, n = array_length(inputs); i < n; i++ )
2024-08-08 06:57:51 +02:00
inputs[i].visible_in_list = false;
2024-10-06 03:25:07 +02:00
inputs_amount = getInputJunctionAmount();
2023-11-30 03:18:25 +01:00
for( var i = 0; i < inputs_amount; i++ ) {
var _input = getInputJunctionIndex(i);
if(_input == noone) continue;
2024-08-08 06:57:51 +02:00
var _inp = inputs[_input];
if(!is_struct(_inp) || !is_instanceof(_inp, NodeValue)) continue;
_inp.visible_in_list = true;
2023-11-30 03:18:25 +01:00
}
2024-10-06 03:25:07 +02:00
outputs_index = array_create_ext(getOutputJunctionAmount(), function(index) { return getOutputJunctionIndex(index); });
}
2023-11-30 03:18:25 +01:00
2024-07-10 11:48:23 +02:00
static setHeight = function() {
2024-08-08 06:57:51 +02:00
w = SHOW_PARAM? attributes.node_param_width : min_w;
2023-11-08 08:38:04 +01:00
if(!auto_height) return;
2024-11-01 05:57:42 +01:00
var _ps = is_surface(getGraphPreviewSurface()) || preserve_height_for_preview;
2024-08-18 13:13:40 +02:00
var _ou = preview_channel >= 0 && preview_channel < array_length(outputs) && outputs[preview_channel].type == VALUE_TYPE.surface;
var _prev_surf = previewable && preview_draw && (_ps || _ou);
junction_draw_hei_y = SHOW_PARAM? 32 : 16;
junction_draw_pad_y = SHOW_PARAM? 128 : 24;
2024-03-28 14:18:02 +01:00
2024-07-10 11:48:23 +02:00
var _hi, _ho;
if(previewable) {
2024-08-09 13:30:09 +02:00
_hi = junction_draw_pad_y;
_ho = junction_draw_pad_y;
if(SHOW_PARAM) {
_hi = con_h;
_ho = con_h;
}
2024-07-10 11:48:23 +02:00
} else {
junction_draw_hei_y = 16;
junction_draw_pad_y = name_height / 2;
_hi = name_height;
_ho = name_height;
}
2023-11-08 08:38:04 +01:00
2024-07-10 11:48:23 +02:00
var _p = previewable;
for( var i = 0, n = array_length(inputs); i < n; i++ ) {
2024-08-08 06:57:51 +02:00
var _inp = inputs[i];
2024-07-10 11:48:23 +02:00
if(is_instanceof(_inp, NodeValue) && _inp.isVisible()) {
if(_p) _hi += junction_draw_hei_y;
_p = true;
}
2023-10-27 13:55:31 +02:00
}
2022-11-01 03:06:03 +01:00
2024-05-23 10:59:39 +02:00
if(auto_input && dummy_input) _hi += junction_draw_hei_y;
2024-07-10 11:48:23 +02:00
var _p = previewable;
2024-05-23 10:59:39 +02:00
for( var i = 0, n = array_length(outputs); i < n; i++ ) {
2024-08-08 06:57:51 +02:00
if(!outputs[i].isVisible()) continue;
if(_p) _ho += junction_draw_hei_y;
_p = true;
2024-07-10 11:48:23 +02:00
}
for( var i = 0, n = array_length(inputs); i < n; i++ ) {
2024-08-14 09:55:53 +02:00
var _inp = inputs[i];
var _byp = _inp.bypass_junc;
if(_byp == noone) continue;
_ho += junction_draw_hei_y * _byp.visible;
}
if(attributes.outp_meta) {
for( var i = 0, n = array_length(junc_meta); i < n; i++ ) {
if(!junc_meta[i].isVisible()) continue;
_ho += junction_draw_hei_y;
}
}
2024-11-23 07:26:39 +01:00
h = max(previewable? con_h : name_height, _prev_surf * 128, _hi, _ho);
2024-07-10 11:48:23 +02:00
if(attributes.node_height) h = max(h, attributes.node_height);
}
2023-02-14 02:51:14 +01:00
2024-08-08 06:57:51 +02:00
static getJunctionList = function() { ////getJunctionList
inputDisplayList = [];
2024-05-24 07:44:36 +02:00
2024-10-10 13:13:21 +02:00
var iamo = getInputAmount();
if(iamo && input_display_dynamic != -1) {
2024-10-10 13:13:21 +02:00
for(var i = 0; i < array_length(input_display_list_raw); i++) {
var ind = input_display_list_raw[i];
if(!is_real(ind)) continue;
var jun = array_safe_get(inputs, ind, noone);
if(jun == noone || is_undefined(jun)) continue;
if(!jun.isVisible()) continue;
array_push(inputDisplayList, jun);
}
for( var i = 0; i < iamo; i++ ) {
var ind = input_fix_len + i * data_length;
for( var j = 0, n = array_length(input_display_dynamic); j < n; j++ ) {
if(!is_real(input_display_dynamic[j])) continue;
var _in_ind = ind + input_display_dynamic[j];
var jun = array_safe_get(inputs, _in_ind, noone);
if(jun == noone || is_undefined(jun)) continue;
if(!jun.isVisible()) continue;
array_push(inputDisplayList, jun);
}
}
} else {
var amo = input_display_list == -1? array_length(inputs) : array_length(input_display_list);
// print($"Amo = {amo}");
2024-10-10 13:13:21 +02:00
for(var i = 0; i < amo; i++) {
var ind = getInputJunctionIndex(i);
if(ind == noone) continue;
var jun = array_safe_get(inputs, ind, noone);
if(jun == noone || is_undefined(jun)) continue;
// print($"{i}: {jun.isVisible()}");
// print($" {jun.visible_manual}, {jun.visible}, {jun.index}, {jun.visible_in_list}");
2024-10-10 13:13:21 +02:00
if(!jun.isVisible()) continue;
array_push(inputDisplayList, jun);
}
2023-01-25 06:49:00 +01:00
// print($"{inputDisplayList}\n");
2023-01-25 06:49:00 +01:00
}
if(auto_input && dummy_input) array_push(inputDisplayList, dummy_input);
// print(inputDisplayList);
2024-08-08 06:57:51 +02:00
}
2023-01-25 06:49:00 +01:00
2024-07-10 13:13:51 +02:00
static onValidate = function() {
value_validation[VALIDATION.pass] = 0;
value_validation[VALIDATION.warning] = 0;
value_validation[VALIDATION.error] = 0;
2024-08-18 13:13:40 +02:00
for( var i = 0; i < array_length(inputs); i++ ) {
2024-08-08 06:57:51 +02:00
var jun = inputs[i];
if(jun.value_validation)
value_validation[jun.value_validation]++;
}
2024-07-10 13:13:51 +02:00
}
2023-02-14 13:44:46 +01:00
2024-11-30 06:50:20 +01:00
static onIOValidate = function() {
var _inline_input = noone;
for( var i = 0, n = array_length(inputs); i < n; i++ ) {
var _j = inputs[i];
if(_j.value_from == noone) continue;
var _n = _j.value_from.node;
if(_n.inline_context == noone) continue;
if(_inline_input != noone && _inline_input != _n.inline_context)
logNode($"Node {getDisplayName()} connected to multiple inline loop inputs, this can cause render error.", 2);
_inline_input = _n.inline_context;
}
var _inline_output = noone;
for( var i = 0, n = array_length(outputs); i < n; i++ ) {
var _j = outputs[i];
var _t = _j.getJunctionTo();
for( var j = 0, m = array_length(_t); j < m; j++ ) {
var _n = _t[j].node;
if(_n.inline_context == noone) continue;
if(_inline_output != noone && _inline_output != _n.inline_context)
logNode($"Node {getDisplayName()} connected to multiple inline loop outputs, this can cause render error.", 2);
_inline_output = _n.inline_context;
}
}
if(_inline_input != noone && _inline_output != noone && _inline_input != inline_context) {
logNode($"Node {getDisplayName()} connected between two inline nodes, but the node itself is not part of the group. The program has automatically add the node back to inline group.", 1);
_inline_input.addNode(self);
}
}
2024-07-10 13:13:51 +02:00
static getJunctionTos = function() {
2024-08-18 13:13:40 +02:00
var _vto = array_create(array_length(outputs));
for (var j = 0; j < array_length(outputs); j++)
2024-08-08 06:57:51 +02:00
_vto[j] = array_clone(outputs[j].value_to);
return _vto;
2024-07-10 13:13:51 +02:00
}
2023-02-14 02:51:14 +01:00
2024-07-10 13:13:51 +02:00
static checkConnectGroup = function(_io) {
2024-08-08 06:57:51 +02:00
var _y = y;
var _n = noone;
2023-03-28 06:58:28 +02:00
2024-08-18 13:13:40 +02:00
for(var i = 0; i < array_length(inputs); i++) {
2024-08-08 06:57:51 +02:00
var _in = inputs[i];
if(_in.value_from == noone) continue;
if(_in.value_from.node.group == group) continue;
var _ind = string(_in.value_from);
_io.map[$ _ind] = _in.value_from;
if(struct_has(_io.inputs, _ind))
array_push(_io.inputs[$ _ind ], _in);
else
_io.inputs[$ _ind ] = [ _in ];
}
2023-09-28 13:15:29 +02:00
2024-08-18 13:13:40 +02:00
for(var i = 0; i < array_length(outputs); i++) {
2024-08-08 06:57:51 +02:00
var _ou = outputs[i];
for(var j = 0; j < array_length(_ou.value_to); j++) {
var _to = _ou.value_to[j];
if(_to.value_from != _ou) continue;
if(!_to.node.active) continue;
if(_to.node.group == group) continue;
var _ind = string(_ou);
_io.map[$ _ind] = _ou;
if(struct_has(_io.outputs, _ind))
array_push(_io.outputs[$ _ind ], _to);
else
_io.outputs[$ _ind ] = [ _to ];
2023-11-08 08:38:04 +01:00
}
2023-11-20 05:10:55 +01:00
}
2024-07-10 13:13:51 +02:00
}
2023-08-16 20:16:31 +02:00
2024-12-11 04:29:11 +01:00
////- INPUTS
2022-12-16 09:18:09 +01:00
set_default = true;
static skipDefault = function() /*=>*/ { set_default = false; return self; }
static resetDefault = function() {
var folder = instanceof(self);
if(!ds_map_exists(global.PRESETS_MAP, folder)) {
2024-08-18 13:13:40 +02:00
for( var i = 0, n = array_length(inputs); i < n; i++ )
2024-08-08 06:57:51 +02:00
inputs[i].resetValue();
return;
}
var pres = global.PRESETS_MAP[? folder];
for( var i = 0, n = array_length(pres); i < n; i++ ) {
var preset = pres[i];
if(preset.name != "_default") continue;
2023-10-27 13:55:31 +02:00
deserialize(loadPreset(preset), true, true);
applyDeserialize(true);
return;
2023-06-13 14:42:06 +02:00
}
2024-08-18 13:13:40 +02:00
for( var i = 0, n = array_length(inputs); i < n; i++ )
2024-08-08 06:57:51 +02:00
inputs[i].resetValue();
} if(!APPENDING && !LOADING) run_in(1, function() /*=>*/ { if(set_default) resetDefault() });
2024-07-10 13:13:51 +02:00
static addInput = function(junctionFrom, shift = input_fix_len) {
2024-07-02 13:25:59 +02:00
var targ = getInput(y, junctionFrom, shift);
if(targ == noone) return;
2023-06-13 14:42:06 +02:00
targ.setFrom(junctionFrom);
2024-07-10 13:13:51 +02:00
}
2023-06-04 18:28:29 +02:00
2024-12-11 12:44:48 +01:00
static getInputData = function(index, def = 0) { return inputs[index].getValue(); } /// array_safe_get_fast(inputs_data, index, def); }
2024-08-18 05:10:39 +02:00
static getInputDataForce = function(index, def = 0) { return inputs[index].getValue(); }
2024-08-06 14:04:41 +02:00
// static setInputData = function(index, value) {
2024-08-08 06:57:51 +02:00
// var _inp = inputs[index];
2024-08-06 14:04:41 +02:00
// inputs_data[index] = value;
// if(is_struct(_inp)) input_value_map[$ _inp.internalName] = value;
// }
2023-10-12 14:14:08 +02:00
2024-07-10 13:13:51 +02:00
static getInputs = function(frame = CURRENT_FRAME) {
2024-08-18 13:13:40 +02:00
inputs_data = array_verify(inputs_data, array_length(inputs));
2024-08-08 06:57:51 +02:00
__frame = frame;
array_foreach(inputs, function(_inp, i) /*=>*/ {
if(!is_instanceof(_inp, NodeValue)) return;
if(!_inp.isDynamic()) return;
2024-08-08 06:57:51 +02:00
var val = _inp.getValue(__frame);
2024-12-07 10:35:29 +01:00
if(_inp.bypass_junc.visible) _inp.bypass_junc.setValue(val);
inputs_data[i] = val; // setInputData(i, val);
2024-08-06 12:39:22 +02:00
input_value_map[$ _inp.internalName] = val;
2024-08-08 06:57:51 +02:00
});
2024-07-10 13:13:51 +02:00
}
2023-10-02 14:41:44 +02:00
2024-12-11 04:29:11 +01:00
////- UPDATE
2024-07-10 13:13:51 +02:00
static forceUpdate = function() {
2023-10-02 14:41:44 +02:00
input_hash = "";
doUpdate();
2024-07-10 13:13:51 +02:00
}
static postUpdate = function(frame = CURRENT_FRAME) {}
2024-12-07 10:35:29 +01:00
static doUpdateLite = function(frame = CURRENT_FRAME) {
render_timer = get_timer();
setRenderStatus(true);
if(attributes.update_graph) {
try { update(frame); }
catch(e) { log_warning("RENDER", exception_print(e), self); }
}
render_time = get_timer() - render_timer;
}
static doUpdateFull = function(frame = CURRENT_FRAME) {
2024-08-08 06:57:51 +02:00
2023-11-01 08:10:25 +01:00
if(PROJECT.safeMode) return;
if(NODE_EXTRACT) return;
2024-12-07 10:35:29 +01:00
render_timer = get_timer();
2024-04-30 05:57:34 +02:00
var _updateRender = !is_instanceof(self, Node_Collection) || !managedRenderOrder;
if(_updateRender) setRenderStatus(true);
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;
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} <<<<<<<<<<");
var sBase = surface_get_target();
2023-10-02 14:41:44 +02:00
try {
if(attributes.update_graph) 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
2024-08-08 06:57:51 +02:00
if(!IS_PLAYING) {
array_foreach(inputs, function(in, i) /*=>*/ { in.updateColor(getInputData(i)); });
array_foreach(outputs, function(in, i) /*=>*/ { in.updateColor(in.getValue()); });
}
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) {
2024-08-18 13:13:40 +02:00
for( var i = 0; i < array_length(outputs); i++ ) {
2024-08-08 06:57:51 +02:00
if(outputs[i].type != VALUE_TYPE.surface) continue;
cacheCurrentFrame(outputs[i].getValue());
2023-07-08 20:29:23 +02:00
break;
}
}
if(hasInspector1Update() && inspectInput1.getValue()) onInspector1Update(true);
if(hasInspector2Update() && inspectInput2.getValue()) onInspector2Update(true);
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
2024-12-07 10:35:29 +01:00
if(!is(self, Node_Collection)) render_time = get_timer() - render_timer;
2023-10-03 07:14:28 +02:00
LOG_BLOCK_END();
2024-07-10 13:13:51 +02:00
}
2023-02-14 02:51:14 +01:00
2024-12-07 10:35:29 +01:00
doUpdate = doUpdateFull;
2024-07-10 13:13:51 +02:00
static valueUpdate = function(index) {
2023-02-14 02:51:14 +01:00
onValueUpdate(index);
cacheCheck();
2024-07-10 13:13:51 +02:00
}
2023-11-02 14:37:13 +01:00
2024-07-10 13:13:51 +02:00
static valueFromUpdate = function(index) {
2023-11-02 14:37:13 +01:00
onValueFromUpdate(index);
onValueUpdate(index);
2024-05-23 10:59:39 +02:00
if(auto_input && !LOADING && !APPENDING)
refreshDynamicInput();
cacheCheck();
2024-07-10 13:13:51 +02:00
}
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
2024-12-11 04:29:11 +01:00
////- RENDER
2024-12-07 10:35:29 +01:00
static isAnimated = function(frame = CURRENT_FRAME) {
if(update_on_frame) return true;
return array_any(inputs, function(inp) /*=>*/ {return inp.is_anim});
}
2024-07-10 13:13:51 +02:00
static isActiveDynamic = function(frame = CURRENT_FRAME) {
if(update_on_frame) return true;
if(!rendered) return true;
force_requeue = false;
2024-08-12 13:42:05 +02:00
__temp_frame = frame;
return array_any(inputs, function(inp) /*=>*/ {return inp.isActiveDynamic(__temp_frame)});
2024-07-10 13:13:51 +02:00
}
2024-07-19 05:20:18 +02:00
static triggerRender = function(resetSelf = true) {
LOG_BLOCK_START();
2024-03-31 11:10:14 +02:00
LOG_IF(global.FLAG.render == 1, $"Trigger render for {self}");
2023-03-28 06:58:28 +02:00
2024-07-19 05:20:18 +02:00
if(resetSelf) resetRender(false);
2023-10-08 04:14:35 +02:00
RENDER_PARTIAL
2023-03-26 07:13:36 +02:00
if(is_instanceof(group, Node_Collection)) {
group.triggerRender();
2023-06-01 10:32:21 +02:00
} else {
var nodes = getNextNodesRaw();
for(var i = 0; i < array_length(nodes); i++)
nodes[i].triggerRender();
}
LOG_BLOCK_END();
2024-07-10 13:13:51 +02:00
}
2023-06-01 10:32:21 +02:00
2023-12-22 04:15:04 +01:00
static clearTopoSorted = function() { INLINE topoSorted = false; }
2024-07-10 13:13:51 +02:00
static forwardPassiveDynamic = function() {
2023-12-22 04:15:04 +01:00
rendered = false;
2024-08-18 13:13:40 +02:00
for( var i = 0, n = array_length(outputs); i < n; i++ ) {
2024-08-08 06:57:51 +02:00
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;
2024-02-11 14:53:33 +01:00
//LOG_IF(global.FLAG.render == 1, $"|| Forwarding dynamic to {_to.node.name} ||");
2023-10-07 16:23:40 +02:00
_to.node.passiveDynamic = true;
2023-12-22 04:15:04 +01:00
_to.node.rendered = false;
}
}
2024-07-10 13:13:51 +02:00
}
2024-07-10 13:13:51 +02:00
static resetRender = function(_clearCache = false) {
2023-10-08 08:02:38 +02:00
setRenderStatus(false);
if(_clearCache) clearInputCache();
2024-07-10 13:13:51 +02:00
}
2023-10-08 08:02:38 +02:00
2024-07-10 13:13:51 +02:00
static isLeaf = function() {
2024-03-31 05:36:11 +02:00
INLINE
2024-08-18 13:13:40 +02:00
for( var i = 0, n = array_length(inputs); i < n; i++ ) {
2024-08-08 06:57:51 +02:00
var _inp = inputs[i];
if(!_inp.value_from == noone) return false;
2024-03-31 05:36:11 +02:00
}
return true;
2024-07-10 13:13:51 +02:00
}
2024-03-31 05:36:11 +02:00
2024-07-10 13:13:51 +02:00
static isLeafList = function(list = noone) {
2024-03-31 05:36:11 +02:00
INLINE
if(list == noone) return isLeaf();
2024-08-18 13:13:40 +02:00
for( var i = 0, n = array_length(inputs); i < n; i++ ) {
2024-08-08 06:57:51 +02:00
var _inp = inputs[i].value_from;
if(_inp != noone && array_exists(list, _inp.node))
return false;
2023-10-27 13:55:31 +02:00
}
return true;
2024-07-10 13:13:51 +02:00
}
2023-10-27 13:55:31 +02:00
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
static isRenderable = function(log = false) { //Check if every input is ready (updated)
2024-08-08 06:57:51 +02:00
if(!active || !isRenderActive()) return false;
2022-01-24 02:21:25 +01:00
for(var j = 0; j < array_length(inputs); j++) {
if(!inputs[j].isRendered()) {
LOG_IF(global.FLAG.render == 1, $"→→ x Node {internalName} {inputs[j]} not rendered.");
return false;
}
}
2022-01-24 02:21:25 +01:00
return true;
}
2022-01-24 02:21:25 +01:00
2024-07-10 13:13:51 +02:00
static setRenderStatus = function(result) {
INLINE
if(rendered == result) return;
2024-11-30 06:50:20 +01:00
logNodeDebug($"Set render status for {getFullName()} : {result}", 3);
rendered = result;
2024-07-10 13:13:51 +02:00
}
2024-07-10 13:13:51 +02:00
static getPreviousNodes = function() {
2023-12-22 04:15:04 +01:00
var prev = [];
2024-12-04 12:20:29 +01:00
var prMp = {};
var _n;
2023-12-22 04:15:04 +01:00
2024-12-04 12:20:29 +01:00
if(attributes.show_update_trigger && updatedInTrigger.value_from) {
_n = updatedInTrigger.value_from.node;
if(!struct_has(prMp, _n.node_id)) {
array_push(prev, _n);
prMp[$ _n.node_id] = 1;
}
}
2024-08-18 13:13:40 +02:00
for( var i = 0, n = array_length(inputs); i < n; i++ ) {
2024-08-08 06:57:51 +02:00
var _in = inputs[i];
2023-12-22 04:15:04 +01:00
if(_in.value_from != noone) {
if(in_VFX && !_in.value_from.node.in_VFX) {
array_push(in_VFX.prev_nodes, _in.value_from.node);
2024-12-04 12:20:29 +01:00
if(!struct_has(prMp, in_VFX.node_id)) {
array_push(prev, in_VFX);
prMp[$ in_VFX.node_id] = 1;
}
2023-12-22 04:15:04 +01:00
continue;
}
2024-12-04 12:20:29 +01:00
_n = _in.value_from.node;
if(!struct_has(prMp, _n.node_id)) {
array_push(prev, _n);
prMp[$ _n.node_id] = 1;
}
2023-12-22 04:15:04 +01:00
}
2024-12-04 12:20:29 +01:00
if(_in.value_from_loop != noone) {
_n = _in.value_from_loop;
if(!struct_has(prMp, _n.node_id)) {
array_push(prev, _n);
prMp[$ _n.node_id] = 1;
}
}
2023-12-22 04:15:04 +01:00
}
onGetPreviousNodes(prev);
return prev;
2024-07-10 13:13:51 +02:00
}
2023-12-22 04:15:04 +01:00
static onGetPreviousNodes = function(arr) {}
2024-12-07 10:35:29 +01:00
__nextNodes = noone;
__nextNodesToLoop = noone;
static getNextNodes = function(checkLoop = false) {
if(checkLoop) {
if(__nextNodesToLoop != noone && __nextNodesToLoop.bypassNextNode())
__nextNodesToLoop.getNextNodes();
return;
}
2024-12-07 10:35:29 +01:00
__nextNodesToLoop = noone;
2024-08-18 13:13:40 +02:00
for(var i = 0; i < array_length(outputs); i++) {
2024-08-08 06:57:51 +02:00
var _ot = outputs[i];
2024-08-14 09:55:53 +02: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];
2024-12-07 10:35:29 +01:00
if(!_to.active) continue;
2023-12-19 14:30:34 +01:00
2024-12-07 10:35:29 +01:00
__nextNodesToLoop = _to;
if(!_to.bypassNextNode()) continue;
2023-12-19 14:30:34 +01:00
return _to.getNextNodes();
}
2024-12-07 10:35:29 +01:00
}
2023-12-19 14:30:34 +01:00
2024-12-07 10:35:29 +01:00
if(__nextNodes != noone) return __nextNodes;
var nodes = [];
for(var i = 0; i < array_length(outputs); i++) {
var _ot = outputs[i];
if(!_ot.forward) continue;
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-28 06:58:28 +02:00
array_push(nodes, _to.node);
2022-01-13 05:24:03 +01:00
}
2023-03-26 07:13:36 +02:00
}
2023-03-28 06:58:28 +02:00
2024-11-02 05:10:04 +01:00
for(var i = 0; i < array_length(junc_meta); i++) {
var _ot = junc_meta[i];
var _tos = _ot.getJunctionTo();
for( var j = 0; j < array_length(_tos); j++ ) {
var _to = _tos[j];
array_push(nodes, _to.node);
}
}
2024-08-18 13:13:40 +02:00
for(var i = 0; i < array_length(inputs); i++) {
2024-08-14 09:55:53 +02:00
var _in = inputs[i];
if(_in.bypass_junc == noone) continue;
var _tos = _in.bypass_junc.getJunctionTo();
for( var j = 0; j < array_length(_tos); j++ ) {
var _to = _tos[j];
array_push(nodes, _to.node);
}
}
2024-12-07 10:35:29 +01:00
__nextNodes = nodes;
2023-03-28 06:58:28 +02:00
return nodes;
2024-07-10 13:13:51 +02:00
}
2022-01-13 05:24:03 +01:00
2024-07-10 13:13:51 +02:00
static getNextNodesRaw = function() {
2023-10-19 11:34:29 +02:00
var nodes = [];
2024-08-18 13:13:40 +02:00
for(var i = 0; i < array_length(outputs); i++) {
2024-08-08 06:57:51 +02:00
var _ot = outputs[i];
2023-10-19 11:34:29 +02:00
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);
}
2024-08-18 13:13:40 +02:00
for(var i = 0; i < array_length(inputs); i++) {
2024-08-14 09:55:53 +02:00
var _in = inputs[i];
if(_in.bypass_junc == noone) continue;
var _tos = _in.bypass_junc.getJunctionTo();
for( var j = 0; j < array_length(_tos); j++ )
array_push(nodes, _tos[j].node);
}
2023-10-19 11:34:29 +02:00
return nodes;
2024-07-10 13:13:51 +02:00
}
2023-10-19 11:34:29 +02:00
2024-12-11 04:29:11 +01:00
////- DRAW
2023-07-21 12:40:20 +02:00
2024-11-23 07:26:39 +01:00
static setShowParameter = function(showParam) {
show_parameter = showParam;
refreshNodeDisplay();
return self;
}
static setPreviewable = function(prev) {
if(previewable == prev) return;
previewable = prev;
y += previewable? -16 : 16;
}
2022-09-23 13:28:42 +02:00
static onInspect = function() {}
2024-07-10 13:13:51 +02:00
static pointIn = function(_x, _y, _mx, _my, _s) {
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);
2024-07-10 13:13:51 +02:00
}
2022-01-13 05:24:03 +01:00
2024-07-10 13:13:51 +02:00
static cullCheck = function(_x, _y, _s, minx, miny, maxx, maxy) {
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;
2024-03-29 05:20:49 +01:00
draw_boundary[0] = minx;
draw_boundary[1] = miny;
draw_boundary[2] = maxx;
draw_boundary[3] = maxy;
2023-06-17 14:30:49 +02:00
draw_graph_culled = !rectangle_in_rectangle(minx, miny, maxx, maxy, x0, y0, x1, y1);
2024-11-23 07:26:39 +01:00
return !draw_graph_culled;
2024-07-10 13:13:51 +02:00
}
2023-06-17 14:30:49 +02:00
2024-07-10 13:13:51 +02:00
static refreshNodeDisplay = function() {
// print("refreshNodeDisplay"); printCallStack();
// if(IS_PLAYING) return;
2024-03-31 11:10:14 +02:00
updateIO();
setHeight();
getJunctionList();
2024-11-24 06:07:17 +01:00
setJunctionIndex();
2024-11-24 11:39:17 +01:00
__preDraw_data.force = true;
} run_in(1, function() /*=>*/ { refreshNodeDisplay(); });
2024-03-31 11:10:14 +02:00
__preDraw_data = { _x: undefined, _y: undefined, _w: undefined, _h: undefined, _s: undefined, _p: undefined, sp: undefined, force: false };
2024-11-23 07:26:39 +01:00
2024-07-10 13:13:51 +02:00
static preDraw = function(_x, _y, _s) {
2022-01-26 06:57:34 +01:00
var xx = x * _s + _x;
var yy = y * _s + _y;
2024-11-23 07:26:39 +01:00
var _d = __preDraw_data;
var _upd = _d._x != xx || _d._y != yy || _d._s != _s || _d.force || _d._w != w || _d._h != h || _d._p != previewable || _d.sp != show_parameter
2024-11-23 07:26:39 +01:00
_d._x = xx;
_d._y = yy;
_d._w = w;
_d._h = h;
_d._s = _s;
_d._p = previewable;
_d.sp = show_parameter;
2024-11-23 07:26:39 +01:00
_d.force = false;
2024-11-24 11:39:17 +01:00
2024-11-23 07:26:39 +01:00
if(!_upd) {
if(SHOW_PARAM) h = h_param;
onPreDraw(_x, _y, _s, _iy, _oy);
return;
}
2022-09-21 06:09:40 +02:00
var jun;
2022-12-13 09:20:36 +01:00
var inspCount = hasInspector1Update() + hasInspector2Update();
2023-03-28 06:58:28 +02:00
var ind = 1;
if(hasInspector1Update()) {
2023-03-28 06:58:28 +02:00
inspectInput1.x = xx + w * _s * ind / (inspCount + 1);
inspectInput1.y = yy;
ind++;
}
if(hasInspector2Update()) {
2023-03-28 06:58:28 +02:00
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
2024-08-18 13:13:40 +02:00
if(in_cache_len != array_length(inputDisplayList) || out_cache_len != array_length(outputs)) {
2024-03-31 11:10:14 +02:00
refreshNodeDisplay();
2023-11-30 03:18:25 +01:00
2024-03-29 05:20:49 +01:00
in_cache_len = array_length(inputDisplayList);
2024-08-18 13:13:40 +02:00
out_cache_len = array_length(outputs);
2023-11-30 03:18:25 +01:00
}
2024-08-09 13:30:09 +02:00
var _junRy = junction_draw_pad_y;
var _junSy = yy + _junRy * _s;
if(SHOW_PARAM) {
_junRy = con_h + junction_draw_hei_y / 2;
_junSy = yy + _junRy * _s;
}
2024-11-23 07:26:39 +01:00
__s = _s;
2024-11-26 05:52:57 +01:00
_ix = xx; _rix = x;
_iy = _junSy; _riy = y + _junRy;
2024-11-26 05:52:57 +01:00
_ox = xx + w * _s; _rox = x + w;
_oy = _junSy; _roy = y + _junRy;
2024-11-23 07:26:39 +01:00
array_foreach(inputs, function(jun) /*=>*/ { jun.x = _ix; jun.y = _iy; });
2024-03-28 14:18:02 +01:00
2024-11-26 05:52:57 +01:00
array_foreach(inputDisplayList, function(jun) /*=>*/ {
jun.x = _ix; jun.rx = _rix;
jun.y = _iy; jun.ry = _riy;
_riy += junction_draw_hei_y;
_iy += junction_draw_hei_y * __s;
});
array_foreach(outputs_index, function(jun) /*=>*/ {
jun = outputs[jun];
jun.x = _ox; jun.rx = _rox;
jun.y = _oy; jun.ry = _roy;
var __vis = jun.isVisible();
_roy += junction_draw_hei_y * __vis
_oy += junction_draw_hei_y * __vis * __s;
});
2023-10-07 09:09:18 +02:00
2024-11-23 07:26:39 +01:00
array_foreach(inputs, function(jun) /*=>*/ { jun = jun.bypass_junc; if(!jun.visible) return;
jun.x = _ox; jun.y = _oy; _oy += junction_draw_hei_y * jun.visible * __s; });
array_foreach(junc_meta, function(jun) /*=>*/ { jun.x = _ox; jun.y = _oy; _oy += junction_draw_hei_y * jun.isVisible() * __s; });
if(SHOW_PARAM) h = h_param;
2024-08-09 13:30:09 +02:00
onPreDraw(_x, _y, _s, _iy, _oy);
2024-07-10 13:13:51 +02:00
}
2023-10-07 09:09:18 +02:00
static onPreDraw = function(_x, _y, _s, _iny, _outy) {}
2024-07-10 13:13:51 +02:00
static isHighlightingInGraph = function() {
2024-01-26 14:38:50 +01:00
var high = display_parameter.highlight;
2023-10-12 07:07:24 +02:00
var _selc = active_draw_index == 0 || branch_drawing;
return !high || _selc;
2024-07-10 13:13:51 +02:00
}
2023-10-12 07:07:24 +02:00
static getColor = function() { INLINE return attributes.color == -1? color : attributes.color; }
2023-10-16 07:25:22 +02:00
2024-11-23 07:26:39 +01:00
static drawNodeBase = function(xx, yy, _s) {
2024-11-24 11:39:17 +01:00
draw_sprite_stretched_ext(bg_spr, 0, xx, yy, w * _s, h * _s, getColor(), .75 * (.25 + .75 * isHighlightingInGraph()));
2024-11-23 07:26:39 +01:00
}
2022-01-13 05:24:03 +01:00
2024-07-03 05:16:46 +02:00
static drawNodeOverlay = function(xx, yy, _mx, _my, _s) {}
2024-03-31 11:10:14 +02:00
__draw_bbox = BBOX();
static drawGetBbox = function(xx, yy, _s, label = true) {
2024-12-07 10:35:29 +01:00
var pad_label = ((display_parameter.avoid_label || label) && draw_name) || label == 2;
2023-08-16 20:16:31 +02:00
var x0 = xx;
var x1 = xx + w * _s;
var y0 = yy;
var y1 = yy + h * _s;
if(pad_label) y0 += name_height * _s;
2024-11-29 06:18:28 +01:00
if(SHOW_PARAM) y1 = yy + con_h * _s;
2023-08-16 20:16:31 +02:00
2024-11-29 06:18:28 +01:00
x0 += max(draw_padding, draw_pad_w) * _s;
x1 -= max(draw_padding, draw_pad_w) * _s;
y0 += max(draw_padding, draw_pad_h) * _s;
y1 -= max(draw_padding, draw_pad_h) * _s;
2023-08-16 20:16:31 +02:00
var _w = x1 - x0;
var _h = y1 - y0;
var _xc = (x0 + x1) / 2;
var _yc = (y0 + y1) / 2;
2024-03-28 14:18:02 +01:00
_w *= display_parameter.preview_scale / 100;
_h *= display_parameter.preview_scale / 100;
2023-08-16 20:16:31 +02:00
x0 = _xc - _w / 2;
x1 = _xc + _w / 2;
y0 = _yc - _h / 2;
y1 = _yc + _h / 2;
2023-01-04 02:30:04 +01:00
2024-03-31 11:10:14 +02:00
return __draw_bbox.fromPoints(x0, y0, x1, y1);
2024-07-10 13:13:51 +02:00
}
2023-01-04 02:30:04 +01:00
static drawNodeName = function(xx, yy, _s, _panel = noone) {
var _name = renamed? display_name : name;
2023-02-14 02:51:14 +01:00
if(_name == "") return;
2023-01-04 02:30:04 +01:00
draw_name = true;
2022-12-10 05:06:01 +01:00
var aa = (.25 + .5 * renderActive) * (.25 + .75 * isHighlightingInGraph());
2023-10-16 07:25:22 +02:00
var cc = getColor();
2024-07-10 11:48:23 +02:00
var nh = previewable? name_height * _s : h * _s;
var ba = aa;
2023-10-12 07:07:24 +02:00
if(_panel && _panel.node_hovering == self) ba = .1;
draw_sprite_stretched_ext(THEME.node_bg, 2, xx, yy, w * _s, nh, cc, ba);
2022-12-10 05:06:01 +01:00
2024-11-24 11:39:17 +01:00
var cc = renderActive? COLORS._main_text : COLORS._main_text_sub;
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
aa += 0.25;
2023-10-12 07:07:24 +02:00
2024-07-10 11:48:23 +02:00
var tx = xx + 6 * _s;
var tw = w * _s - 8 * _s;
2024-07-10 11:48:23 +02:00
if(_panel && _panel.is_searching && _panel.search_string != "" && search_match == -9999)
aa *= .15;
2024-07-10 11:48:23 +02:00
if(icon) {
tx += _s * 6;
2024-12-07 10:35:29 +01:00
draw_sprite_ui_uniform(icon, 0, round(tx) + 1, round(yy + nh / 2) + 1, _s, c_black, 1);
draw_sprite_ui_uniform(icon, 0, round(tx), round(yy + nh / 2), _s, icon_blend, 1);
tx += _s * 12;
tw -= _s * (12 + 6);
2024-07-10 11:48:23 +02:00
}
2023-02-19 13:49:20 +01:00
var _ts = _s * 0.275;
var _tx = round(tx);
var _ty = round(yy + nh / 2 + 1);
2024-07-10 11:48:23 +02:00
draw_set_text(f_sdf, fa_left, fa_center, cc, aa);
var _txt = string_cut(_name, tw, "...", _ts);
BLEND_ALPHA_MULP
draw_set_color(0); draw_set_alpha(1); draw_text_transformed(_tx + 1, _ty + 1, _txt, _ts, _ts, 0);
draw_set_color(cc); draw_set_alpha(1); draw_text_transformed(_tx, _ty, _txt, _ts, _ts, 0);
BLEND_NORMAL
2023-02-19 13:49:20 +01:00
draw_set_alpha(1);
}
2022-01-13 05:24:03 +01:00
2024-07-10 13:13:51 +02:00
static drawJunctionWidget = function(_x, _y, _mx, _my, _s, _hover, _focus) {
2024-04-01 11:10:01 +02:00
2024-03-28 14:18:02 +01:00
var hover = noone;
var _m = [ _mx, _my ];
var pd = junction_draw_pad_y * _s;
2024-03-29 09:13:26 +01:00
var wh = junction_draw_hei_y * _s;
2024-03-28 14:18:02 +01:00
var ww = w * _s * 0.5;
2024-04-01 11:10:01 +02:00
var wt = w * _s * 0.25;
2024-03-28 14:18:02 +01:00
var wx = _x + w * _s - ww - 8;
var lx = _x + 12 * _s;
var jy = _y + con_h * _s + wh / 2;
2024-03-28 14:18:02 +01:00
var rx = PANEL_GRAPH.x;
var ry = PANEL_GRAPH.y;
var extY = 0;
var drwT = _s > 0.5;
2024-03-29 05:20:49 +01:00
2024-03-29 09:13:26 +01:00
for(var i = 0, n = array_length(inputDisplayList); i < n; i++) {
var jun = inputDisplayList[i];
2024-03-31 05:36:11 +02:00
var wd = jun.graphWidget;
jun.y = jy;
if(drwT) {
2024-04-01 11:10:01 +02:00
draw_set_text(f_sdf, fa_left, fa_center, jun.color_display);
draw_text_add(lx, jun.y, jun.getName(), _s * 0.25);
} else {
draw_set_color(jun.color_display);
draw_rectangle(lx, jun.y - 1 * _s, lx + wt, jun.y + 4 * _s, false);
}
2024-03-31 05:36:11 +02:00
2024-03-31 11:10:14 +02:00
if(jun.value_from || wd == noone) {
2024-08-09 13:30:09 +02:00
extY += junction_draw_hei_y;
jy += wh;
2024-03-31 05:36:11 +02:00
continue;
}
2024-03-28 14:18:02 +01:00
2024-03-29 09:13:26 +01:00
var _param = jun.graphWidgetP;
2024-03-28 14:18:02 +01:00
2024-03-29 09:13:26 +01:00
_param.w = ww;
_param.h = wh - 4 * _s;
_param.x = wx;
_param.y = jy - _param.h / 2;
2024-03-29 09:13:26 +01:00
_param.data = jun.showValue();
_param.m = _m;
_param.rx = rx;
_param.ry = ry;
_param.s = wh;
_param.font = f_p2;
_param.color = getColor();
2024-03-28 14:18:02 +01:00
2024-03-29 09:13:26 +01:00
if(is_instanceof(jun, checkBox))
_param.halign = fa_center;
2024-03-29 05:20:49 +01:00
2024-03-29 09:13:26 +01:00
wd.setInteract(wh > line_get_height(f_p2));
wd.setFocusHover(_focus, _hover);
var _h = wd.drawParam(_param);
jun.graphWidgetH = _h / _s;
extY += max(0, jun.graphWidgetH + 4);
jy += (jun.graphWidgetH + 4) * _s;
2024-03-29 09:13:26 +01:00
if(wd.isHovering()) draggable = false;
2024-03-29 05:20:49 +01:00
}
2024-03-29 09:13:26 +01:00
2024-08-09 13:30:09 +02:00
h = con_h + extY + 4;
h_param = h;
2024-07-10 13:13:51 +02:00
}
2024-03-28 14:18:02 +01:00
2024-11-24 06:07:17 +01:00
static drawJunctions = function(_draw, _x, _y, _mx, _my, _s) {
2022-01-13 05:24:03 +01:00
var hover = noone;
gpu_set_texfilter(true);
2022-01-13 05:24:03 +01:00
2024-10-10 13:13:21 +02:00
for(var i = 0, n = array_length(inputDisplayList); i < n; i++) { //inputs
2024-03-29 05:20:49 +01:00
var jun = inputDisplayList[i];
2022-01-13 05:24:03 +01:00
2024-11-24 06:07:17 +01:00
if(jun.drawJunction(_draw, _s, _mx, _my)) hover = jun;
2022-01-13 05:24:03 +01:00
}
2024-10-10 13:13:21 +02:00
for(var i = 0; i < array_length(outputs); i++) { // outputs
2024-08-08 06:57:51 +02:00
var jun = outputs[i];
2022-01-13 05:24:03 +01:00
2024-08-14 09:55:53 +02:00
if(!jun.isVisible()) continue;
2024-11-24 06:07:17 +01:00
if(jun.drawJunction(_draw, _s, _mx, _my)) hover = jun;
2022-01-13 05:24:03 +01:00
}
2024-10-10 13:13:21 +02:00
for( var i = 0; i < array_length(inputs); i++ ) { // bypass
2024-08-14 09:55:53 +02:00
var _inp = inputs[i];
2024-10-10 13:13:21 +02:00
var jun = _inp.bypass_junc;
2023-03-28 06:58:28 +02:00
2024-08-14 09:55:53 +02:00
if(jun == noone || !jun.visible) continue;
2024-11-24 06:07:17 +01:00
if(jun.drawJunction(_draw, _s, _mx, _my)) hover = jun;
2024-08-14 09:55:53 +02:00
}
2024-11-24 06:07:17 +01:00
if(hasInspector1Update() && inspectInput1.drawJunction(_draw, _s, _mx, _my)) hover = inspectInput1;
if(hasInspector2Update() && inspectInput2.drawJunction(_draw, _s, _mx, _my)) hover = inspectInput2;
2023-03-28 06:58:28 +02:00
2023-10-06 11:51:11 +02:00
if(attributes.show_update_trigger) {
2024-11-24 06:07:17 +01:00
if(updatedInTrigger.drawJunction(_draw, _s, _mx, _my)) hover = updatedInTrigger;
if(updatedOutTrigger.drawJunction(_draw, _s, _mx, _my)) hover = updatedOutTrigger;
2023-10-06 11:51:11 +02:00
}
2023-09-28 13:15:29 +02:00
if(attributes.outp_meta) {
for(var i = 0; i < array_length(junc_meta); i++) { // outputs
var jun = junc_meta[i];
if(!jun.isVisible()) continue;
2024-11-24 06:07:17 +01:00
if(jun.drawJunction(_draw, _s, _mx, _my)) hover = jun;
}
}
2023-10-07 09:09:18 +02:00
onDrawJunctions(_x, _y, _mx, _my, _s);
2024-03-31 11:10:14 +02:00
gpu_set_texfilter(false);
2024-03-31 11:10:14 +02:00
return hover;
2024-07-10 11:48:23 +02:00
}
2024-03-31 11:10:14 +02:00
2024-11-24 06:07:17 +01:00
static drawJunctions_fast = function(_draw, _x, _y, _mx, _my, _s) {
2024-03-31 11:10:14 +02:00
var hover = noone;
draw_set_circle_precision(4);
for(var i = 0, n = array_length(inputDisplayList); i < n; i++) {
var jun = inputDisplayList[i];
2024-11-24 06:07:17 +01:00
if(jun.drawJunction_fast(_draw, _s, _mx, _my)) hover = jun;
2024-03-31 11:10:14 +02:00
}
2024-08-18 13:13:40 +02:00
for(var i = 0; i < array_length(outputs); i++) {
2024-08-08 06:57:51 +02:00
var jun = outputs[i];
2024-03-31 11:10:14 +02:00
2024-08-14 09:55:53 +02:00
if(!jun.isVisible()) continue;
2024-11-24 06:07:17 +01:00
if(jun.drawJunction_fast(_draw, _s, _mx, _my)) hover = jun;
2024-03-31 11:10:14 +02:00
}
2024-08-18 13:13:40 +02:00
for( var i = 0; i < array_length(inputs); i++ ) {
2024-08-14 09:55:53 +02:00
var _inp = inputs[i];
var jun = _inp.bypass_junc;
2024-03-31 11:10:14 +02:00
2024-08-14 09:55:53 +02:00
if(jun == noone || !jun.visible) continue;
2024-11-24 06:07:17 +01:00
if(jun.drawJunction_fast(_draw, _s, _mx, _my)) hover = jun;
2024-08-14 09:55:53 +02:00
}
2024-11-24 06:07:17 +01:00
if(hasInspector1Update() && inspectInput1.drawJunction_fast(_draw, _s, _mx, _my)) hover = inspectInput1;
if(hasInspector2Update() && inspectInput2.drawJunction_fast(_draw, _s, _mx, _my)) hover = inspectInput2;
2024-03-31 11:10:14 +02:00
if(attributes.show_update_trigger) {
2024-11-24 06:07:17 +01:00
if(updatedInTrigger.drawJunction_fast(_draw, _s, _mx, _my)) hover = updatedInTrigger;
if(updatedOutTrigger.drawJunction_fast(_draw, _s, _mx, _my)) hover = updatedOutTrigger;
2024-03-31 11:10:14 +02:00
}
if(attributes.outp_meta) {
for(var i = 0; i < array_length(junc_meta); i++) { // outputs
var jun = junc_meta[i];
if(!jun.isVisible()) continue;
2024-11-24 06:07:17 +01:00
if(jun.drawJunction_fast(_draw, _s, _mx, _my)) hover = jun;
}
}
2024-07-10 11:48:23 +02:00
onDrawJunctions(_x, _y, _mx, _my, _s);
2023-11-17 06:24:31 +01:00
2022-01-13 05:24:03 +01:00
return hover;
2024-07-10 11:48:23 +02:00
}
2022-01-13 05:24:03 +01:00
2023-10-07 09:09:18 +02:00
static onDrawJunctions = function(_x, _y, _mx, _my, _s) {}
2024-07-10 13:13:51 +02:00
static drawJunctionNames = function(_x, _y, _mx, _my, _s) {
2024-08-18 13:13:40 +02:00
var amo = input_display_list == -1? array_length(inputs) : array_length(input_display_list);
2022-09-27 06:37:28 +02:00
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);
2024-07-02 13:25:59 +02:00
2024-07-10 11:48:23 +02:00
show_input_name = _hov;
show_output_name = _hov;
2022-09-27 06:37:28 +02:00
2024-07-10 11:48:23 +02:00
var _y0 = previewable? yy + name_height * _s : yy;
var _y1 = yy + h * _s;
show_input_name &= point_in_rectangle(_mx, _my, xx - ( 12) * _s, _y0, xx + ( 12) * _s, _y1);
show_output_name &= point_in_rectangle(_mx, _my, xx + (w - 12) * _s, _y0, xx + (w + 12) * _s, _y1);
2024-08-14 09:55:53 +02:00
2024-07-02 13:25:59 +02:00
if(PANEL_GRAPH.value_dragging && PANEL_GRAPH.node_hovering == self) {
2024-08-20 10:15:53 +02:00
if(PANEL_GRAPH.value_dragging.connect_type == CONNECT_TYPE.input) show_output_name = true;
if(PANEL_GRAPH.value_dragging.connect_type == CONNECT_TYPE.output) show_input_name = true;
2024-07-02 13:25:59 +02:00
}
2022-09-27 06:37:28 +02:00
if(show_input_name) {
2024-03-29 05:20:49 +01:00
for(var i = 0, n = array_length(inputDisplayList); i < n; i++) {
var jun = inputDisplayList[i];
jun.drawNameBG(_s);
2022-09-27 06:37:28 +02:00
}
2024-03-29 05:20:49 +01:00
for(var i = 0, n = array_length(inputDisplayList); i < n; i++) {
var jun = inputDisplayList[i];
jun.drawName(_s, _mx, _my);
2022-09-27 06:37:28 +02:00
}
}
if(show_output_name) {
2024-08-18 13:13:40 +02:00
for(var i = 0; i < array_length(outputs); i++)
2024-08-08 06:57:51 +02:00
if(outputs[i].isVisible()) outputs[i].drawNameBG(_s);
2022-09-27 06:37:28 +02:00
2024-08-18 13:13:40 +02:00
for( var i = 0; i < array_length(inputs); i++ ) {
2024-08-14 09:55:53 +02:00
var jun = inputs[i].bypass_junc;
if(jun == noone || !jun.visible) continue;
jun.drawNameBG(_s);
}
2024-08-18 13:13:40 +02:00
for(var i = 0; i < array_length(outputs); i++)
2024-08-08 06:57:51 +02:00
if(outputs[i].isVisible()) outputs[i].drawName(_s, _mx, _my);
2024-08-14 09:55:53 +02:00
2024-08-18 13:13:40 +02:00
for( var i = 0; i < array_length(inputs); i++ ) {
2024-08-14 09:55:53 +02:00
var jun = inputs[i].bypass_junc;
if(jun == noone || !jun.visible) continue;
jun.drawName(_s, _mx, _my);
}
if(attributes.outp_meta) {
for(var i = 0; i < array_length(junc_meta); i++) {
var jun = junc_meta[i];
if(!jun.isVisible()) continue;
jun.drawNameBG(_s);
jun.drawName(_s, _mx, _my);
}
}
2022-09-27 06:37:28 +02:00
}
2023-03-28 06:58:28 +02:00
if(hasInspector1Update() && PANEL_GRAPH.pHOVER && point_in_circle(_mx, _my, inspectInput1.x, inspectInput1.y, 10)) {
2023-03-28 06:58:28 +02:00
inspectInput1.drawNameBG(_s);
inspectInput1.drawName(_s, _mx, _my);
}
if(hasInspector2Update() && PANEL_GRAPH.pHOVER && point_in_circle(_mx, _my, inspectInput2.x, inspectInput2.y, 10)) {
2023-03-28 06:58:28 +02:00
inspectInput2.drawNameBG(_s);
inspectInput2.drawName(_s, _mx, _my);
}
2024-07-10 13:13:51 +02:00
}
2022-09-27 06:37:28 +02:00
2024-11-24 06:07:17 +01:00
__draw_inputs = [];
__draw_inputs_len = 0;
static setJunctionIndex = function() {
var drawLineIndex = 1;
__draw_outputs_len = 0;
for(var i = 0, n = array_length(outputs); i < n; i++) {
var _jun = outputs[i];
var connected = !array_empty(_jun.value_to);
if(connected) __draw_outputs_len++;
}
2023-03-05 07:16:44 +01:00
var _ind = 0;
2024-11-23 07:26:39 +01:00
for(var i = 0, n = array_length(outputs); i < n; i++) {
var _jun = outputs[i];
var connected = !array_empty(_jun.value_to);
2023-03-05 07:16:44 +01:00
if(connected) {
_jun.drawLineIndex = 1 + (_ind > __draw_outputs_len / 2? (__draw_outputs_len - 1 - _ind) : _ind) * 0.5;
_ind++;
2023-03-05 07:16:44 +01:00
}
}
2024-08-18 13:13:40 +02:00
__draw_inputs = array_verify(__draw_inputs, array_length(inputs));
2023-03-05 07:16:44 +01:00
var drawLineIndex = 1;
2024-11-24 06:07:17 +01:00
__draw_inputs_len = 0;
2024-08-18 13:13:40 +02:00
for(var i = 0, n = array_length(inputs); i < n; i++) {
2024-08-08 06:57:51 +02:00
_jun = inputs[i];
2023-11-27 11:40:28 +01:00
2024-11-23 07:26:39 +01:00
if( _jun.value_from == noone || !_jun.value_from.node.active || !_jun.isVisible()) continue;
2024-11-24 06:07:17 +01:00
__draw_inputs[__draw_inputs_len++] = _jun;
2024-08-14 09:55:53 +02:00
}
2024-11-24 06:07:17 +01:00
for( var i = 0; i < __draw_inputs_len; i++ ) {
_jun = __draw_inputs[i];
2024-11-24 06:07:17 +01:00
_jun.drawLineIndex = 1 + (i > __draw_inputs_len / 2? (__draw_inputs_len - 1 - i) : i) * 0.5;
}
}
static drawConnections = function(params = {}, _draw = true) {
if(!active) return noone;
var _hov, hovering = noone;
if(hasInspector1Update()) { _hov = inspectInput1.drawConnections(params, _draw); if(_hov) hovering = _hov; }
if(hasInspector2Update()) { _hov = inspectInput2.drawConnections(params, _draw); if(_hov) hovering = _hov; }
for( var i = 0; i < __draw_inputs_len; i++ ) {
var _jun = __draw_inputs[i];
2023-03-28 06:58:28 +02:00
2024-11-24 06:07:17 +01:00
if(_jun.bypass_junc.visible) _jun.bypass_junc.drawBypass(params);
_hov = _jun.drawConnections(params, _draw); 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) {
2024-11-24 06:07:17 +01:00
if(updatedInTrigger.drawConnections(params, _draw)) hovering = updatedInTrigger;
if(updatedOutTrigger.drawConnections(params, _draw)) hovering = updatedOutTrigger;
2023-10-06 11:51:11 +02:00
}
return hovering;
2024-07-10 13:13:51 +02:00
}
2022-01-13 05:24:03 +01:00
2024-08-20 10:15:53 +02:00
static getGraphPreviewSurface = function() {
2024-08-08 06:57:51 +02:00
var _node = array_safe_get(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 :
2024-08-20 10:15:53 +02:00
return _node.showValue();
2023-09-09 13:52:16 +02:00
}
return noone;
2024-07-10 13:13:51 +02:00
}
2023-08-10 11:51:16 +02:00
2024-04-03 09:40:37 +02:00
__preview_surf = false;
2024-03-31 11:10:14 +02:00
__preview_sw = noone;
__preview_sh = noone;
2024-07-10 13:13:51 +02:00
static setPreview = function(_surf) {
2024-04-03 09:40:37 +02:00
preview_surface = _surf;
__preview_surf = is_surface(_surf);
2024-07-10 13:13:51 +02:00
}
2024-04-03 09:40:37 +02:00
2024-07-10 13:13:51 +02:00
static drawPreview = function(xx, yy, _s) {
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
}
2024-04-03 09:40:37 +02:00
setPreview(surf);
if(!__preview_surf) return;
2022-11-03 11:44:49 +01:00
2024-04-08 07:13:46 +02:00
__preview_sw = surface_get_width_safe(preview_surface);
__preview_sh = surface_get_height_safe(preview_surface);
2024-03-31 11:10:14 +02:00
var bbox = drawGetBbox(xx, yy, _s, false);
2023-08-16 20:16:31 +02:00
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
2024-03-31 11:10:14 +02:00
var _sw = __preview_sw;
var _sh = __preview_sh;
var _ss = min(bbox.w / _sw, bbox.h / _sh);
var _ps = preview_surface;
if(is_struct(_ps) && is_instanceof(_ps, dynaSurf))
_ps = array_safe_get_fast(_ps.surfaces, 0, noone);
draw_surface_ext_safe(_ps, bbox.xc - _sw * _ss / 2, bbox.yc - _sh * _ss / 2, _ss, _ss);
2024-07-10 13:13:51 +02:00
}
2023-01-25 06:49:00 +01:00
2024-07-10 13:13:51 +02:00
static getNodeDimension = function(showFormat = true) {
2024-04-03 09:40:37 +02:00
if(!__preview_surf) 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);
2024-04-08 07:13:46 +02:00
var format = surface_get_format_safe(preview_surface);
2023-03-19 09:17:39 +01:00
2024-04-23 11:53:16 +02:00
var txt = $"[{pw} x {ph}";
2023-11-27 11:40:28 +01:00
if(preview_amount) txt = $"{preview_amount} x {txt}";
2023-03-19 09:17:39 +01:00
switch(format) {
2024-04-23 11:53:16 +02:00
case surface_rgba8unorm : break;
case surface_rgba4unorm : txt += showFormat? " 4RGBA" : " 4R"; 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;
2024-07-10 13:13:51 +02:00
}
2023-01-25 06:49:00 +01:00
2024-07-10 13:13:51 +02:00
static drawDimension = function(xx, yy, _s) {
2023-06-17 14:30:49 +02:00
if(draw_graph_culled) return;
2024-07-10 11:48:23 +02:00
if(!active) return;
if(_s * w < 64) return;
if(!previewable) return;
2023-01-25 06:49:00 +01:00
2024-04-23 11:53:16 +02:00
draw_set_text(f_p3, 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);
2024-04-23 11:53:16 +02:00
ty += string_height(txt) - 2;
2023-01-25 06:49:00 +01:00
}
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";
2024-04-23 11:53:16 +02:00
2023-10-02 14:41:44 +02:00
} 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]);
2024-04-23 11:53:16 +02:00
2023-01-25 06:49:00 +01:00
} else if(render_time < 1000000) {
rt = string_format(render_time / 1000, -1, 2);
unit = "ms";
draw_set_color(COLORS.speed[1]);
2024-04-23 11:53:16 +02:00
2023-01-25 06:49:00 +01:00
} 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
2024-04-23 11:53:16 +02:00
draw_text(round(tx), round(ty), $"{rt} {unit}");
2022-01-13 05:24:03 +01:00
}
2024-07-10 13:13:51 +02:00
}
2022-01-13 05:24:03 +01:00
static groupCheck = function(_x, _y, _s, _mx, _my) {}
static drawNodeBG = function(_x, _y, _mx, _my, _s, display_parameter = noone, _panel = noone) {
var xx = x * _s + _x;
var yy = y * _s + _y;
drawDimension(xx, yy, _s);
return false;
}
2023-11-02 12:43:00 +01:00
static drawNodeFG = function(_x, _y, _mx, _my, _s, display_parameter = noone, _panel = noone) { }
2024-11-24 06:07:17 +01:00
static drawNode = function(_draw, _x, _y, _mx, _my, _s, display_parameter = noone, _panel = noone) {
2024-11-23 08:31:15 +01: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;
2024-11-24 06:07:17 +01:00
if(!_draw) return _s > 0.5? drawJunctions(_draw, xx, yy, _mx, _my, _s) : drawJunctions_fast(_draw, xx, yy, _mx, _my, _s);
2023-03-26 07:13:36 +02:00
preview_mx = _mx;
preview_my = _my;
if(value_validation[VALIDATION.error])
2024-03-31 05:36:11 +02:00
draw_sprite_stretched_ext(THEME.node_glow_border, 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);
2024-03-28 14:18:02 +01:00
draggable = true;
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);
2024-03-26 04:03:45 +01:00
2024-03-28 14:18:02 +01:00
try {
var _hover = PANEL_GRAPH.node_hovering == self;
var _focus = PANEL_GRAPH.getFocusingNode() == self;
onDrawNode(xx, yy, _mx, _my, _s, _hover, _focus);
}
2024-03-26 04:03:45 +01:00
catch(e) { log_warning("NODE onDrawNode", exception_print(e)); }
2024-03-28 14:18:02 +01:00
}
if(SHOW_PARAM) drawJunctionWidget(xx, yy, _mx, _my, _s, _hover, _focus);
2023-12-03 05:02:04 +01:00
2024-04-03 09:40:37 +02:00
draw_name = false;
if((previewable && _s >= 0.5) || (!previewable && h * _s >= name_height * .5)) drawNodeName(xx, yy, _s, _panel);
2023-03-05 07:16:44 +01:00
if(attributes.annotation != "") {
2024-11-26 05:52:57 +01:00
draw_set_text(f_sdf_medium, fa_left, fa_bottom, attributes.annotation_color);
var _ts = _s * attributes.annotation_size;
BLEND_ADD
2024-09-07 12:48:57 +02:00
draw_text_ext_transformed(xx, yy - 4 * _s, attributes.annotation, -1, (w + 8) * _s / _ts, _ts, _ts, 0);
BLEND_NORMAL
}
2022-01-13 05:24:03 +01:00
if(active_draw_index > -1) {
draw_sprite_stretched_ext(bg_spr, 1, xx, yy, round(w * _s), round(h * _s), active_draw_index > 1? COLORS.node_border_file_drop : COLORS._main_accent, 1);
if(active_draw_anchor) draw_sprite_stretched_add(bg_spr, 1, xx, yy, round(w * _s), round(h * _s), COLORS._main_accent, 0.5);
active_draw_anchor = false;
active_draw_index = -1;
2022-01-13 05:24:03 +01:00
}
2023-11-27 11:40:28 +01:00
if(draw_droppable) {
draw_sprite_stretched_ext(THEME.color_picker_box, 0, xx - 2 * _s, yy - 2 * _s, w * _s + 4 * _s, h * _s + 4 * _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
if(bg_spr_add > 0) draw_sprite_stretched_add(bg_spr, 1, xx, yy, w * _s, h * _s, bg_spr_add_clr, bg_spr_add);
2024-07-03 05:16:46 +02:00
drawNodeOverlay(xx, yy, _mx, _my, _s);
2024-11-24 06:07:17 +01:00
if(!previewable) return drawJunctions_fast(_draw, xx, yy, _mx, _my, _s);
return _s > 0.5? drawJunctions(_draw, xx, yy, _mx, _my, _s) : drawJunctions_fast(_draw, xx, yy, _mx, _my, _s);
2024-07-10 13:13:51 +02:00
}
2023-03-28 06:58:28 +02:00
2024-07-10 13:13:51 +02:00
static drawNodeBehind = function(_x, _y, _mx, _my, _s) {
var xx = x * _s + _x;
var yy = y * _s + _y;
onDrawNodeBehind(_x, _y, _mx, _my, _s);
2024-07-10 13:13:51 +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) {}
2024-01-12 10:38:58 +01:00
static drawPreviewBackground = function(_x, _y, _mx, _my, _s) { return false; }
2024-07-10 13:13:51 +02:00
static drawBadge = function(_x, _y, _s) {
2023-03-28 06:58:28 +02:00
badgePreview = lerp_float(badgePreview, !!previewing, 2);
badgeInspect = lerp_float(badgeInspect, inspecting, 2);
if(previewable) {
var xx = x * _s + _x + w * _s;
var yy = y * _s + _y;
if(badgePreview > 0) { draw_sprite_ext(THEME.node_state, is_3D? 3 : 0, xx, yy, badgePreview, badgePreview, 0, c_white, 1); xx -= 28 * badgePreview; }
if(badgeInspect > 0) { draw_sprite_ext(THEME.node_state, 1, xx, yy, badgeInspect, badgeInspect, 0, c_white, 1); xx -= 28 * badgeInspect; }
if(isTool) { draw_sprite_ext(THEME.node_state, 2, xx, yy, 1, 1, 0, c_white, 1); xx -= 28 * 2; }
} else {
var xx = _x + _s * (x + w - 10);
var yy = _y + _s * y;
if(badgePreview > 0) { draw_sprite_ext(THEME.circle_16, 0, xx, yy, .5 * _s, .5 * _s, 0, CDEF.orange); xx -= 12 * _s; }
if(badgeInspect > 0) { draw_sprite_ext(THEME.circle_16, 0, xx, yy, .5 * _s, .5 * _s, 0, CDEF.lime); xx -= 12 * _s; }
if(isTool) { draw_sprite_ext(THEME.circle_16, 0, xx, yy, .5 * _s, .5 * _s, 0, CDEF.blue); xx -= 12 * _s; }
2023-07-17 19:58:33 +02:00
}
2022-01-13 05:24:03 +01:00
inspecting = false;
previewing = 0;
2024-07-10 13:13:51 +02:00
}
2022-01-13 05:24:03 +01:00
2024-07-10 13:13:51 +02:00
static drawBranch = function(_depth = 0) {
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;
2024-08-18 13:13:40 +02:00
for( var i = 0, n = array_length(inputs); i < n; i++ ) {
2024-08-08 06:57:51 +02:00
if(inputs[i].value_from == noone) continue;
inputs[i].value_from.node.drawBranch(_depth + 1);
2023-10-12 07:07:24 +02:00
}
2024-07-10 13:13:51 +02:00
}
2023-10-12 07:07:24 +02:00
2024-07-10 13:13:51 +02:00
static drawActive = function(_x, _y, _s, ind = 0) {
2023-10-12 07:07:24 +02:00
active_draw_index = ind;
2024-01-26 14:38:50 +01:00
if(display_parameter.highlight) drawBranch();
2024-07-10 13:13:51 +02:00
}
2022-01-13 05:24:03 +01:00
2024-03-14 14:35:19 +01:00
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {}
2022-01-13 05:24:03 +01:00
2024-03-14 14:35:19 +01:00
static drawPreviewToolOverlay = function(hover, active, _mx, _my, _panel) { return false; }
2023-10-18 14:58:55 +02:00
2023-05-22 20:31:55 +02:00
static drawAnimationTimeline = function(_w, _h, _s) {}
2024-12-11 04:29:11 +01:00
////- PREVIEW
2024-07-10 13:13:51 +02:00
static getPreviewValues = function() {
2024-08-18 13:13:40 +02:00
if(preview_channel >= array_length(outputs)) return noone;
2022-01-13 05:24:03 +01:00
2024-08-08 06:57:51 +02:00
var _type = outputs[preview_channel].type;
if(_type != VALUE_TYPE.surface && _type != VALUE_TYPE.dynaSurface)
return noone;
2024-08-08 06:57:51 +02:00
var val = outputs[preview_channel].getValue();
if(is_struct(val) && is_instanceof(val, dynaSurf))
val = array_safe_get_fast(val.surfaces, 0, noone);
2022-01-13 05:24:03 +01:00
return val;
2024-07-10 13:13:51 +02:00
}
2023-02-14 02:51:14 +01:00
2024-07-10 13:13:51 +02:00
static getPreviewBoundingBox = function() {
var _surf = getPreviewValues();
if(is_array(_surf))
_surf = array_safe_get_fast(_surf, preview_index, noone);
if(!is_surface(_surf)) return noone;
2024-02-25 11:02:10 +01:00
return BBOX().fromWH(preview_x, preview_y, surface_get_width_safe(_surf), surface_get_height_safe(_surf));
2024-07-10 13:13:51 +02:00
}
2023-02-14 02:51:14 +01:00
2024-12-11 04:29:11 +01:00
////- CACHE
2024-07-10 13:13:51 +02:00
static cacheCheck = function() {
INLINE
if(cache_group) cache_group.enableNodeGroup();
if(group != noone) group.cacheCheck();
2024-07-10 13:13:51 +02:00
}
static getAnimationCacheExist = function(frame) { return cacheExist(frame); }
2024-07-10 13:13:51 +02:00
static clearInputCache = function() {
2024-08-18 13:13:40 +02:00
for( var i = 0; i < array_length(inputs); i++ )
2024-08-08 06:57:51 +02:00
inputs[i].cache_value[0] = false;
2024-07-10 13:13:51 +02:00
}
2023-02-14 02:51:14 +01:00
2024-07-10 13:13:51 +02:00
static cacheArrayCheck = function() {
cached_output = array_verify(cached_output, TOTAL_FRAMES);
cache_result = array_verify(cache_result, TOTAL_FRAMES);
2024-07-10 13:13:51 +02:00
}
2022-12-10 05:06:01 +01:00
2024-11-12 03:39:57 +01:00
static cacheCurrentFrame = function(_surface) {
2022-12-10 05:06:01 +01:00
cacheArrayCheck();
2024-11-12 03:39:57 +01:00
var _frame = CURRENT_FRAME;
if(_frame < 0) return;
if(_frame >= array_length(cached_output)) return;
2022-01-13 05:24:03 +01:00
2024-11-12 03:39:57 +01:00
if(is_array(_surface)) {
surface_array_free(cached_output[_frame]);
cached_output[_frame] = surface_array_clone(_surface);
} else if(surface_exists(_surface)) {
var _sw = surface_get_width(_surface);
var _sh = surface_get_height(_surface);
cached_output[_frame] = surface_verify(cached_output[_frame], _sw, _sh);
surface_set_target(cached_output[_frame]);
DRAW_CLEAR BLEND_OVERRIDE
draw_surface(_surface, 0, 0);
surface_reset_target();
}
2022-12-10 05:06:01 +01:00
2024-11-12 03:39:57 +01:00
array_safe_set(cache_result, _frame, true);
2023-05-03 21:42:17 +02:00
2024-11-12 03:39:57 +01:00
return cached_output[_frame];
2024-07-10 13:13:51 +02:00
}
2023-02-19 13:49:20 +01:00
2024-07-10 13:13:51 +02:00
static cacheExist = function(frame = CURRENT_FRAME) {
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;
2024-03-31 05:36:11 +02:00
if(!array_safe_get_fast(cache_result, frame, false)) return false;
2023-05-03 21:42:17 +02:00
2024-03-31 05:36:11 +02:00
var s = array_safe_get_fast(cached_output, frame);
2023-05-03 21:42:17 +02:00
return is_array(s) || surface_exists(s);
2024-07-10 13:13:51 +02:00
}
2022-12-10 05:06:01 +01:00
2024-07-10 13:13:51 +02:00
static getCacheFrame = function(frame = CURRENT_FRAME) {
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;
2024-03-31 05:36:11 +02:00
var surf = array_safe_get_fast(cached_output, frame);
2023-02-19 13:49:20 +01:00
return surf;
2024-07-10 13:13:51 +02:00
}
2023-02-19 13:49:20 +01:00
2024-07-10 13:13:51 +02:00
static recoverCache = function(frame = CURRENT_FRAME) {
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];
2024-08-08 06:57:51 +02:00
outputs[0].setValue(_s);
2022-11-22 14:25:39 +01:00
return true;
2024-07-10 13:13:51 +02:00
}
2023-08-16 20:16:31 +02:00
2024-07-10 13:13:51 +02:00
static clearCache = function(_force = false) {
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
}
2024-07-10 13:13:51 +02:00
}
2023-07-08 20:29:23 +02:00
2024-07-10 13:13:51 +02:00
static clearCacheForward = function() {
2023-10-19 11:34:29 +02:00
_clearCacheForward();
2024-07-10 13:13:51 +02:00
}
2023-07-08 20:29:23 +02:00
2024-07-10 13:13:51 +02:00
static _clearCacheForward = function() {
2023-06-17 14:30:49 +02:00
if(!isRenderActive()) return;
2023-03-08 07:35:51 +01:00
2024-09-02 11:53:15 +02: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();
2024-07-10 13:13:51 +02:00
}
2023-07-25 20:12:40 +02:00
2024-07-10 13:13:51 +02:00
static cachedPropagate = function(_group = group) {
2023-10-27 15:42:17 +02:00
if(group != _group) return;
setRenderStatus(true);
2024-08-18 13:13:40 +02:00
for( var i = 0, n = array_length(inputs); i < n; i++ ) {
2024-08-08 06:57:51 +02:00
var _input = inputs[i];
if(_input.value_from == noone) continue;
_input.value_from.node.cachedPropagate(_group);
2022-01-13 05:24:03 +01:00
}
2024-07-10 13:13:51 +02:00
}
2022-01-13 05:24:03 +01:00
2024-07-10 13:13:51 +02:00
static clearInputCache = function() {
2024-08-18 13:13:40 +02:00
for( var i = 0; i < array_length(inputs); i++ ) {
2024-08-08 06:57:51 +02:00
if(!is_instanceof(inputs[i], NodeValue)) continue;
inputs[i].resetCache();
}
2024-07-10 13:13:51 +02:00
}
2024-12-11 04:29:11 +01:00
////- TOOLS
2023-03-11 01:40:17 +01:00
2024-07-10 13:13:51 +02:00
static isUsingTool = function(index = undefined, subtool = noone) {
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;
2024-07-10 13:13:51 +02:00
}
2023-03-11 01:40:17 +01:00
static isNotUsingTool = function() { return PANEL_PREVIEW.tool_current == noone; }
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; }
2024-07-10 13:13:51 +02:00
static setTool = function(tool) {
2023-07-17 19:58:33 +02:00
if(!tool) {
isTool = false;
return;
}
for( var i = 0; i < array_length(group.nodes); i++ )
group.nodes[i].isTool = false;
2023-07-17 19:58:33 +02:00
isTool = true;
2024-07-10 13:13:51 +02:00
}
2023-07-17 19:58:33 +02:00
2024-06-11 05:06:42 +02:00
static drawTools = noone;
2024-12-11 04:29:11 +01:00
////- SERIALIZE
2024-05-22 12:13:46 +02:00
2024-07-10 13:13:51 +02:00
static serialize = function(scale = false, preset = false) {
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.name = display_name;
_map.iname = internalName;
_map.x = x;
_map.y = y;
_map.type = instanceof(self);
2024-11-23 12:08:44 +01:00
if(isTool) _map.tool = isTool;
if(group != noone) _map.group = group.node_id;
if(!renderActive) _map.render = renderActive;
if(!previewable) _map.previewable = previewable;
if(show_parameter) _map.show_parameter = show_parameter;
}
var _attr = attributeSerialize();
var attri = struct_append(variable_clone(attributes), _attr);
2024-11-24 02:33:57 +01:00
#region attribute stripping // TODO : make it an array
2024-11-23 12:08:44 +01:00
if(struct_try_get(attri, "color_depth") == 3) struct_remove(attri, "color_depth");
if(struct_try_get(attri, "interpolate") == 1) struct_remove(attri, "interpolate");
if(struct_try_get(attri, "oversample") == 1) struct_remove(attri, "oversample");
if(struct_try_get(attri, "node_width") == 0) struct_remove(attri, "node_width");
if(struct_try_get(attri, "node_height") == 0) struct_remove(attri, "node_height");
if(struct_try_get(attri, "node_param_width") == 192) struct_remove(attri, "node_param_width");
if(struct_try_get(attri, "outp_meta") == false) struct_remove(attri, "outp_meta");
2024-11-26 05:52:57 +01:00
if(struct_try_get(attri, "annotation") == "") struct_remove(attri, "annotation");
if(struct_try_get(attri, "annotation_size") == .4) struct_remove(attri, "annotation_size");
if(struct_try_get(attri, "annotation_color") == COLORS._main_text_sub) struct_remove(attri, "annotation_color");
2024-11-23 12:08:44 +01:00
if(struct_try_get(attri, "color") == -1) struct_remove(attri, "color");
if(struct_try_get(attri, "update_graph") == true) struct_remove(attri, "update_graph");
if(struct_try_get(attri, "show_update_trigger") == false) struct_remove(attri, "show_update_trigger");
if(struct_try_get(attri, "array_process") == 0) struct_remove(attri, "array_process");
2024-11-26 05:52:57 +01:00
if(struct_has(attri, "use_project_dimension")) struct_remove(attri, "use_project_dimension");
2024-11-23 12:08:44 +01:00
if(struct_names_count(attri)) _map.attri = attri;
#endregion
2023-08-05 14:00:33 +02:00
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 = [];
2024-08-08 06:57:51 +02:00
for(var i = 0; i < array_length(inputs); i++)
array_push(_inputs, inputs[i].serialize(scale, preset));
2023-06-13 14:42:06 +02:00
_map.inputs = _inputs;
2022-01-13 05:24:03 +01:00
2023-06-13 14:42:06 +02:00
var _outputs = [];
2024-08-08 06:57:51 +02:00
for(var i = 0; i < array_length(outputs); i++)
array_push(_outputs, outputs[i].serialize(scale, preset));
2023-06-13 14:42:06 +02:00
_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
var _outMeta = [];
for(var i = 0; i < array_length(junc_meta); i++)
_outData[i] = junc_meta[i].serialize(scale, preset);
2023-06-13 14:42:06 +02:00
_map.inspectInputs = _trigger;
2024-11-23 12:08:44 +01:00
if(!array_empty(_outMeta)) _map.outputMeta = _outMeta;
if(renamed) _map.renamed = renamed;
2024-01-20 05:06:56 +01: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;
2024-07-10 13:13:51 +02:00
}
2022-01-13 05:24:03 +01:00
static attributeSerialize = function() { return {}; }
static doSerialize = function(_map) {}
static processSerialize = function(_map) {}
2024-12-11 04:29:11 +01:00
////- DESERIALIZE
2022-01-13 05:24:03 +01:00
2024-07-10 13:13:51 +02:00
static deserialize = function(_map, scale = false, preset = false) {
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
preDeserialize();
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-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();
2024-04-11 05:51:13 +02:00
load_group = struct_try_get(load_map, "group", noone);
if(load_group == -1) load_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");
2024-03-28 14:18:02 +01:00
renderActive = struct_try_get(load_map, "render", true);
2024-11-23 12:08:44 +01:00
previewable = struct_try_get(load_map, "previewable", true);
isTool = struct_try_get(load_map, "tool", false);
show_parameter = struct_try_get(load_map, "show_parameter", false);
2022-12-10 05:06:01 +01:00
}
2022-01-13 05:24:03 +01:00
2024-11-23 12:08:44 +01:00
if(struct_has(load_map, "attri")) {
var _lattr = load_map.attri;
_lattr.color_depth = struct_try_get(_lattr, "color_depth", 3);
_lattr.interpolate = struct_try_get(_lattr, "interpolate", 1);
_lattr.oversample = struct_try_get(_lattr, "oversample", 1);
_lattr.node_width = struct_try_get(_lattr, "node_width", 0);
_lattr.node_height = struct_try_get(_lattr, "node_height", 0);
_lattr.node_param_width = struct_try_get(_lattr, "node_param_width", 192);
_lattr.outp_meta = struct_try_get(_lattr, "outp_meta", false);
2024-11-26 05:52:57 +01:00
2024-11-23 12:08:44 +01:00
_lattr.color = struct_try_get(_lattr, "color", -1);
_lattr.update_graph = struct_try_get(_lattr, "update_graph", true);
_lattr.show_update_trigger = struct_try_get(_lattr, "show_update_trigger", false);
_lattr.array_process = struct_try_get(_lattr, "array_process", 0);
attributeDeserialize(CLONING? variable_clone(_lattr) : _lattr);
2024-01-20 05:06:56 +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();
postLoad();
2023-04-22 16:23:51 +02:00
}
2024-11-07 07:59:04 +01:00
anim_timeline = struct_try_get(attributes, "show_timeline", false);
2024-11-04 06:08:06 +01:00
if(anim_timeline) refreshTimeline();
2024-07-10 13:13:51 +02:00
}
2023-03-28 06:58:28 +02:00
static inputBalance = function() { // 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;
var _dynamic_inputs = (array_length(load_map.inputs) - _input_fix_len) / _data_length;
if(frac(_dynamic_inputs) != 0) {
2024-06-26 06:38:57 +02:00
var _txt = "LOAD: Uneven dynamic input.";
logNode(_txt); noti_warning(_txt);
2023-08-05 14:00:33 +02:00
_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);
2024-07-10 13:13:51 +02:00
}
2023-08-05 14:00:33 +02:00
static inputGenerate = function() { // Generate inputs for dynamic input nodes
2023-08-05 14:00:33 +02:00
if(createNewInput == noone)
return;
var _dynamic_inputs = ceil((array_length(load_map.inputs) - input_fix_len) / data_length);
2023-08-05 14:00:33 +02:00
repeat(_dynamic_inputs)
createNewInput();
2024-07-10 13:13:51 +02:00
}
2022-01-13 05:24:03 +01:00
2024-07-10 13:13:51 +02:00
static attributeDeserialize = function(attr) {
2024-11-23 12:08:44 +01:00
struct_override(attributes, attr);
if(!CLONING && LOADING_VERSION < 1_18_02_0) {
2024-11-24 06:07:17 +01:00
if(struct_has(attributes, "color_depth")) attributes.color_depth += (!array_empty(inputs) && inputs[0].type == VALUE_TYPE.surface)? 1 : 2;
if(struct_has(attributes, "interpolate")) attributes.interpolate++;
if(struct_has(attributes, "oversample")) attributes.oversample++;
}
2024-07-10 13:13:51 +02:00
}
2023-02-28 09:43:01 +01:00
static processDeserialize = function() {}
static preDeserialize = function() {}
static postDeserialize = function() {}
2024-04-13 07:32:04 +02:00
2024-07-10 13:13:51 +02:00
static applyDeserialize = function(preset = false) {
2024-04-02 14:33:25 +02:00
preApplyDeserialize();
2023-06-13 14:42:06 +02:00
var _inputs = load_map.inputs;
2024-08-08 06:57:51 +02:00
var amo = min(array_length(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++) {
2024-08-08 06:57:51 +02:00
if(inputs[i] == noone || _inputs[i] == noone) continue;
2024-08-08 06:57:51 +02:00
//print($" Apply {i} : {inputs[i].name}");
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;
2024-08-08 06:57:51 +02:00
var amo = min(array_length(outputs), array_length(_outputs));
2023-06-17 14:30:49 +02:00
for(var i = 0; i < amo; i++) {
2024-08-08 06:57:51 +02:00
if(outputs[i] == noone) continue;
2024-08-08 06:57:51 +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
if(struct_has(load_map, "outputMeta")) {
var _outMeta = load_map.outputMeta;
for(var i = 0; i < min(array_length(_outMeta), array_length(junc_meta)); i++)
junc_meta[i].applyDeserialize(_outMeta[i], load_scale, preset);
}
2023-10-18 14:58:55 +02:00
//print($"Applying deserialzie for {name} complete");
postApplyDeserialize();
2024-07-10 13:13:51 +02:00
}
2022-12-21 02:30:23 +01:00
2024-04-02 14:33:25 +02:00
static preApplyDeserialize = function() {}
static postApplyDeserialize = function() {}
2023-01-09 03:14:20 +01:00
2024-11-24 11:39:17 +01:00
static loadGroup = function(ctx = noone) {
2024-04-11 05:51:13 +02:00
if(load_group == noone) {
2024-11-24 11:39:17 +01:00
if(ctx) ctx.add(self);
else array_push(project.nodes, self);
onLoadGroup();
return;
2022-01-13 05:24:03 +01:00
}
2023-10-18 14:58:55 +02:00
2024-11-24 11:39:17 +01:00
if(APPENDING) load_group = GetAppendID(load_group);
if(ds_map_exists(PROJECT.nodeMap, load_group)) {
var _grp = PROJECT.nodeMap[? load_group];
if(struct_has(_grp, "add"))
_grp.add(self);
else
throw($"Group load failed. Node ID {load_group} is not a group.");
} else
throw($"Group load failed. Can't find node ID {load_group}");
2023-10-18 14:58:55 +02:00
onLoadGroup();
2024-07-10 13:13:51 +02:00
}
2022-01-18 05:31:19 +01:00
2023-10-18 14:58:55 +02:00
static onLoadGroup = function() {}
2024-07-10 13:13:51 +02:00
static connect = function(log = false) {
2022-01-13 05:24:03 +01:00
var connected = true;
2024-08-08 06:57:51 +02:00
for(var i = 0; i < array_length(inputs); i++)
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;
2024-07-10 13:13:51 +02:00
}
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() {}
2024-12-11 04:29:11 +01:00
////- CLEAN UP
2023-04-10 20:02:59 +02:00
2024-07-10 13:13:51 +02:00
static cleanUp = function() {
2024-11-24 11:39:17 +01:00
for( var i = 0; i < array_length(inputs); i++ ) { inputs[i].cleanUp(); delete inputs[i]; }
for( var i = 0; i < array_length(outputs); i++ ) { outputs[i].cleanUp(); delete outputs[i]; }
2023-04-15 14:48:29 +02:00
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();
2024-07-10 13:13:51 +02:00
}
2023-02-23 07:02:19 +01:00
static onCleanUp = function() {}
2023-03-19 09:17:39 +01:00
2024-12-11 04:29:11 +01:00
////- ACTION
2024-07-10 13:13:51 +02:00
static setDimension = function(_w = 128, _h = 128, _apply = true) {
INLINE
2024-11-23 07:26:39 +01:00
var _oh = con_h;
min_w = _w;
con_h = _h;
2024-11-23 07:26:39 +01:00
if(!_apply) return;
w = max(w, min_w);
if(_oh != _h) refreshNodeDisplay();
2024-07-10 13:13:51 +02:00
}
2024-07-10 13:13:51 +02:00
static move = function(_x, _y, _s) {
if(x == _x && y == _y) return;
x = _x;
y = _y;
if(!LOADING) PROJECT.modified = true;
2024-07-10 13:13:51 +02:00
}
static enable = function() { INLINE active = true; timeline_item.active = true; }
static disable = function() { INLINE active = false; timeline_item.active = false; }
static onDestroy = function() {}
2024-07-10 13:13:51 +02:00
static destroy = function(_merge = false, record = true) {
if(!active) return;
disable();
array_remove(group == noone? PROJECT.nodes : group.getNodeList(), self);
if(PANEL_GRAPH.node_hover == self) PANEL_GRAPH.node_hover = noone;
array_remove(PANEL_GRAPH.nodes_selecting, self);
if(PANEL_INSPECTOR.inspecting == self) PANEL_INSPECTOR.inspecting = noone;
PANEL_PREVIEW.removeNodePreview(self);
var val_from_map = {};
2024-08-08 06:57:51 +02:00
for( var i = 0; i < array_length(inputs); i++ ) {
var _i = inputs[i];
if(_i.value_from == noone) continue;
val_from_map[$ _i.type] = _i.value_from;
}
2024-08-08 06:57:51 +02:00
for(var i = 0; i < array_length(outputs); i++) {
var jun = outputs[i];
for(var j = array_length(jun.value_to) - 1; j >= 0; j--) {
var _vt = jun.value_to[j];
if(_vt.value_from == noone || _vt.value_from.node != self)
continue;
if(_merge && struct_has(val_from_map, _vt.type))
_vt.setFrom(val_from_map[$ _vt.type]);
else
_vt.removeFrom(false);
}
jun.value_to = [];
}
2024-08-08 06:57:51 +02:00
for( var i = 0; i < array_length( inputs); i++ ) inputs[i].destroy();
for( var i = 0; i < array_length(outputs); i++ ) outputs[i].destroy();
onDestroy();
if(group) group.refreshNodes();
if(record) recordAction(ACTION_TYPE.node_delete, self);
RENDER_ALL_REORDER
2024-07-10 13:13:51 +02:00
}
static onRestore = function() {}
2024-07-10 13:13:51 +02:00
static restore = function() {
if(active) return;
enable();
array_push(group == noone? PROJECT.nodes : group.getNodeList(), self);
onRestore();
if(group) group.refreshNodes();
RENDER_ALL_REORDER
2024-07-10 13:13:51 +02:00
}
2024-07-10 13:13:51 +02:00
static droppable = function(dragObj) {
2024-08-08 06:57:51 +02:00
for( var i = 0; i < array_length(inputs); i++ ) {
if(dragObj.type == inputs[i].drop_key)
return true;
}
return false;
2024-07-10 13:13:51 +02:00
}
on_drop_file = noone;
2024-07-10 13:13:51 +02:00
static onDrop = function(dragObj) {
if(dragObj.type == "Asset" && is_callable(on_drop_file)) {
on_drop_file(dragObj.data.path);
return;
}
2024-08-08 06:57:51 +02:00
for( var i = 0; i < array_length(inputs); i++ ) {
if(dragObj.type == inputs[i].drop_key) {
inputs[i].setValue(dragObj.data);
return;
}
}
2024-07-10 13:13:51 +02:00
}
2024-12-10 10:46:35 +01:00
static dropPath = noone;
2024-12-10 10:45:17 +01:00
2024-07-10 13:13:51 +02:00
static clone = function(target = PANEL_GRAPH.getCurrentContext()) {
CLONING = true;
var _type = instanceof(self);
var _node = nodeBuild(_type, x, y, target);
CLONING = false;
LOADING_VERSION = SAVE_VERSION;
if(!_node) return;
CLONING = true;
var _nid = _node.node_id;
_node.deserialize(serialize());
_node.postDeserialize();
_node.applyDeserialize();
_node.node_id = _nid;
PROJECT.nodeMap[? node_id] = self;
PROJECT.nodeMap[? _nid] = _node;
CLONING = false;
refreshTimeline();
onClone(_node, target);
return _node;
2024-07-10 13:13:51 +02:00
}
static onClone = function(_NewNode, target = PANEL_GRAPH.getCurrentContext()) {}
2024-12-11 04:29:11 +01:00
////- MISC
2024-07-10 13:13:51 +02:00
static isInLoop = function() {
return array_exists(global.loop_nodes, instanceof(group));
2024-07-10 13:13:51 +02:00
}
2024-07-10 13:13:51 +02:00
static isTerminal = function() {
2024-08-08 06:57:51 +02:00
for( var i = 0; i < array_length(outputs); i++ ) {
var _to = outputs[i].getJunctionTo();
if(array_length(_to)) return false;
}
return true;
2024-07-10 13:13:51 +02:00
}
static resetAnimation = function() {}
static getAttribute = function(_key) {
var _val = struct_try_get(attributes, _key, 0);
switch(_key) {
case "interpolate" :
case "oversample" :
2024-11-04 06:08:06 +01:00
if(_val == 0 && group != noone) return group.getAttribute(_key);
return _val;
}
return _val;
}
2024-07-10 13:13:51 +02:00
static attrDepth = function() {
var form = -1;
2023-06-13 14:42:06 +02:00
if(struct_has(attributes, "color_depth")) {
form = global.SURFACE_FORMAT[attributes.color_depth];
if(form >= 0) return form;
}
if(form == -1) { // input
var _s = getInputData(0);
while(is_array(_s) && array_length(_s)) _s = _s[0];
if(is_surface(_s)) return surface_get_format(_s);
2023-03-19 09:17:39 +01:00
}
if(form == -2 && group != noone) // group
return group.attrDepth();
return surface_rgba8unorm;
2024-07-10 13:13:51 +02:00
}
2023-10-02 10:45:30 +02:00
static checkGroup = function() {
for( var i = 0, n = array_length(attributeEditors); i < n; i++ ) {
var _att = attributeEditors[i];
if(!is_array(_att)) continue;
var _wid = _att[2];
if(!is(_wid, scrollBox)) continue;
var _key = array_safe_get(_att, 3, "");
var _l = _wid.data_list;
for( var j = 0, m = array_length(_l); j < m; j++ ) {
var _scl = _l[j];
if(!is(_scl, scrollItem)) continue;
if(_scl.name != "Group") continue;
_scl.active = group != noone;
if(!_scl.active && attributes[$ _key] == j) attributes[$ _key] = _att[0] == "Color depth"? 3 : 1;
break;
}
}
2024-10-18 04:47:55 +02:00
} run_in(1, function() /*=>*/ { checkGroup(); });
2024-12-07 10:35:29 +01:00
nextn = [];
2024-11-30 06:50:20 +01:00
static generateNodeRenderReport = function() {
var _report = {};
_report.search_res = true;
2024-11-30 06:50:20 +01:00
_report.type = "render";
_report.node = self;
_report.inputs = array_create(array_length(inputs));
for( var i = 0, n = array_length(inputs); i < n; i++ ) {
var _j = inputs[i];
_report.inputs[i] = _j.getValue();
if(_j.type == VALUE_TYPE.surface)
_report.inputs[i] = surface_array_clone(_report.inputs[i]);
}
_report.outputs = array_create(array_length(outputs));
for( var i = 0, n = array_length(outputs); i < n; i++ ) {
var _j = outputs[i];
_report.outputs[i] = _j.getValue();
if(_j.type == VALUE_TYPE.surface)
_report.outputs[i] = surface_array_clone(_report.outputs[i]);
}
_report.logs = array_clone(messages_dbg);
2024-12-07 10:35:29 +01:00
_report.nextn = nextn;
2024-11-30 06:50:20 +01:00
_report.queue = array_clone(RENDER_QUEUE.data, 1);
2024-12-07 10:35:29 +01:00
nextn = [];
2024-11-30 06:50:20 +01:00
return _report;
}
2024-12-07 10:35:29 +01:00
static summarizeReport = function(_startTime) {
2024-11-30 06:50:20 +01:00
var _srcstr = $"{getFullName()}";
2024-12-07 10:35:29 +01:00
var _report = generateNodeRenderReport();
2024-11-30 06:50:20 +01:00
for( var i = 0, n = array_length(_report.nextn); i < n; i++ ) _srcstr += $"{_report.nextn[i].getFullName()}";
for( var i = 0, n = array_length(_report.queue); i < n; i++ ) _srcstr += $"{_report.queue[i].getFullName()}";
2024-12-07 10:35:29 +01:00
_report.time = get_timer() - _startTime;
_report.renderTime = render_time;
2024-11-30 06:50:20 +01:00
_report.search_string = _srcstr;
2024-12-07 10:35:29 +01:00
array_push(PROFILER_DATA, _report);
2024-11-30 06:50:20 +01:00
}
2024-11-24 11:39:17 +01:00
static toString = function() { return $"Node [{internalName}] [{instanceof(self)}]: {node_id}"; }
2022-01-13 05:24:03 +01:00
}