Pixel-Composer/scripts/node_delay/node_delay.gml

72 lines
1.9 KiB
Text
Raw Normal View History

2024-01-20 05:06:56 +01:00
function Node_Delay(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
name = "Delay";
2024-03-23 07:26:11 +01:00
is_simulation = true;
2024-08-18 06:16:20 +02:00
newInput(0, nodeValue_Surface("Surface", self));
2024-01-20 05:06:56 +01:00
2024-08-18 06:16:20 +02:00
newInput(1, nodeValue_Int("Frames", self, 1));
2024-01-20 05:06:56 +01:00
newInput(2, nodeValue_Enum_Scroll("Overflow", self, 0, [ "Hold", "Loop", "Clear" ]));
2024-08-30 11:08:30 +02:00
2024-09-04 03:57:11 +02:00
newOutput(0, nodeValue_Output("Surface", self, VALUE_TYPE.surface, noone));
2024-01-20 05:06:56 +01:00
input_display_list = [ 0,
2024-08-30 11:08:30 +02:00
["Delay", false], 1, 2,
2024-01-20 05:06:56 +01:00
];
surf_indexes = [];
curr_frame = 0;
2024-01-20 05:06:56 +01:00
static processData_prebatch = function() {
surf_indexes = array_verify(surf_indexes, process_amount);
for( var i = 0; i < process_amount; i++ )
surf_indexes[i] = array_verify(surf_indexes[i], TOTAL_FRAMES);
}
static processData = function(_output, _data, _output_index, _array_index = 0) {
var _surf = _data[0];
var _frme = _data[1];
var _ovrf = _data[2];
2024-01-20 05:06:56 +01:00
var _time = CURRENT_FRAME;
var _totl = TOTAL_FRAMES;
2024-08-30 11:08:30 +02:00
var _frtm = _time - _frme;
switch(_ovrf) {
case 0 : _frtm = clamp(_frtm, 0, _totl - 1); break;
case 1 : _frtm = (_frtm + _totl) % _totl; break;
}
2024-01-20 05:06:56 +01:00
var _sw = surface_get_width_safe(_surf);
var _sh = surface_get_height_safe(_surf);
var _surfA = surf_indexes[_array_index];
_surfA[_time] = surface_verify(_surfA[_time], _sw, _sh);
2024-01-20 05:06:56 +01:00
surface_set_shader(_surfA[_time], sh_sample, true, BLEND.over);
2024-01-20 05:06:56 +01:00
draw_surface_safe(_surf);
surface_reset_target();
_output = surface_verify(_output, _sw, _sh);
surface_set_shader(_output, sh_sample, true, BLEND.over);
if(0 <= _frtm && _frtm < _totl)
draw_surface_safe(_surfA[_frtm]);
2024-01-20 05:06:56 +01:00
surface_reset_target();
curr_frame = _frtm;
2024-01-20 05:06:56 +01:00
return _output;
}
static drawAnimationTimeline = function(_shf, _w, _h, _s) {
draw_set_color(COLORS._main_value_positive);
draw_set_alpha(1);
var _x = _shf + (curr_frame + 1) * _s;
draw_line_width(_x, 0, _x, _h, 1);
draw_set_alpha(1);
}
2024-01-20 05:06:56 +01:00
}