From 27c195b6d8339e71642fea89c8707d0a0cc153f4 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 7 Nov 2014 19:38:47 -0500 Subject: Rename (sly helpers) module to (sly utils). * sly/helpers.scm: Delete. * sly/utils.scm: New file. * Makefile.am (SOURCES): Remove old file. Add new one. * sly/render/camera.scm: s/helpers/utils/ * sly/scene.scm: Likewise. * sly/shader.scm: Likewise. * sly/sprite.scm: Likewise. * sly/texture.scm: Likewise. * sly/transform.scm: Likewise. * examples/tilemap.scm: Likewise. --- Makefile.am | 2 +- examples/tilemap.scm | 2 +- sly/helpers.scm | 76 --------------------------------------------------- sly/render/camera.scm | 2 +- sly/shader.scm | 2 +- sly/sprite.scm | 2 +- sly/texture.scm | 2 +- sly/utils.scm | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 82 insertions(+), 82 deletions(-) delete mode 100644 sly/helpers.scm create mode 100644 sly/utils.scm diff --git a/Makefile.am b/Makefile.am index 45d501e..7a65af2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -21,6 +21,7 @@ moddir=$(prefix)/share/guile/site/2.0 godir=$(libdir)/guile/2.0/ccache SOURCES = \ + sly/utils.scm \ sly/agenda.scm \ sly/animation.scm \ sly/audio.scm \ @@ -31,7 +32,6 @@ SOURCES = \ sly/font.scm \ sly/fps.scm \ sly/game.scm \ - sly/helpers.scm \ sly/keyboard.scm \ sly/live-reload.scm \ sly/math.scm \ diff --git a/examples/tilemap.scm b/examples/tilemap.scm index 48a8807..bfe41b0 100644 --- a/examples/tilemap.scm +++ b/examples/tilemap.scm @@ -30,7 +30,7 @@ (sly camera) (sly color) (sly transition) - (sly helpers) + (sly utils) (sly keyboard)) (load "common.scm") diff --git a/sly/helpers.scm b/sly/helpers.scm deleted file mode 100644 index d63d470..0000000 --- a/sly/helpers.scm +++ /dev/null @@ -1,76 +0,0 @@ -;;; Sly -;;; Copyright (C) 2013, 2014 David Thompson -;;; Copyright (C) 2014 Ludovic Courtès -;;; -;;; 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: -;; -;; Miscellaneous helper procedures. -;; -;;; Code: - -(define-module (sly helpers) - #:use-module (srfi srfi-1) - #:use-module (rnrs arithmetic bitwise) - #:use-module (sly agenda) - #:export (any-equal? - logand? - define-guardian - memoize - forever - trampoline)) - -(define (any-equal? elem . args) - "Return #t if ELEM equals any of the elements in the list ARGS." - (any (lambda (e) (equal? elem e)) args)) - -(define (logand? . args) - "Return #t if the result of a bitwise AND of the integers in list -ARGS is non-zero." - (not (zero? (apply logand args)))) - -(define-syntax-rule (define-guardian name reaper) - "Define a new guardian called NAME and call REAPER when an object -within the guardian is GC'd. Reaping is ensured to happen from the -same thread that is running the game loop." - (begin - (define name (make-guardian)) - (schedule-each - (lambda () - (let reap ((obj (name))) - (when obj - (reaper obj) - (reap (name)))))))) - -(define (memoize proc) - "Return a memoizing version of PROC." - (let ((cache (make-hash-table))) - (lambda args - (let ((results (hash-ref cache args))) - (if results - (apply values results) - (let ((results (call-with-values (lambda () - (apply proc args)) - list))) - (hash-set! cache args results) - (apply values results))))))) - -(define-syntax-rule (forever body ...) - (while #t body ...)) - -(define-syntax-rule (trampoline proc) - (lambda args - (apply proc args))) diff --git a/sly/render/camera.scm b/sly/render/camera.scm index f5921e3..7a56112 100644 --- a/sly/render/camera.scm +++ b/sly/render/camera.scm @@ -28,7 +28,7 @@ #:use-module (gl low-level) #:use-module (gl enums) #:use-module (sly wrappers gl) - #:use-module (sly helpers) + #:use-module (sly utils) #:use-module (sly color) #:use-module (sly rect) #:use-module (sly transform) diff --git a/sly/shader.scm b/sly/shader.scm index 5e9ad0a..5ad97ab 100644 --- a/sly/shader.scm +++ b/sly/shader.scm @@ -25,7 +25,7 @@ #:use-module (srfi srfi-9) #:use-module (gl) #:use-module (gl low-level) - #:use-module (sly helpers) + #:use-module (sly utils) #:use-module (sly transform) #:use-module (sly math vector) #:use-module (sly color) diff --git a/sly/sprite.scm b/sly/sprite.scm index f6f2d78..33c679f 100644 --- a/sly/sprite.scm +++ b/sly/sprite.scm @@ -31,7 +31,7 @@ #:use-module (sly color) #:use-module (sly config) #:use-module (sly agenda) - #:use-module (sly helpers) + #:use-module (sly utils) #:use-module (sly math) #:use-module (sly mesh) #:use-module (sly shader) diff --git a/sly/texture.scm b/sly/texture.scm index 15521a0..b7221de 100644 --- a/sly/texture.scm +++ b/sly/texture.scm @@ -29,7 +29,7 @@ #:use-module (gl low-level) #:use-module (gl contrib packed-struct) #:use-module (sly color) - #:use-module (sly helpers) + #:use-module (sly utils) #:use-module (sly math vector) #:use-module (sly wrappers gl) #:use-module (sly wrappers freeimage) diff --git a/sly/utils.scm b/sly/utils.scm new file mode 100644 index 0000000..7bf38f7 --- /dev/null +++ b/sly/utils.scm @@ -0,0 +1,76 @@ +;;; Sly +;;; Copyright (C) 2013, 2014 David Thompson +;;; Copyright (C) 2014 Ludovic Courtès +;;; +;;; 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: +;; +;; Miscellaneous helper procedures. +;; +;;; Code: + +(define-module (sly utils) + #:use-module (srfi srfi-1) + #:use-module (rnrs arithmetic bitwise) + #:use-module (sly agenda) + #:export (any-equal? + logand? + define-guardian + memoize + forever + trampoline)) + +(define (any-equal? elem . args) + "Return #t if ELEM equals any of the elements in the list ARGS." + (any (lambda (e) (equal? elem e)) args)) + +(define (logand? . args) + "Return #t if the result of a bitwise AND of the integers in list +ARGS is non-zero." + (not (zero? (apply logand args)))) + +(define-syntax-rule (define-guardian name reaper) + "Define a new guardian called NAME and call REAPER when an object +within the guardian is GC'd. Reaping is ensured to happen from the +same thread that is running the game loop." + (begin + (define name (make-guardian)) + (schedule-each + (lambda () + (let reap ((obj (name))) + (when obj + (reaper obj) + (reap (name)))))))) + +(define (memoize proc) + "Return a memoizing version of PROC." + (let ((cache (make-hash-table))) + (lambda args + (let ((results (hash-ref cache args))) + (if results + (apply values results) + (let ((results (call-with-values (lambda () + (apply proc args)) + list))) + (hash-set! cache args results) + (apply values results))))))) + +(define-syntax-rule (forever body ...) + (while #t body ...)) + +(define-syntax-rule (trampoline proc) + (lambda args + (apply proc args))) -- cgit v1.2.3