From 46544b7dba0081f22e686f70c606a338c7fa52dd Mon Sep 17 00:00:00 2001 From: David Thompson Date: Mon, 21 Sep 2015 19:44:10 -0400 Subject: render: Reimplement rendering engine using functional combinators. Warning: This is a huge commit. I completely gutted the old scene graph and replaced it with a somewhat monadic rendering combinator module instead. The interface remains purely functional, but replaces the data type with procedures in the rendering monad instead. This opens the door for rendering *anything*, not just meshes. Now I can implement particle systems and other non-static things. --- examples/animation.scm | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'examples/animation.scm') diff --git a/examples/animation.scm b/examples/animation.scm index 5dc9166..8aaff2e 100644 --- a/examples/animation.scm +++ b/examples/animation.scm @@ -15,25 +15,29 @@ ;;; along with this program. If not, see ;;; . -(use-modules (sly game) +(use-modules (sly utils) + (sly game) (sly window) (sly signal) (sly math) + (sly math rect) (sly math tween) (sly math vector) + (sly render) (sly render camera) - (sly render model) (sly render sprite) - (sly render tileset) - (sly render scene)) + (sly render tileset)) (load "common.scm") +(define sprite* (memoize make-sprite)) +(define move* (memoize move)) + (define walk-cycle (let ((tiles (load-tileset "images/princess.png" 64 64))) (list->vector (map (lambda (id) - (sprite (tileset-ref tiles id))) + (sprite* (tileset-ref tiles id))) '(19 20 21 22 23 24 25 26))))) (define position-tween @@ -46,13 +50,14 @@ (tween (compose floor lerp) (compose ease-linear ease-loop) 0 frame-count (* frame-count frame-rate)))) -(define camera (orthographic-camera 640 480)) +(define camera (2d-camera #:area (make-rect 0 0 640 480))) (define-signal scene (signal-let ((time (signal-timer))) - (let* ((frame (vector-ref walk-cycle (frame-tween time))) - (model (model-move (position-tween time) frame))) - (make-scene camera model)))) + (let* ((frame (vector-ref walk-cycle (frame-tween time)))) + (with-camera camera + (move* (position-tween time) + (render-sprite frame)))))) (with-window (make-window #:title "Animation") (run-game-loop scene)) -- cgit v1.2.3