summaryrefslogtreecommitdiff
path: root/chickadee/render/tiled.scm
diff options
context:
space:
mode:
Diffstat (limited to 'chickadee/render/tiled.scm')
-rw-r--r--chickadee/render/tiled.scm51
1 files changed, 30 insertions, 21 deletions
diff --git a/chickadee/render/tiled.scm b/chickadee/render/tiled.scm
index 1a4c200..1fbdbe6 100644
--- a/chickadee/render/tiled.scm
+++ b/chickadee/render/tiled.scm
@@ -118,16 +118,17 @@
(duration animation-frame-duration))
(define-record-type <tile>
- (%make-tile id texture animation properties)
+ (%make-tile id texture batch animation properties)
tile?
(id tile-id)
(texture tile-texture)
+ (batch tile-batch)
(animation tile-animation)
(properties tile-properties))
(define-record-type <tileset>
(%make-tileset name first-gid size tile-width tile-height
- atlas tiles properties)
+ atlas tiles properties batch)
tileset?
(name tileset-name)
(first-gid tileset-first-gid)
@@ -136,7 +137,8 @@
(tile-height tileset-tile-height)
(atlas tileset-atlas)
(tiles tileset-tiles)
- (properties tileset-properties))
+ (properties tileset-properties)
+ (batch tileset-batch))
(define-record-type <map-tile>
(%make-map-tile tile rect)
@@ -230,26 +232,25 @@
(duration (attr node 'duration string->number)))
;; TODO: lookup actual tile in tileset
(%make-animation-frame tile-id duration)))
- (define (parse-tile node rows columns atlas)
+ (define (parse-tile node rows columns atlas batch)
(let ((id (attr node 'id string->number))
(animation (map parse-frame ((sxpath '(animation frame)) node)))
(properties (map parse-property
((sxpath '(properties property)) node))))
- (%make-tile id (texture-atlas-ref atlas id)
- animation properties)))
- (define (parse-tiles nodes size columns atlas)
+ (%make-tile id (texture-atlas-ref atlas id) batch animation properties)))
+ (define (parse-tiles nodes size columns atlas batch)
(let ((table (make-hash-table))
(tiles (make-vector size))
(rows (/ size columns)))
(for-each (lambda (node)
- (let ((tile (parse-tile node rows columns atlas)))
+ (let ((tile (parse-tile node rows columns atlas batch)))
(hash-set! table (tile-id tile) tile)))
nodes)
(let loop ((i 0))
(when (< i size)
(let ((tile
(or (hash-ref table i)
- (%make-tile i (texture-atlas-ref atlas i) #f '()))))
+ (%make-tile i (texture-atlas-ref atlas i) batch #f '()))))
(vector-set! tiles i tile))
(loop (+ i 1))))
tiles))
@@ -266,11 +267,12 @@
(texture (parse-image ((sxpath '(image)) node)))
(atlas (split-texture texture tile-width tile-height
#:margin margin #:spacing spacing))
- (tiles (parse-tiles ((sxpath '(tile)) node) size columns atlas))
+ (batch (make-sprite-batch texture))
+ (tiles (parse-tiles ((sxpath '(tile)) node) size columns atlas batch))
(properties (map parse-property
((sxpath '(properties property)) node))))
(%make-tileset name first-gid size tile-width tile-height
- atlas tiles properties)))
+ atlas tiles properties batch)))
(define (parse-external-tileset node)
(let* ((first-gid (attr node 'firstgid string->number))
(source (scope (attr node 'source)))
@@ -419,9 +421,11 @@
(let ((tile (vector-ref (tile-layer-tiles layer)
(+ (* y width) x))))
(when tile
- (draw-sprite* (tile-texture (map-tile-ref tile))
- (map-tile-rect tile)
- matrix)))
+ (let ((tref (map-tile-ref tile)))
+ (sprite-batch-add* (tile-batch tref)
+ (map-tile-rect tile)
+ matrix
+ #:texture-region (tile-texture tref)))))
(x-loop (+ x 1))))
(y-loop (+ y 1))))))
@@ -440,13 +444,18 @@
(y1 (max (inexact->exact (floor (/ ry th))) 0))
(x2 (min (inexact->exact (ceiling (/ (+ rx rw) tw))) w))
(y2 (min (inexact->exact (ceiling (/ (+ ry rh) th))) h)))
- (with-batched-sprites
- (vector-for-each (lambda (i layer)
- (when (and (tile-layer? layer)
- (or (not layers)
- (memv i layers)))
- (draw-tile-layer layer matrix x1 y1 x2 y2)))
- (tile-map-layers tile-map)))))
+ (vector-for-each (lambda (i layer)
+ (when (and (tile-layer? layer)
+ (or (not layers)
+ (memv i layers)))
+ (for-each (lambda (tileset)
+ (sprite-batch-clear! (tileset-batch tileset)))
+ (tile-map-tilesets tile-map))
+ (draw-tile-layer layer matrix x1 y1 x2 y2)
+ (for-each (lambda (tileset)
+ (draw-sprite-batch (tileset-batch tileset)))
+ (tile-map-tilesets tile-map))))
+ (tile-map-layers tile-map))))
(define %null-vec2 (vec2 0.0 0.0))
(define %default-scale (vec2 1.0 1.0))