diff options
author | David Thompson <dthompson2@worcester.edu> | 2015-09-21 19:44:10 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2015-09-21 19:48:44 -0400 |
commit | 46544b7dba0081f22e686f70c606a338c7fa52dd (patch) | |
tree | 9688f43493606f7b0e4da8784a7804cc32f128eb /examples/life.scm | |
parent | b7bf25020f146331d161d86ef30df31d2959a8dc (diff) |
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 <model> 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.
Diffstat (limited to 'examples/life.scm')
-rw-r--r-- | examples/life.scm | 53 |
1 files changed, 24 insertions, 29 deletions
diff --git a/examples/life.scm b/examples/life.scm index 2842690..2d4e30a 100644 --- a/examples/life.scm +++ b/examples/life.scm @@ -1,6 +1,6 @@ ;;; Life, Sly edition ;;; Copyright (C) 2015 Christopher Allan Webber <cwebber@dustycloud.org> -;;; Copyright (C) 2014 David Thompson <davet@gnu.org> +;;; Copyright (C) 2014, 2015 David Thompson <davet@gnu.org> ;;; ;;; This program is free software: you can redistribute it and/or ;;; modify it under the terms of the GNU General Public License as @@ -30,11 +30,10 @@ (sly math rect) (sly math transform) (sly math vector) + (sly render) (sly render camera) - (sly render model) (sly render sprite) (sly render color) - (sly render scene) (sly input mouse)) ;;; @@ -68,15 +67,17 @@ (define tile-size 32) (define window-res (vector2 448 480)) +(define alive-texture + (load-texture "mines/images/tile-down.png")) + +(define empty-texture + (load-texture "mines/images/tile-up.png")) + (define sprite-cell-alive - (load-sprite - "mines/images/tile-down.png" - #:anchor 'bottom-left)) + (make-sprite alive-texture #:anchor 'bottom-left)) (define sprite-cell-empty - (load-sprite - "mines/images/tile-up.png" - #:anchor 'bottom-left)) + (make-sprite empty-texture #:anchor 'bottom-left)) ;;; ;;; State @@ -106,10 +107,7 @@ ;; Give a heartbeat indicating it's time to run an evolution on the board ;; (if the simulation is running) (define-signal time-to-evolve - (signal-map - (lambda _ - 'evolve) - (signal-every 20))) + (signal-constant 'evolve (signal-every 20))) (define (tile-on-board? x y board-size) "Is the tile on the board?" @@ -295,17 +293,18 @@ If there is no neighbor on an edge, the board wraps around" (define-signal tiles-view (signal-let ((board board) (board-size board-size)) - (list->model + (list->renderer (enumerate-map (lambda (row row-count) - (list->model + (list->renderer (enumerate-map (lambda (tile-alive col-count) - (model-move (tile-pos row-count col-count - board-size tile-size) - (if tile-alive - sprite-cell-alive - sprite-cell-empty))) + (move (tile-pos row-count col-count + board-size tile-size) + (render-sprite + (if tile-alive + sprite-cell-alive + sprite-cell-empty)))) (vlist->list row)))) ;; FIXME: ;; This slows things down more than it should have to @@ -314,17 +313,13 @@ If there is no neighbor on an edge, the board wraps around" (define-signal camera (signal-let ((running? simulation-running?)) - (orthographic-camera - (vx window-res) (vy window-res) - #:viewport (make-viewport (make-rect (vector2 0 0) window-res) - #:clear-color (if running? - tango-dark-chameleon - tango-dark-scarlet-red))))) + (2d-camera #:area (make-rect (vector2 0 0) window-res) + #:clear-color (if running? + tango-dark-chameleon + tango-dark-scarlet-red)))) (define-signal scene - (signal-let ((model tiles-view) - (camera camera)) - (make-scene camera model))) + (signal-map with-camera camera tiles-view)) ;;; ;;; Initialization |