From 58e694abecec7b387fb19f71ced7d66bda468d9b Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas Date: Tue, 31 Oct 2023 14:06:59 +0200 Subject: [PATCH] Optimize canvas drawing by only calling queue_redraw when the image has changed --- src/Tools/3DShapeEdit.gd | 1 + src/UI/Canvas/Canvas.gd | 17 ++++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Tools/3DShapeEdit.gd b/src/Tools/3DShapeEdit.gd index 4e1871bf7..356ec338d 100644 --- a/src/Tools/3DShapeEdit.gd +++ b/src/Tools/3DShapeEdit.gd @@ -77,6 +77,7 @@ var _object_names := { func sprite_changed_this_frame(): _checker_update_qued = true _old_cel_image = _cel.get_image() + Global.canvas.sprite_changed_this_frame = true func _input(_event: InputEvent) -> void: diff --git a/src/UI/Canvas/Canvas.gd b/src/UI/Canvas/Canvas.gd index c504040fd..0841d4588 100644 --- a/src/UI/Canvas/Canvas.gd +++ b/src/UI/Canvas/Canvas.gd @@ -69,7 +69,7 @@ func _input(event: InputEvent) -> void: ): return - var tmp_position: Vector2 = Global.main_viewport.get_local_mouse_position() + var tmp_position := Global.main_viewport.get_local_mouse_position() if get_velocity: var velocity := Input.get_vector( "move_mouse_left", "move_mouse_right", "move_mouse_up", "move_mouse_down" @@ -82,14 +82,12 @@ func _input(event: InputEvent) -> void: var tmp_transform := get_canvas_transform().affine_inverse() current_pixel = tmp_transform.basis_xform(tmp_position) + tmp_transform.origin - if Global.has_focus: - queue_redraw() - sprite_changed_this_frame = false - Tools.handle_draw(Vector2i(current_pixel.floor()), event) if sprite_changed_this_frame: + if Global.has_focus: + queue_redraw() update_selected_cels_textures() @@ -106,7 +104,7 @@ func update_texture(layer_i: int, frame_i := -1, project := Global.current_proje frame_i = project.current_frame if frame_i < project.frames.size() and layer_i < project.layers.size(): - var current_cel: BaseCel = project.frames[frame_i].cels[layer_i] + var current_cel := project.frames[frame_i].cels[layer_i] current_cel.update_texture() @@ -115,7 +113,7 @@ func update_selected_cels_textures(project := Global.current_project) -> void: var frame_index: int = cel_index[0] var layer_index: int = cel_index[1] if frame_index < project.frames.size() and layer_index < project.layers.size(): - var current_cel: BaseCel = project.frames[frame_index].cels[layer_index] + var current_cel := project.frames[frame_index].cels[layer_index] current_cel.update_texture() @@ -129,7 +127,8 @@ func draw_layers() -> void: for i in Global.current_project.layers.size(): if current_cels[i] is GroupCel: continue - if Global.current_project.layers[i].is_visible_in_hierarchy(): + var layer := Global.current_project.layers[i] + if layer.is_visible_in_hierarchy(): var cel_image := current_cels[i].get_image() textures.append(cel_image) opacities.append(current_cels[i].opacity) @@ -137,7 +136,7 @@ func draw_layers() -> void: origins.append(Vector2(move_preview_location) / Vector2(cel_image.get_size())) else: origins.append(Vector2.ZERO) - blend_modes.append(Global.current_project.layers[i].blend_mode) + blend_modes.append(layer.blend_mode) var texture_array := Texture2DArray.new() texture_array.create_from_images(textures) material.set_shader_parameter("layers", texture_array)