[Path] Fix node reallocate preview surface every update frame.

This commit is contained in:
Tanasart 2025-01-20 13:46:55 +07:00
parent 143ab54e7e
commit c791220419
7 changed files with 40 additions and 28 deletions

Binary file not shown.

Binary file not shown.

View file

@ -116,7 +116,7 @@ event_inherited();
return bool(_b & value_bit(junction_called.type)); return bool(_b & value_bit(junction_called.type));
} }
function setPage(pageIndex) { function setPage(pageIndex, subPageIndex = 0) {
ADD_NODE_PAGE = min(pageIndex, array_length(category) - 1); ADD_NODE_PAGE = min(pageIndex, array_length(category) - 1);
subgroups = []; subgroups = [];
subgroup_index = 0; subgroup_index = 0;
@ -192,11 +192,13 @@ event_inherited();
array_push(subgroups, _node); array_push(subgroups, _node);
} }
setSubgroup(0);
setSubgroup(subPageIndex);
} }
function setSubgroup(_subg) { function setSubgroup(_subg) {
subgroup_index = _subg; subgroup_index = _subg;
ADD_NODE_SUBPAGE = _subg;
} }
#endregion #endregion
@ -326,6 +328,7 @@ event_inherited();
break; break;
} }
} }
} }
#endregion #endregion
@ -872,11 +875,13 @@ event_inherited();
if(PREFERENCES.add_node_remember) { if(PREFERENCES.add_node_remember) {
content_pane.scroll_y_raw = ADD_NODE_SCROLL; content_pane.scroll_y_raw = ADD_NODE_SCROLL;
content_pane.scroll_y_to = ADD_NODE_SCROLL; content_pane.scroll_y_to = ADD_NODE_SCROLL;
} else
ADD_NODE_PAGE = 0; } else {
ADD_NODE_PAGE = 0;
ADD_NODE_SUBPAGE = 0;
}
setPage(ADD_NODE_PAGE); setPage(ADD_NODE_PAGE, ADD_NODE_SUBPAGE);
run_in(1, function() /*=>*/ { setPage(ADD_NODE_PAGE) });
#endregion #endregion
#region resize #region resize

View file

@ -83,12 +83,13 @@
DIALOG_CLICK = true; DIALOG_CLICK = true;
globalvar ADD_NODE_PAGE, ADD_NODE_SCROLL; globalvar ADD_NODE_PAGE, ADD_NODE_SCROLL, ADD_NODE_SUBPAGE;
ADD_NODE_PAGE = 0; ADD_NODE_PAGE = 0;
ADD_NODE_SCROLL = 0; ADD_NODE_SUBPAGE = 0;
WINDOW_ACTIVE = noone; ADD_NODE_SCROLL = 0;
TOOLTIP_WINDOW = noone; WINDOW_ACTIVE = noone;
TOOLTIP_WINDOW = noone;
#endregion #endregion
#region macro #region macro

View file

@ -48,8 +48,9 @@ function Node_Path(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
["Anchors", false], ["Anchors", false],
]; ];
output_display_list = [ 1, 0, 2 ]; output_display_list = [ 1, 0, 2 ];
path_preview_surface = noone; _path_preview_surface = noone;
path_preview_surface = noone;
setDynamicInput(1, false); setDynamicInput(1, false);
@ -1149,10 +1150,9 @@ function Node_Path(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
var maxx = boundary.maxx + pad, maxy = boundary.maxy + pad; var maxx = boundary.maxx + pad, maxy = boundary.maxy + pad;
var rngx = maxx - minx, rngy = maxy - miny; var rngx = maxx - minx, rngy = maxy - miny;
var prev_s = 128; var prev_s = 128;
var _surf = surface_create(prev_s, prev_s);
_surf = surface_verify(_surf, prev_s, prev_s); _path_preview_surface = surface_verify(_path_preview_surface, prev_s, prev_s);
surface_set_target(_surf); surface_set_target(_path_preview_surface);
DRAW_CLEAR DRAW_CLEAR
var ox, oy, nx, ny; var ox, oy, nx, ny;
@ -1184,10 +1184,8 @@ function Node_Path(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
shader_set_f("cornerDis", 0.5); shader_set_f("cornerDis", 0.5);
shader_set_f("mixAmo", 1); shader_set_f("mixAmo", 1);
draw_surface_safe(_surf); draw_surface_safe(_path_preview_surface);
surface_reset_shader(); surface_reset_shader();
surface_free(_surf);
} }
static getLineCount = function() { return 1; } static getLineCount = function() { return 1; }
@ -1349,4 +1347,10 @@ function Node_Path(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
} }
static getPreviewBoundingBox = function() { return BBOX().fromBoundingBox(boundary); } static getPreviewBoundingBox = function() { return BBOX().fromBoundingBox(boundary); }
static onCleanUp = function() {
surface_free(_path_preview_surface);
surface_free( path_preview_surface);
}
} }

View file

@ -34,7 +34,8 @@ function Node_Path_Smooth(_x, _y, _group = noone) : Node(_x, _y, _group) constru
boundary = new BoundingBox(); boundary = new BoundingBox();
cached_pos = ds_map_create(); cached_pos = ds_map_create();
path_preview_surface = noone; path_preview_surface = noone;
_path_preview_surface = noone;
#endregion #endregion
#region ---- editor ---- #region ---- editor ----
@ -189,10 +190,9 @@ function Node_Path_Smooth(_x, _y, _group = noone) : Node(_x, _y, _group) constru
var maxx = boundary.maxx + pad, maxy = boundary.maxy + pad; var maxx = boundary.maxx + pad, maxy = boundary.maxy + pad;
var rngx = maxx - minx, rngy = maxy - miny; var rngx = maxx - minx, rngy = maxy - miny;
var prev_s = 128; var prev_s = 128;
var _surf = surface_create(prev_s, prev_s);
_surf = surface_verify(_surf, prev_s, prev_s); _path_preview_surface = surface_verify(_path_preview_surface, prev_s, prev_s);
surface_set_target(_surf); surface_set_target(_path_preview_surface);
DRAW_CLEAR DRAW_CLEAR
var ox, oy, nx, ny; var ox, oy, nx, ny;
@ -224,10 +224,9 @@ function Node_Path_Smooth(_x, _y, _group = noone) : Node(_x, _y, _group) constru
shader_set_f("cornerDis", 0.5); shader_set_f("cornerDis", 0.5);
shader_set_f("mixAmo", 1); shader_set_f("mixAmo", 1);
draw_surface_safe(_surf); draw_surface_safe(_path_preview_surface);
surface_reset_shader(); surface_reset_shader();
surface_free(_surf);
} }
static getLineCount = function() { return 1; } static getLineCount = function() { return 1; }
@ -353,4 +352,9 @@ function Node_Path_Smooth(_x, _y, _group = noone) : Node(_x, _y, _group) constru
} }
} }
static onCleanUp = function() {
surface_free(_path_preview_surface);
surface_free( path_preview_surface);
}
} }

View file

@ -22,8 +22,6 @@ function Node_Segment_Filter(_x, _y, _group = noone) : Node(_x, _y, _group) cons
["Filter", false], 1, 2, 3, ["Filter", false], 1, 2, 3,
]; ];
path_preview_surface = noone;
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
var _segs = outputs[0].getValue(); var _segs = outputs[0].getValue();
var ox, oy, nx, ny; var ox, oy, nx, ny;