From c9cbd41bb6ec00bbdb0b62907ed5aef5a202af1a Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 8 Nov 2014 07:39:31 -0500 Subject: render: Move tileset module to sly/render directory. * sly/tileset.scm: Delete. * sly/render/tileset.scm: New file. * Makefile.am (SOURCES): Add new file. Delete old one. * examples/animation.scm: Use (sly render tileset). * examples/tileset.scm: Likewise. --- Makefile.am | 2 +- examples/animation.scm | 2 +- examples/tilemap.scm | 2 +- sly/render/tileset.scm | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ sly/tileset.scm | 89 -------------------------------------------------- 5 files changed, 92 insertions(+), 92 deletions(-) create mode 100644 sly/render/tileset.scm delete mode 100644 sly/tileset.scm diff --git a/Makefile.am b/Makefile.am index bc1335a..e99fb61 100644 --- a/Makefile.am +++ b/Makefile.am @@ -42,7 +42,6 @@ SOURCES = \ sly/repl.scm \ sly/scene.scm \ sly/signal.scm \ - sly/tileset.scm \ sly/transform.scm \ sly/transition.scm \ sly/window.scm \ @@ -55,6 +54,7 @@ SOURCES = \ sly/render/shader.scm \ sly/render/shape.scm \ sly/render/sprite.scm \ + sly/render/tileset.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 64a49c1..b38b1a8 100644 --- a/examples/animation.scm +++ b/examples/animation.scm @@ -18,7 +18,7 @@ (use-modules (sly animation) (sly game) (sly render sprite) - (sly tileset) + (sly render tileset) (sly vector) (sly window)) diff --git a/examples/tilemap.scm b/examples/tilemap.scm index 05dbd1f..079aa13 100644 --- a/examples/tilemap.scm +++ b/examples/tilemap.scm @@ -22,7 +22,7 @@ (sly game) (sly render sprite) (sly render texture) - (sly tileset) + (sly render tileset) (sly vector) (sly window) (sly scene) diff --git a/sly/render/tileset.scm b/sly/render/tileset.scm new file mode 100644 index 0000000..6802cbb --- /dev/null +++ b/sly/render/tileset.scm @@ -0,0 +1,89 @@ +;;; 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: +;; +;; Tilesets encapsulate a group of uniformly sized texture regions +;; that come from a single texture. +;; +;;; Code: + +(define-module (sly render tileset) + #:use-module (srfi srfi-9) + #:use-module (srfi srfi-42) + #:use-module (sly render texture) + #:export ( + make-tileset + load-tileset + tileset? + tileset-tiles + tileset-width + tileset-height + tileset-margin + tileset-spacing + tileset-ref)) + +(define-record-type + (%make-tileset tiles width height margin spacing) + tileset? + (tiles tileset-tiles) + (width tileset-width) + (height tileset-height) + (margin tileset-margin) + (spacing tileset-spacing)) + +(define (split-texture texture width height margin spacing) + "Split TEXTURE into a vector of texture regions of WIDTH x HEIGHT +size. SPACING refers to the number of pixels separating each +tile. MARGIN refers to the number of pixels on the top and left of +TEXTURE before the first tile begins." + (define (build-tile tx ty) + (let* ((x (+ (* tx (+ width spacing)) margin)) + (y (+ (* ty (+ height spacing)) margin))) + (make-texture-region texture x y width height))) + + (let* ((tw (texture-width texture)) + (th (texture-height texture)) + (rows (/ (- tw margin) (+ width spacing))) + (columns (/ (- tw margin) (+ height spacing)))) + (vector-ec (: y rows) (: x columns) (build-tile x y)))) + +(define* (make-tileset texture width height + #:optional #:key (margin 0) (spacing 0)) + "Return a new tileset that is built by splitting TEXTURE into +tiles." + (let ((tiles (split-texture texture + width + height + margin + spacing))) + (%make-tileset tiles width height margin spacing))) + +(define* (load-tileset filename width height + #:optional #:key (margin 0) (spacing 0)) + "Return a new tileset that is built by loading the texture at +FILENAME and splitting the texture into tiles." + (let* ((tiles (split-texture (load-texture filename) + width + height + margin + spacing))) + (%make-tileset tiles width height margin spacing))) + +(define (tileset-ref tileset i) + "Return the tile texture of TILESET at index I." + (vector-ref (tileset-tiles tileset) i)) diff --git a/sly/tileset.scm b/sly/tileset.scm deleted file mode 100644 index 24bbf54..0000000 --- a/sly/tileset.scm +++ /dev/null @@ -1,89 +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: -;; -;; Tilesets encapsulate a group of uniformly sized texture regions -;; that come from a single texture. -;; -;;; Code: - -(define-module (sly tileset) - #:use-module (srfi srfi-9) - #:use-module (srfi srfi-42) - #:use-module (sly render texture) - #:export ( - make-tileset - load-tileset - tileset? - tileset-tiles - tileset-width - tileset-height - tileset-margin - tileset-spacing - tileset-ref)) - -(define-record-type - (%make-tileset tiles width height margin spacing) - tileset? - (tiles tileset-tiles) - (width tileset-width) - (height tileset-height) - (margin tileset-margin) - (spacing tileset-spacing)) - -(define (split-texture texture width height margin spacing) - "Split TEXTURE into a vector of texture regions of WIDTH x HEIGHT -size. SPACING refers to the number of pixels separating each -tile. MARGIN refers to the number of pixels on the top and left of -TEXTURE before the first tile begins." - (define (build-tile tx ty) - (let* ((x (+ (* tx (+ width spacing)) margin)) - (y (+ (* ty (+ height spacing)) margin))) - (make-texture-region texture x y width height))) - - (let* ((tw (texture-width texture)) - (th (texture-height texture)) - (rows (/ (- tw margin) (+ width spacing))) - (columns (/ (- tw margin) (+ height spacing)))) - (vector-ec (: y rows) (: x columns) (build-tile x y)))) - -(define* (make-tileset texture width height - #:optional #:key (margin 0) (spacing 0)) - "Return a new tileset that is built by splitting TEXTURE into -tiles." - (let ((tiles (split-texture texture - width - height - margin - spacing))) - (%make-tileset tiles width height margin spacing))) - -(define* (load-tileset filename width height - #:optional #:key (margin 0) (spacing 0)) - "Return a new tileset that is built by loading the texture at -FILENAME and splitting the texture into tiles." - (let* ((tiles (split-texture (load-texture filename) - width - height - margin - spacing))) - (%make-tileset tiles width height margin spacing))) - -(define (tileset-ref tileset i) - "Return the tile texture of TILESET at index I." - (vector-ref (tileset-tiles tileset) i)) -- cgit v1.2.3