diff --git a/src/Tools/BaseTool.gd b/src/Tools/BaseTool.gd index 67ef9feee..cd0aaf04c 100644 --- a/src/Tools/BaseTool.gd +++ b/src/Tools/BaseTool.gd @@ -8,6 +8,9 @@ var cursor_text := "" var _cursor := Vector2.INF +var _draw_cache: PoolVector2Array = [] # for storing already drawn pixels +var _for_frame := 0 # cache for which frame? + func _ready() -> void: kname = name.replace(" ", "_").to_lower() @@ -40,6 +43,7 @@ func update_config() -> void: func draw_start(_position: Vector2) -> void: + _draw_cache = [] is_moving = true @@ -52,6 +56,7 @@ func draw_move(position: Vector2) -> void: func draw_end(_position: Vector2) -> void: is_moving = false + _draw_cache = [] func cursor_move(position: Vector2) -> void: diff --git a/src/Tools/Draw.gd b/src/Tools/Draw.gd index f2ede06f0..c332c1465 100644 --- a/src/Tools/Draw.gd +++ b/src/Tools/Draw.gd @@ -2,6 +2,7 @@ extends BaseTool var _brush := Brushes.get_default_brush() var _brush_size := 1 +var _cache_limit: int = 3 var _brush_interpolate := 0 var _brush_image := Image.new() var _brush_texture := ImageTexture.new() @@ -43,6 +44,7 @@ func _on_Brush_selected(brush: Brushes.Brush) -> void: func _on_BrushSize_value_changed(value: float) -> void: _brush_size = int(value) + _cache_limit = (_brush_size * _brush_size) * 3 # This equation seems the best match update_config() save_config() @@ -345,6 +347,13 @@ func draw_indicator_at(position: Vector2, offset: Vector2, color: Color) -> void func _set_pixel(position: Vector2, ignore_mirroring := false) -> void: + if position in _draw_cache and _for_frame == Global.current_project.current_frame: + return + if _draw_cache.size() > _cache_limit or _for_frame != Global.current_project.current_frame: + _draw_cache = [] + _for_frame = Global.current_project.current_frame + _draw_cache.append(position) # Store the position of pixel + var project: Project = Global.current_project if project.tile_mode and project.get_tile_mode_rect().has_point(position): position = position.posmodv(project.size)