2023-11-02 12:43:00 +01:00
|
|
|
function __Node_Cache(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
2023-11-02 14:37:13 +01:00
|
|
|
name = "Cache";
|
2023-11-02 12:43:00 +01:00
|
|
|
clearCacheOnChange = false;
|
|
|
|
update_on_frame = true;
|
|
|
|
|
|
|
|
attributes.cache_group = [];
|
|
|
|
cache_group_members = [];
|
|
|
|
group_vertex = [];
|
|
|
|
vertex_hash = "";
|
|
|
|
|
|
|
|
insp1UpdateTooltip = "Generate cache group";
|
2023-11-02 14:37:13 +01:00
|
|
|
insp1UpdateIcon = [ THEME.cache_group, 0, COLORS._main_icon ];
|
|
|
|
|
|
|
|
if(NOT_LOAD) run_in(1, function() { onInspector1Update(); });
|
|
|
|
|
|
|
|
static removeNode = function(node) { #region
|
|
|
|
if(node.cache_group == noone) return;
|
|
|
|
|
|
|
|
array_remove(attributes.cache_group, node.node_id);
|
|
|
|
node.cache_group = noone;
|
|
|
|
refreshCacheGroup();
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
static addNode = function(node) { #region
|
|
|
|
array_push_unique(attributes.cache_group, node.node_id);
|
|
|
|
refreshCacheGroup();
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
static enableNodeGroup = function() { #region
|
|
|
|
for( var i = 0, n = array_length(cache_group_members); i < n; i++ )
|
|
|
|
cache_group_members[i].renderActive = true;
|
|
|
|
clearCache(true);
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
static disableNodeGroup = function() { #region
|
|
|
|
if(IS_PLAYING && CURRENT_FRAME == TOTAL_FRAMES - 1)
|
|
|
|
for( var i = 0, n = array_length(cache_group_members); i < n; i++ )
|
|
|
|
cache_group_members[i].renderActive = false;
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
static refreshCacheGroup = function() { #region
|
|
|
|
cache_group_members = array_create(array_length(attributes.cache_group));
|
|
|
|
for( var i = 0, n = array_length(attributes.cache_group); i < n; i++ ) {
|
|
|
|
cache_group_members[i] = PROJECT.nodeMap[? attributes.cache_group[i]];
|
|
|
|
cache_group_members[i].cache_group = self;
|
|
|
|
}
|
|
|
|
} #endregion
|
2023-11-02 12:43:00 +01:00
|
|
|
|
|
|
|
static getCacheGroup = function(node) { #region
|
2023-11-02 14:37:13 +01:00
|
|
|
if(node != self)
|
2023-11-02 12:43:00 +01:00
|
|
|
array_push(attributes.cache_group, node.node_id);
|
|
|
|
|
|
|
|
for( var i = 0, n = ds_list_size(node.inputs); i < n; i++ ) {
|
|
|
|
var _from = node.inputs[| i].value_from;
|
|
|
|
|
|
|
|
if(_from == noone) continue;
|
|
|
|
if(_from.node == self) continue;
|
|
|
|
if(array_exists(attributes.cache_group, _from.node.node_id)) continue;
|
|
|
|
getCacheGroup(_from.node);
|
|
|
|
}
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
static onInspector1Update = function() { #region
|
|
|
|
attributes.cache_group = [];
|
|
|
|
cache_group_members = [];
|
|
|
|
|
|
|
|
getCacheGroup(self);
|
2023-11-02 14:37:13 +01:00
|
|
|
refreshCacheGroup();
|
2023-11-02 12:43:00 +01:00
|
|
|
} #endregion
|
|
|
|
|
|
|
|
static ccw = function(a, b, c) { return (b[0] - a[0]) * (c[1] - a[1]) - (c[0] - a[0]) * (b[1] - a[1]); }
|
|
|
|
|
|
|
|
static getNodeBorder = function(_i, _vertex, _node) { #region
|
|
|
|
var _rad = 8;
|
|
|
|
var _stp = 15;
|
|
|
|
|
|
|
|
var _nx0 = _node.x - 32 + _rad;
|
|
|
|
var _ny0 = _node.y - 32 + _rad;
|
|
|
|
var _nx1 = _node.x + _node.w + 32 - _rad;
|
|
|
|
var _ny1 = _node.y + _node.h + 32 - _rad;
|
|
|
|
|
|
|
|
var _ind = 0;
|
|
|
|
for( var i = 0; i <= 90; i += _stp )
|
|
|
|
_vertex[_i * 7 * 4 + _ind++] = [ _nx1 + lengthdir_x(_rad, i), _ny0 + lengthdir_y(_rad, i) ];
|
|
|
|
|
|
|
|
for( var i = 90; i <= 180; i += _stp )
|
|
|
|
_vertex[_i * 7 * 4 + _ind++] = [ _nx0 + lengthdir_x(_rad, i), _ny0 + lengthdir_y(_rad, i) ];
|
|
|
|
|
|
|
|
for( var i = 180; i <= 270; i += _stp )
|
|
|
|
_vertex[_i * 7 * 4 + _ind++] = [ _nx0 + lengthdir_x(_rad, i), _ny1 + lengthdir_y(_rad, i) ];
|
|
|
|
|
|
|
|
for( var i = 270; i <= 360; i += _stp )
|
|
|
|
_vertex[_i * 7 * 4 + _ind++] = [ _nx1 + lengthdir_x(_rad, i), _ny1 + lengthdir_y(_rad, i) ];
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
static refrshGroupBG = function() { #region
|
|
|
|
group_vertex = [];
|
|
|
|
|
|
|
|
if(array_empty(cache_group_members)) return;
|
|
|
|
var _vtrx = array_create((array_length(cache_group_members) + 1) * 4 * 7);
|
|
|
|
|
|
|
|
for( var i = -1, n = array_length(cache_group_members); i < n; i++ ) {
|
|
|
|
var _node = i == -1? self : cache_group_members[i];
|
|
|
|
getNodeBorder(i + 1, _vtrx, _node);
|
|
|
|
}
|
|
|
|
|
|
|
|
__temp_minP = [ x, y ];
|
|
|
|
__temp_minI = 0;
|
|
|
|
|
|
|
|
for( var i = 0, n = array_length(_vtrx); i < n; i++ ) {
|
|
|
|
var _v = _vtrx[i];
|
|
|
|
|
|
|
|
if(_v[1] > __temp_minP[1] || (_v[1] == __temp_minP[1] && _v[0] < __temp_minP[0])) {
|
|
|
|
__temp_minP = _v;
|
|
|
|
__temp_minI = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_vtrx = array_map( _vtrx, function(a, i) { return [ a[0], a[1], i == __temp_minI? -999 : point_direction(__temp_minP[0], __temp_minP[1], a[0], a[1]) + 360 ] });
|
|
|
|
array_sort(_vtrx, function(a0, a1) { return a0[2] == a1[2]? sign(a0[0] - a1[0]) : sign(a0[2] - a1[2]); });
|
|
|
|
|
|
|
|
var _linS = 0;
|
|
|
|
for( var i = 1, n = array_length(_vtrx); i < n; i++ ) {
|
|
|
|
if(_vtrx[i][1] != _vtrx[0][1]) break;
|
|
|
|
_linS = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
array_delete(_vtrx, 1, _linS - 1);
|
|
|
|
|
|
|
|
group_vertex = [ _vtrx[0], _vtrx[1] ];
|
|
|
|
|
|
|
|
for( var i = 2, n = array_length(_vtrx); i < n; i++ ) {
|
|
|
|
var _v = _vtrx[i];
|
|
|
|
|
|
|
|
while( array_length(group_vertex) >= 2 && ccw( group_vertex[array_length(group_vertex) - 2], group_vertex[array_length(group_vertex) - 1], _v ) >= 0 )
|
|
|
|
array_pop(group_vertex);
|
|
|
|
array_push(group_vertex, _v);
|
|
|
|
}
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
static drawNodeBG = function(_x, _y, _mx, _my, _s) { #region
|
|
|
|
var _hash = "";
|
|
|
|
for( var i = -1, n = array_length(cache_group_members); i < n; i++ ) {
|
|
|
|
var _node = i == -1? self : cache_group_members[i];
|
|
|
|
_hash += $"{_node.x},{_node.y},{_node.w},{_node.h}|";
|
|
|
|
}
|
|
|
|
_hash = md5_string_utf8(_hash);
|
|
|
|
|
|
|
|
if(vertex_hash != _hash) refrshGroupBG();
|
|
|
|
vertex_hash = _hash;
|
|
|
|
|
|
|
|
if(array_length(group_vertex) < 3) return;
|
|
|
|
|
|
|
|
var _color = getColor();
|
|
|
|
draw_set_color(_color);
|
|
|
|
draw_set_alpha(0.025);
|
|
|
|
draw_primitive_begin(pr_trianglelist);
|
|
|
|
var a = group_vertex[0];
|
|
|
|
var b = group_vertex[1];
|
|
|
|
var c;
|
|
|
|
|
|
|
|
for( var i = 2, n = array_length(group_vertex); i < n; i++ ) {
|
|
|
|
c = group_vertex[i];
|
|
|
|
|
|
|
|
draw_vertex(_x + a[0] * _s, _y + a[1] * _s);
|
|
|
|
draw_vertex(_x + b[0] * _s, _y + b[1] * _s);
|
|
|
|
draw_vertex(_x + c[0] * _s, _y + c[1] * _s);
|
|
|
|
|
|
|
|
b = group_vertex[i];
|
|
|
|
}
|
|
|
|
draw_primitive_end();
|
|
|
|
|
|
|
|
draw_set_alpha(0.3);
|
|
|
|
draw_primitive_begin(pr_linestrip);
|
|
|
|
for( var i = 0, n = array_length(group_vertex); i < n; i++ ) {
|
|
|
|
var a = group_vertex[i];
|
|
|
|
draw_vertex(_x + a[0] * _s, _y + a[1] * _s);
|
|
|
|
}
|
|
|
|
|
|
|
|
a = group_vertex[0];
|
|
|
|
draw_vertex(_x + a[0] * _s, _y + a[1] * _s);
|
|
|
|
draw_primitive_end();
|
|
|
|
|
|
|
|
draw_set_alpha(1);
|
|
|
|
} #endregion
|
2023-11-02 14:37:13 +01:00
|
|
|
|
|
|
|
static attributeDeserialize = function(attr) { #region
|
|
|
|
struct_override(attributes, attr);
|
|
|
|
refreshCacheGroup();
|
|
|
|
} #endregion
|
2023-11-02 12:43:00 +01:00
|
|
|
}
|