summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2019-05-10 08:34:53 -0400
committerDavid Thompson <dthompson2@worcester.edu>2019-05-12 11:38:43 -0400
commit34975b307a85cbb34b040b8a0c6a0f9104b4c331 (patch)
tree26e27980c64491026eaa1d1d51af9c861d5f7102 /examples
parentdd1ccc8afc8ec0411ac636f542fd4bb8d4d242af (diff)
render: sprite: Rewrite sprite batching API.
This new version performs better and has a better API. It closely resembles Love2D's sprite batch API. * chickadee/render/sprite.scm (with-batched-sprites, sprite-batch-reset!, sprite-batch-begin!, draw-sprite-batched, *batch?*, %batch): Delete. (draw-sprite-unbatched): Rename to 'draw-sprite*'. (<sprite-batch>)[index-buffer, position-buffer, texture-buffer]: Delete fields. [vertex-buffer]: New field. (init-sprite-batch, double-sprite-batch-size!, sprite-batch-add!, sprite-batch-flush!): Rewrite. (make-sprite-batch): Add 'capacity' and 'blend-mode' arguments. (draw-sprite-batch): New procedure. (draw-nine-patch*): Stop using sprite batches for now. * chickadee/render/font.scm: (<font>)[sprite-batches]: New field. (load-tile-font, load-font): Create a sprite batch for each texture loaded. (draw-text*): Use sprite batches. * chickadee/render/tiled.scm: (<tile>)[batch]: New field. (<tileset>)[batch]: New field. (load-tile-map): Create a sprite batch for each tileset. (draw-tile-layer): Use new sprite batch API. (draw-tile-map*): Remove reference to deleted macro.
Diffstat (limited to 'examples')
-rw-r--r--examples/sprite-batch.scm22
1 files changed, 12 insertions, 10 deletions
diff --git a/examples/sprite-batch.scm b/examples/sprite-batch.scm
index c31ffbf..4bddf8f 100644
--- a/examples/sprite-batch.scm
+++ b/examples/sprite-batch.scm
@@ -14,6 +14,7 @@
(statprof))
(define texture #f)
+(define batch #f)
(define start-time (sdl-ticks))
(define avg-frame-time 16)
(define num-sprites 5000)
@@ -37,6 +38,7 @@
(define (load)
(set! *random-state* (random-state-from-platform))
(set! texture (load-image "images/shot.png"))
+ (set! batch (make-sprite-batch texture #:capacity 8000))
(script
(forever
(sleep 60)
@@ -44,13 +46,14 @@
(define stats-text-pos (vec2 4.0 464.0))
(define (draw alpha)
- (with-batched-sprites
- (for-each (match-lambda
- ((r v)
- (set-rect-x! r (+ (rect-x r) (vec2-x v)))
- (set-rect-y! r (+ (rect-y r) (vec2-y v)))
- (draw-sprite* texture r matrix)))
- sprites))
+ (sprite-batch-clear! batch)
+ (for-each (match-lambda
+ ((r v)
+ (set-rect-x! r (+ (rect-x r) (vec2-x v)))
+ (set-rect-y! r (+ (rect-y r) (vec2-y v)))
+ (sprite-batch-add* batch r matrix)))
+ sprites)
+ (draw-sprite-batch batch)
(draw-text stats-text stats-text-pos)
(let ((current-time (sdl-ticks)))
(set! avg-frame-time
@@ -61,6 +64,5 @@
(define (update dt)
(update-agenda 1))
-(gcprof
- (lambda ()
- (run-game #:load load #:draw draw #:update update)))
+(run-game #:load load #:draw draw #:update update
+ #:window-title "sprite batch stress test")