1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00

Draw optimizer (#657)

* draw optimizer

* improvements

* some memory improvements

don't think this one's needed but doing it just in case...

* formatting

* add limit change with brush

* fixed a small bug

cache was being kept when frames were changed

* formatting

* change `_cache_limit` on changing `_brush_size`
This commit is contained in:
Variable 2022-03-03 17:54:27 +05:00 committed by GitHub
parent ce026395df
commit 57ea4d25f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View file

@ -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:

View file

@ -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)