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/joystick.scm | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'examples/joystick.scm') diff --git a/examples/joystick.scm b/examples/joystick.scm index a191de5..661b18e 100644 --- a/examples/joystick.scm +++ b/examples/joystick.scm @@ -1,5 +1,6 @@ ;;; Sly ;;; Copyright (C) 2014 Jordan Russell +;;; Copyright (C) 2015 David Thompson ;;; ;;; This program is free software: you can redistribute it and/or ;;; modify it under the terms of the GNU General Public License as @@ -17,21 +18,21 @@ ;;; Commentary: ;; -;; Joystick example code +;; Joystick example code. ;; ;;; Code: (use-modules (sly game) (sly signal) (sly window) + (sly math rect) (sly math vector) (sly input joystick) + (sly render) (sly render camera) - (sly render model) (sly render sprite) (sly render texture) - (sly render font) - (sly render scene)) + (sly render font)) (load "common.scm") @@ -42,7 +43,10 @@ (define resolution (vector2 640 480)) -(define player (load-sprite "images/p1_front.png")) +(define player-texture + (load-texture "images/p1_front.png")) + +(define player (make-sprite player-texture)) (define-signal player-position (signal-fold v+ (vector2 320 240) @@ -56,7 +60,8 @@ (define-signal caption (signal-map (lambda (text) - (model-move (vector2 -76 -90) (label font text))) + (move (vector2 -76 -90) + (render-sprite (make-label font text)))) (signal-merge (make-signal "Press a button") (button-caption-signal "Hello there" 0) @@ -64,15 +69,20 @@ (button-caption-signal "This is the other caption" 2) (button-caption-signal "This is the other other caption" 3)))) -(define-signal model - (signal-map (lambda (position caption) - (model-move position (model-group player caption))) - player-position caption)) +(define-signal view + (signal-let ((position player-position) + (caption caption)) + (move position + (render-begin + (render-sprite player) + caption)))) -(define camera (orthographic-camera (vx resolution) (vy resolution))) +(define camera + (2d-camera #:area (make-rect (vector2 0 0) resolution))) (define-signal scene - (signal-map (lambda (model) (make-scene camera model)) model)) + (signal-let ((view view)) + (with-camera camera view))) (add-hook! joystick-axis-hook (lambda (which axis value) -- cgit v1.2.3