]> git.jsancho.org Git - gacela.git/commitdiff
Merge branch 'release/0.2'
authorJavier Sancho <jsf@jsancho.org>
Tue, 14 Feb 2017 19:16:21 +0000 (20:16 +0100)
committerJavier Sancho <jsf@jsancho.org>
Tue, 14 Feb 2017 19:16:21 +0000 (20:16 +0100)
12 files changed:
examples/01-hello-world/01-hello-world.scm [new file with mode: 0644]
examples/01-hello-world/hello-world.bmp [new file with mode: 0644]
examples/02-event-driven-programming/02-event-driven-programming.scm [new file with mode: 0644]
examples/02-event-driven-programming/x.bmp [new file with mode: 0755]
examples/fran.scm
examples/hello_world.bmp [deleted file]
gacela.scm
gacela/event.scm [new file with mode: 0644]
gacela/game.scm
gacela/image.scm
gacela/scene.scm
gacela/window.scm [new file with mode: 0644]

diff --git a/examples/01-hello-world/01-hello-world.scm b/examples/01-hello-world/01-hello-world.scm
new file mode 100644 (file)
index 0000000..61263f1
--- /dev/null
@@ -0,0 +1,24 @@
+#!/usr/bin/env guile
+!#
+
+;;; Gacela, a GNU Guile extension for fast games development
+;;; Copyright (C) 2017 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/>.
+
+(use-modules (gacela))
+
+(display-scene
+ (window ((resolution '(640 480)))
+   (bitmap "hello-world.bmp")))
diff --git a/examples/01-hello-world/hello-world.bmp b/examples/01-hello-world/hello-world.bmp
new file mode 100644 (file)
index 0000000..def2531
Binary files /dev/null and b/examples/01-hello-world/hello-world.bmp differ
diff --git a/examples/02-event-driven-programming/02-event-driven-programming.scm b/examples/02-event-driven-programming/02-event-driven-programming.scm
new file mode 100644 (file)
index 0000000..b151233
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/env guile
+!#
+
+;;; Gacela, a GNU Guile extension for fast games development
+;;; Copyright (C) 2017 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/>.
+
+(use-modules (gacela))
+
+(define counter-quit #f)
+(let ((n 0))
+  (set! counter-quit
+    (lambda ()
+      (set! n (+ n 1))
+      (format #t "Quit clicked ~a times !!~%" n)
+      (if (> n 2)
+         (stop-game)))))
+
+(display-scene
+ (window ((resolution '(640 480))
+         (when-quit counter-quit))
+   (bitmap "x.bmp")))
diff --git a/examples/02-event-driven-programming/x.bmp b/examples/02-event-driven-programming/x.bmp
new file mode 100755 (executable)
index 0000000..9633a7e
Binary files /dev/null and b/examples/02-event-driven-programming/x.bmp differ
index ea016f37b8541a4be8a3dd393b03272fdd7f49cf..79c005542f946154d0c85415a31e9fde800bcf7e 100644 (file)
 
 ;;; First example
 
-(run-scene (import-bitmap "hello_world.bmp"))
-
-(define red (import-bitmap "red.bmp"))
+(define red (bitmap "red.bmp"))
 (define left-right-red (move-xy wiggle 0 red))
 (run-scene left-right-red)
 
-(define blue (import-bitmap "blue.bmp"))
+(define blue (bitmap "blue.bmp"))
 (define up-down-blue (move-xy 0 waggle blue))
 (run-scene up-down-blue)
diff --git a/examples/hello_world.bmp b/examples/hello_world.bmp
deleted file mode 100644 (file)
index def2531..0000000
Binary files a/examples/hello_world.bmp and /dev/null differ
index 5b31c641174c17f026b27c8ecc9bf8781f084f58..90840bf9e02d435b37d5e3c189bcebe31fde2b4a 100644 (file)
   (begin
     (define %public-modules
       '((gacela image)
+       (gacela game)
        (gacela math)
-       (gacela scene)))
+       (gacela scene)
+       (gacela window)))
 
     (for-each (let ((i (module-public-interface (current-module))))
                (lambda (m)
diff --git a/gacela/event.scm b/gacela/event.scm
new file mode 100644 (file)
index 0000000..9efd8e1
--- /dev/null
@@ -0,0 +1,37 @@
+;;; Gacela, a GNU Guile extension for fast games development
+;;; Copyright (C) 2017 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 event)
+  #:use-module ((sdl2 events) #:prefix sdl2:)
+  #:export (process-events
+           quit?))
+
+
+(define *current-events* '())
+
+(define (poll-events)
+  (let ((event (sdl2:poll-event)))
+    (cond (event
+          (cons event (poll-events)))
+         (else
+          '()))))
+
+(define (process-events)
+  (set! *current-events* (poll-events)))
+
+(define (quit?)
+  (not (null? (filter (lambda (e) (sdl2:quit-event? e)) *current-events*))))
index dad04126bbd1812ea0ef7b92f4810fb49d33ab9f..48bf1297b2fce045905db6d40030fa10165fe81e 100644 (file)
 
 (define-module (gacela game)
   #:use-module (gacela math)
+  #:use-module (gacela event)
   #:use-module ((sdl2) #:prefix sdl2:)
   #:use-module ((sdl2 render) #:prefix sdl2:)
   #:use-module ((sdl2 surface) #:prefix sdl2:)
   #:use-module ((sdl2 video) #:prefix sdl2:)
   #:use-module (gl)
   #:use-module (srfi srfi-11)
-  #:export (play-game
+  #:export (start-game
+           stop-game
            %sdl-renderer))
 
 
@@ -37,7 +39,8 @@
 (define* (run-game-loop scene #:key
                         (frame-rate 60)
                         (tick-rate 60)
-                        (max-ticks-per-frame 4))
+                        (max-ticks-per-frame 4)
+                       (when-quit #f))
   "Run the game loop.  SCENE is a signal which contains the current
 scene renderer procedure.  FRAME-RATE specifies the optimal number of
 frames to draw SCENE per second.  TICK-RATE specifies the optimal game
@@ -72,7 +75,9 @@ unused accumulator time."
        (cond ((>= ticks max-ticks-per-frame)
               lag)
              ((>= lag tick-interval)
-                                       ;(process-events)
+              (process-events)
+              (if (and (quit?) (procedure? when-quit))
+                  (when-quit))
                                        ;(agenda-tick!)
               (iter (- lag tick-interval) (1+ ticks)))
              (else
@@ -142,7 +147,7 @@ milliseconds of the last iteration of the game loop."
   (set! %gl-context (sdl2:make-gl-context %sdl-window))
   (sdl2:set-gl-swap-interval! 'vsync))
 
-(define* (open-window #:key (title "Untitled") (resolution '(640 480)) (fullscreen? #f))
+(define (open-window title resolution fullscreen?)
   (sdl2:set-window-title! %sdl-window title)
   (sdl2:set-window-size! %sdl-window resolution)
   (sdl2:set-window-fullscreen! %sdl-window fullscreen?)
@@ -152,8 +157,15 @@ milliseconds of the last iteration of the game loop."
   (sdl2:hide-window! %sdl-window)
   (sdl2:sdl-quit))
 
-(define (play-game scene)
+(define* (start-game scene #:key
+                   (title "Untitled")
+                   (resolution '(640 480))
+                   (fullscreen? #f)
+                   (when-quit (lambda () (stop-game))))
   (init-window)
-  (open-window)
-  (run-game-loop scene)
+  (open-window title resolution fullscreen?)
+  (run-game-loop scene #:when-quit when-quit)
   (close-window))
+
+(define (stop-game)
+  (stop-game-loop))
index 370bbd179cdf0415e340d3ba66d2b58df4b79ea9..b1ee674bbe501fe38e8b514277665d49c3c2485d 100644 (file)
   #:use-module ((sdl2 image) #:prefix sdl2:)
   #:use-module ((sdl2 render) #:prefix sdl2:)
   #:use-module ((sdl2 surface) #:prefix sdl2:)
-  #:export (import-bitmap
+  #:export (bitmap
            move-xy))
 
-(define (import-bitmap filename)
+(define (bitmap filename)
   (make-scene
    "bitmap"
    (let ((image (sdl2:load-image filename))
index e62048021a414f34de219e179378b9983ee84029..ccdc23e9c47d9e536859360fa2962efe99aa1b19 100644 (file)
@@ -42,6 +42,6 @@
 (define (display-scene scene . args)
   (apply (scene-procedure scene) args))
 
-(define (run-scene scene)
-  (play-game
-   (scene-procedure scene)))
+(define (run-scene scene . args)
+  (apply start-game
+        (cons (scene-procedure scene) args)))
diff --git a/gacela/window.scm b/gacela/window.scm
new file mode 100644 (file)
index 0000000..6d43ce6
--- /dev/null
@@ -0,0 +1,32 @@
+;;; Gacela, a GNU Guile extension for fast games development
+;;; Copyright (C) 2016 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 window)
+  #:use-module (gacela scene)
+  #:export (window))
+
+
+(define-syntax window
+  (lambda (x)
+    (syntax-case x ()
+      ((_ ((property-name property-value) ...) scene)
+       #'(make-scene
+         "window"
+         (lambda ()
+           (apply run-scene (cons scene
+                                  (append (list (symbol->keyword 'property-name) property-value)
+                                          ...)))))))))