Reduce size of exported maps.

This commit is contained in:
David Thompson 2024-05-22 14:22:27 -04:00
parent f1afd9e177
commit 793a9ef027
4 changed files with 62 additions and 33 deletions

View file

@ -528,22 +528,24 @@ the default ORIENTATION value of 'orthogonal' is supported."
(bytevector-copy! bv 0 new-bv offset len)
(loop rest (+ offset len))))))))
;; Not a sparse layer packing. Assumes all tiles have something in
;; them.
(define (compile-tile-layer tile-map layer-name)
(let ((tw (tile-map-tile-width tile-map))
(th (tile-map-tile-height tile-map))
(layer (tile-map-layer-ref tile-map layer-name)))
(bytevector-concat
(append-map (lambda (y)
(filter-map (lambda (x)
(let ((tile (tile-layer-ref layer x y)))
(and tile
(let ((bv (make-bytevector 10)))
(bytevector-ieee-single-native-set! bv 0 (* x tw))
(bytevector-ieee-single-native-set! bv 4 (* y th))
(bytevector-u16-native-set! bv 8 (tile-id (map-tile-ref tile)))
bv))))
(iota (tile-layer-width layer))))
(iota (tile-layer-height layer))))))
(let* ((layer (tile-map-layer-ref tile-map layer-name))
(w (tile-layer-width layer))
(h (tile-layer-height layer))
(bv (make-u16vector (* w h))))
(let y-loop ((y 0))
(when (< y h)
(let x-loop ((x 0))
(when (< x w)
(let ((tile (tile-layer-ref layer x y)))
(bytevector-u16-set! bv (* (+ (* y w) x) 2)
(tile-id (map-tile-ref tile))
(endianness little)))
(x-loop (1+ x))))
(y-loop (1+ y))))
bv))
(define obj:wall:brick 1)
(define obj:wall:copper 2)