Skip to content

Commit

Permalink
fix rendering cache
Browse files Browse the repository at this point in the history
  • Loading branch information
cxxxr committed Oct 2, 2023
1 parent 01cd4ec commit 40f4fd3
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/display-3.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,14 @@

(defun invalidate-cache (window y height)
(setf (drawing-cache window)
(remove-if (lambda (elt)
(destructuring-bind (cache-y cache-height cache-logical-line) elt
(declare (ignore cache-logical-line))
(not (or (<= (+ y height)
cache-y)
(<= (+ cache-y cache-height)
y)))))
(drawing-cache window))))
(remove-if-not (lambda (elt)
(destructuring-bind (cache-y cache-height cache-logical-line) elt
(declare (ignore cache-logical-line))
(or (< (+ y height)
cache-y)
(<= (+ cache-y cache-height)
y))))
(drawing-cache window))))

(defun update-and-validate-cache-p (window y height objects)
(cond ((validate-cache-p window y height objects) t)
Expand All @@ -324,6 +324,10 @@
(drawing-cache window))
nil)))

(defun render-line-with-caching (window x y objects height)
(unless (update-and-validate-cache-p window y height objects)
(render-line window x y objects height)))

(defun max-height-of-objects (objects)
(loop :for object :in objects
:maximize (object-height object)))
Expand All @@ -344,8 +348,7 @@
(loop :for objects :in objects-per-physical-line
:for height := (max-height-of-objects objects)
:for x := 0 :then left-side-width
:do (unless (update-and-validate-cache-p window y height objects)
(render-line window x y objects height))
:do (render-line-with-caching window x y objects height)
(incf y height)
:sum height)))

Expand Down Expand Up @@ -404,8 +407,7 @@
(horizontal-scroll-start window)
(+ (horizontal-scroll-start window)
(window-view-width window)))))
(unless (update-and-validate-cache-p window y height objects)
(render-line window 0 y objects height)))
(render-line-with-caching window 0 y objects height))
height))

(defun redraw-lines (window)
Expand Down

0 comments on commit 40f4fd3

Please sign in to comment.