Pixel-Composer/scripts/node_processor/node_processor.gml

111 lines
2.7 KiB
Plaintext
Raw Normal View History

2022-01-13 05:24:03 +01:00
enum ARRAY_PROCESS {
loop,
hold
}
2022-12-13 09:20:36 +01:00
function Node_Processor(_x, _y, _group = -1) : Node(_x, _y, _group) constructor {
2022-01-13 05:24:03 +01:00
array_process = ARRAY_PROCESS.loop;
current_data = [];
2022-11-18 03:20:31 +01:00
icon = THEME.node_processor;
2022-01-13 05:24:03 +01:00
2022-01-18 05:31:19 +01:00
static process_data = function(_outSurf, _data, _output_index) { return _outSurf; }
2022-01-13 05:24:03 +01:00
2022-01-18 05:31:19 +01:00
static update = function() {
2022-01-13 05:24:03 +01:00
var len = 0;
for(var i = 0; i < ds_list_size(inputs); i++) {
var _in = inputs[| i].getValue();
2022-11-22 14:25:39 +01:00
if(inputs[| i].isArray() && is_array(_in))
len = max(len, array_length(_in));
2022-01-13 05:24:03 +01:00
}
for(var _oi = 0; _oi < ds_list_size(outputs); _oi++) {
if(outputs[| _oi].type != VALUE_TYPE.surface) continue;
var outSurfs = outputs[| _oi].getValue();
if(len) {
if(!is_array(outSurfs))
outSurfs = array_create(len);
else if(array_length(outSurfs) != len)
array_resize(outSurfs, len);
for(var i = 0; i < len; i++) {
var ww = 1, hh = 1;
if(inputs[| 0].type == VALUE_TYPE.surface) {
var base_s = getData(0, i);
if(is_surface(base_s)) {
2022-11-22 14:25:39 +01:00
ww = surface_get_width(base_s);
hh = surface_get_height(base_s);
2022-01-13 05:24:03 +01:00
}
}
2022-11-22 14:25:39 +01:00
if(is_surface(outSurfs[i]))
2022-01-13 05:24:03 +01:00
surface_size_to(outSurfs[i], ww, hh)
2022-11-22 14:25:39 +01:00
else
outSurfs[i] = surface_create_valid(ww, hh);
2022-01-13 05:24:03 +01:00
var _data = getDataArray(i);
process_data(outSurfs[i], _data, _oi);
if(i == preview_index) current_data = _data;
}
outputs[| _oi].setValue(outSurfs);
} else {
var ww = 1, hh = 1;
if(inputs[| 0].type == VALUE_TYPE.surface) {
var base_texture = inputs[| 0].getValue();
if(is_surface(base_texture)) {
ww = surface_get_width(base_texture);
hh = surface_get_height(base_texture);
}
}
if(is_array(outSurfs)) {
for(var i = 1; i < array_length(outSurfs); i++) {
if(is_surface(outSurfs[i]))
surface_free(outSurfs[i]);
}
outSurfs = outSurfs[0];
outputs[| _oi].setValue(outSurfs);
}
2022-11-22 14:25:39 +01:00
if(is_surface(outSurfs)) {
surface_size_to(outSurfs, ww, hh);
} else {
2022-11-03 11:44:49 +01:00
outSurfs = surface_create_valid(ww, hh);
2022-01-13 05:24:03 +01:00
outputs[| _oi].setValue(outSurfs);
2022-11-22 14:25:39 +01:00
}
2022-01-13 05:24:03 +01:00
var _data = getDataArray(0);
process_data(outSurfs, _data, _oi);
current_data = _data;
}
}
}
function getDataArray(index) {
var _data = array_create(ds_list_size(inputs));
for(var i = 0; i < array_length(_data); i++) {
_data[i] = getData(i, index);
}
return _data;
}
function getData(data, index) {
var _data = 0;
var val = inputs[| data].getValue();
if(inputs[| data].isArray()) {
if(array_length(val) == 0) return 0;
_data = val[safe_mod(index, array_length(val))];
} else
_data = val;
return _data;
}
}