#:use-module (gacela video)
#:use-module (gacela audio)
#:use-module (ice-9 optargs)
- #:export (load-texture
- load-font
- *title*
+ #:export (*title*
*width-screen*
*height-screen*
*bpp-screen*
3d-mode?))
-;;; Resources Cache
-
-(define resources-cache (make-weak-value-hash-table))
-
-(define (from-cache key)
- (hash-ref resources-cache key))
-
-(define (into-cache key res)
- (hash-set! resources-cache key res))
-
-(define-macro (use-cache-with module proc)
- (let ((pwc (string->symbol (string-concatenate (list (symbol->string proc) "-without-cache")))))
- `(begin
- (define ,pwc (@ ,module ,proc))
- (define (,proc . param)
- (let* ((key param)
- (res (from-cache key)))
- (cond (res
- res)
- (else
- (set! res (apply ,pwc param))
- (into-cache key res)
- res)))))))
-
-(use-cache-with (gacela video) load-texture)
-(use-cache-with (gacela video) load-font)
-
-
;;; Main Loop
(define loop-flag #f)
--- /dev/null
+;;; Gacela, a GNU Guile extension for fast games development
+;;; Copyright (C) 2009 by Javier Sancho Fernandez <jsf at jsancho dot org>
+;;;
+;;; 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 <http://www.gnu.org/licenses/>.
+
+
+(define-module (gacela utils)
+ #:export (use-cache-with))
+
+
+;;; Cache for procedures
+
+(define (use-cache-with proc)
+ (let ((cache (make-weak-value-hash-table)))
+ (lambda (. param)
+ (let* ((key param)
+ (res (hash-ref cache key)))
+ (cond (res res)
+ (else
+ (set! res (apply proc param))
+ (hash-set! cache key res)
+ res))))))
#:use-module (gacela gl)
#:use-module (gacela ftgl)
#:use-module (gacela math)
+ #:use-module (gacela utils)
#:use-module (ice-9 optargs)
#:use-module (ice-9 receive)
#:export (init-video
progn-textures
draw
load-texture
+ load-texture-without-cache
get-texture-properties
draw-texture
draw-line
set-camera
camera-look
load-font
+ load-font-without-texture
render-text)
#:export-syntax (glmatrix-block))
(else (let ((zoomx (/ (+ width 0.5) old-width)) (zoomy (/ (+ height 0.5) old-height)))
(zoomSurface surface zoomx zoomy 0))))))
-(define* (load-texture filename #:key (min-filter GL_LINEAR) (mag-filter GL_LINEAR))
+(define* (load-texture-without-cache filename #:key (min-filter GL_LINEAR) (mag-filter GL_LINEAR))
(progn-textures
(receive
(image real-w real-h) (load-image-for-texture filename)
(set-texture-size! texture real-w real-h)
texture))))))
+(define load-texture (use-cache-with load-texture-without-cache))
+
(define (get-texture-properties texture)
`((width . ,(texture-w texture)) (height . ,(texture-h texture))))
;;; Text and fonts
-(define* (load-font font-file #:key (size 40) (encoding ft_encoding_unicode))
+(define* (load-font-without-cache font-file #:key (size 40) (encoding ft_encoding_unicode))
(let ((font (ftglCreateTextureFont font-file size)))
(ftglSetFontFaceSize font size 72)
(ftglSetFontCharMap font encoding)
font))
+(define load-font (use-cache-with load-font-without-cache))
+
(define* (render-text text font #:key (size #f))
(cond (size
(cond ((not (= (ftglGetFontFaceSize font) size))