From 40f21faf0413748213066632c3f2ad7e11668d71 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 7 Nov 2014 22:31:16 -0500 Subject: render: Move sprite module to sly/render directory. * sly/sprite.scm: Delete. * sly/render/sprite.scm: New file. * Makefile.am (SOURCES): Add new file and delete old one. * sly/font.scm: Use (sly render sprite). * examples/animation.scm: Likewise. * examples/common.scm: Likewise. * examples/coroutine.scm: Likewise. * examples/joystick.scm: Likewise. * examples/particles.scm: Likewise. * examples/simple.scm: Likewise. * examples/tilemap.scm: Likewise. * examples/transition.scm: Likewise. --- Makefile.am | 2 +- examples/animation.scm | 2 +- examples/common.scm | 2 +- examples/coroutine.scm | 2 +- examples/joystick.scm | 2 +- examples/particles.scm | 2 +- examples/simple.scm | 2 +- examples/tilemap.scm | 2 +- examples/transition.scm | 2 +- sly/font.scm | 2 +- sly/render/sprite.scm | 105 ++++++++++++++++++++++++++++++++++++++++++++++++ sly/sprite.scm | 105 ------------------------------------------------ 12 files changed, 115 insertions(+), 115 deletions(-) create mode 100644 sly/render/sprite.scm delete mode 100644 sly/sprite.scm diff --git a/Makefile.am b/Makefile.am index a5f1aa8..9921ff2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -45,7 +45,6 @@ SOURCES = \ sly/shader.scm \ sly/shape.scm \ sly/signal.scm \ - sly/sprite.scm \ sly/tileset.scm \ sly/transform.scm \ sly/transition.scm \ @@ -55,6 +54,7 @@ SOURCES = \ sly/render/camera.scm \ sly/render/framebuffer.scm \ sly/render/texture.scm \ + sly/render/sprite.scm \ sly/render/vertex-array.scm \ sly/render/context.scm \ sly/render/renderer.scm \ diff --git a/examples/animation.scm b/examples/animation.scm index 04fc46e..64a49c1 100644 --- a/examples/animation.scm +++ b/examples/animation.scm @@ -17,7 +17,7 @@ (use-modules (sly animation) (sly game) - (sly sprite) + (sly render sprite) (sly tileset) (sly vector) (sly window)) diff --git a/examples/common.scm b/examples/common.scm index 07e7aae..f3c91b2 100644 --- a/examples/common.scm +++ b/examples/common.scm @@ -21,7 +21,7 @@ (sly keyboard) (sly repl) (sly signal) - (sly sprite) + (sly render sprite) (sly window)) (open-window) diff --git a/examples/coroutine.scm b/examples/coroutine.scm index 708f174..ae8229d 100644 --- a/examples/coroutine.scm +++ b/examples/coroutine.scm @@ -19,7 +19,7 @@ (sly agenda) (sly coroutine) (sly game) - (sly sprite) + (sly render sprite) (sly render texture) (sly vector) (sly window)) diff --git a/examples/joystick.scm b/examples/joystick.scm index 268c1ee..6714ff3 100644 --- a/examples/joystick.scm +++ b/examples/joystick.scm @@ -24,7 +24,7 @@ (use-modules (sly game) (sly repl) - (sly sprite) + (sly render sprite) (sly render texture) (sly joystick) (sly signal) diff --git a/examples/particles.scm b/examples/particles.scm index 1d2f335..17a043d 100644 --- a/examples/particles.scm +++ b/examples/particles.scm @@ -19,7 +19,7 @@ (srfi srfi-9) (sly agenda) (sly game) - (sly sprite) + (sly render sprite) (sly render texture) (sly vector) (sly window)) diff --git a/examples/simple.scm b/examples/simple.scm index 09554d3..92a2010 100644 --- a/examples/simple.scm +++ b/examples/simple.scm @@ -19,7 +19,7 @@ (sly game) (sly rect) (sly scene) - (sly sprite) + (sly render sprite) (sly transform) (sly vector) (sly window) diff --git a/examples/tilemap.scm b/examples/tilemap.scm index 8ce7f81..05dbd1f 100644 --- a/examples/tilemap.scm +++ b/examples/tilemap.scm @@ -20,7 +20,7 @@ (srfi srfi-9) (srfi srfi-42) (sly game) - (sly sprite) + (sly render sprite) (sly render texture) (sly tileset) (sly vector) diff --git a/examples/transition.scm b/examples/transition.scm index 606942f..1e18e0e 100644 --- a/examples/transition.scm +++ b/examples/transition.scm @@ -16,7 +16,7 @@ ;;; . (use-modules (sly game) - (sly sprite) + (sly render sprite) (sly vector) (sly window) (sly color) diff --git a/sly/font.scm b/sly/font.scm index 9d28f74..c14905b 100644 --- a/sly/font.scm +++ b/sly/font.scm @@ -35,7 +35,7 @@ #:use-module (sly config) #:use-module (sly mesh) #:use-module (sly shader) - #:use-module (sly sprite) + #:use-module (sly render sprite) #:use-module (sly render texture) #:export (enable-fonts load-font diff --git a/sly/render/sprite.scm b/sly/render/sprite.scm new file mode 100644 index 0000000..5bdaac7 --- /dev/null +++ b/sly/render/sprite.scm @@ -0,0 +1,105 @@ +;;; Sly +;;; Copyright (C) 2013, 2014 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 +;;; published by the Free Software Foundation, either version 3 of the +;;; License, or (at your option) any later version. +;;; +;;; This program is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with this program. If not, see +;;; . + +;;; Commentary: +;; +;; Sprites are typically the most important part of a 2D game. This +;; module provides sprites as an abstraction around OpenGL textures. +;; +;;; Code: + +(define-module (sly render sprite) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) + #:use-module (gl) + #:use-module (gl contrib packed-struct) + #:use-module ((sdl sdl) #:prefix SDL:) + #:use-module (sly color) + #:use-module (sly config) + #:use-module (sly agenda) + #:use-module (sly utils) + #:use-module (sly math) + #:use-module (sly mesh) + #:use-module (sly shader) + #:use-module (sly signal) + #:use-module (sly render texture) + #:use-module (sly math vector) + #:export (make-sprite + load-sprite + make-animated-sprite)) + +;;; +;;; Sprites +;;; + +(define* (make-sprite texture #:optional #:key + (shader (load-default-shader)) + (anchor 'center) + (color white)) + "Return a 2D rectangular mesh that displays the image TEXTURE. The +size of the mesh is the size of TEXTURE, in pixels. Optionally, a +custom SHADER can be specified." + (let* ((anchor (anchor-texture texture anchor)) + (x1 (- (vx anchor))) + (y1 (- (vy anchor))) + (x2 (+ x1 (texture-width texture))) + (y2 (+ y1 (texture-height texture))) + (s1 (texture-s1 texture)) + (t1 (texture-t1 texture)) + (s2 (texture-s2 texture)) + (t2 (texture-t2 texture))) + (make-mesh + #:shader shader + #:texture texture + #:indices #(0 3 2 0 2 1) + #:positions (vector + (vector3 x1 y1 0) + (vector3 x2 y1 0) + (vector3 x2 y2 0) + (vector3 x1 y2 0)) + #:textures (vector + (vector2 s1 t1) + (vector2 s2 t1) + (vector2 s2 t2) + (vector2 s1 t2))))) + +(define* (load-sprite file-name #:optional #:key (shader (load-default-shader)) + (anchor 'center) (color white)) + "Return a sprite mesh for the texture loaded from FILE-NAME. +Optionally, a custom SHADER can be specified." + (make-sprite (load-texture file-name) #:shader shader + #:anchor anchor #:color color)) + +(define* (make-animated-sprite textures frame-duration #:optional #:key + (loop? #t) + (shader (load-default-shader))) + "Return a signal that iterates through the list TEXTURES and +displays them each for FRAME-DURATION ticks. The optional LOOP? flag +specifies if the animation should play once or indefinitely. +Optionally, a SHADER can be specified, otherwise the default mesh +shader is used." + (let ((frames (map (cut make-sprite <> #:shader shader) textures))) + (signal-generator + (define (animate) + (for-each (lambda (frame) + (yield frame) + (wait frame-duration)) + frames)) + + (if loop? + (forever (animate)) + (animate))))) diff --git a/sly/sprite.scm b/sly/sprite.scm deleted file mode 100644 index e452247..0000000 --- a/sly/sprite.scm +++ /dev/null @@ -1,105 +0,0 @@ -;;; Sly -;;; Copyright (C) 2013, 2014 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 -;;; published by the Free Software Foundation, either version 3 of the -;;; License, or (at your option) any later version. -;;; -;;; This program is distributed in the hope that it will be useful, -;;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -;;; General Public License for more details. -;;; -;;; You should have received a copy of the GNU General Public License -;;; along with this program. If not, see -;;; . - -;;; Commentary: -;; -;; Sprites are typically the most important part of a 2D game. This -;; module provides sprites as an abstraction around OpenGL textures. -;; -;;; Code: - -(define-module (sly sprite) - #:use-module (srfi srfi-1) - #:use-module (srfi srfi-26) - #:use-module (gl) - #:use-module (gl contrib packed-struct) - #:use-module ((sdl sdl) #:prefix SDL:) - #:use-module (sly color) - #:use-module (sly config) - #:use-module (sly agenda) - #:use-module (sly utils) - #:use-module (sly math) - #:use-module (sly mesh) - #:use-module (sly shader) - #:use-module (sly signal) - #:use-module (sly render texture) - #:use-module (sly math vector) - #:export (make-sprite - load-sprite - make-animated-sprite)) - -;;; -;;; Sprites -;;; - -(define* (make-sprite texture #:optional #:key - (shader (load-default-shader)) - (anchor 'center) - (color white)) - "Return a 2D rectangular mesh that displays the image TEXTURE. The -size of the mesh is the size of TEXTURE, in pixels. Optionally, a -custom SHADER can be specified." - (let* ((anchor (anchor-texture texture anchor)) - (x1 (- (vx anchor))) - (y1 (- (vy anchor))) - (x2 (+ x1 (texture-width texture))) - (y2 (+ y1 (texture-height texture))) - (s1 (texture-s1 texture)) - (t1 (texture-t1 texture)) - (s2 (texture-s2 texture)) - (t2 (texture-t2 texture))) - (make-mesh - #:shader shader - #:texture texture - #:indices #(0 3 2 0 2 1) - #:positions (vector - (vector3 x1 y1 0) - (vector3 x2 y1 0) - (vector3 x2 y2 0) - (vector3 x1 y2 0)) - #:textures (vector - (vector2 s1 t1) - (vector2 s2 t1) - (vector2 s2 t2) - (vector2 s1 t2))))) - -(define* (load-sprite file-name #:optional #:key (shader (load-default-shader)) - (anchor 'center) (color white)) - "Return a sprite mesh for the texture loaded from FILE-NAME. -Optionally, a custom SHADER can be specified." - (make-sprite (load-texture file-name) #:shader shader - #:anchor anchor #:color color)) - -(define* (make-animated-sprite textures frame-duration #:optional #:key - (loop? #t) - (shader (load-default-shader))) - "Return a signal that iterates through the list TEXTURES and -displays them each for FRAME-DURATION ticks. The optional LOOP? flag -specifies if the animation should play once or indefinitely. -Optionally, a SHADER can be specified, otherwise the default mesh -shader is used." - (let ((frames (map (cut make-sprite <> #:shader shader) textures))) - (signal-generator - (define (animate) - (for-each (lambda (frame) - (yield frame) - (wait frame-duration)) - frames)) - - (if loop? - (forever (animate)) - (animate))))) -- cgit v1.2.3