[pal-cvs] CVS pal

tneste tneste at common-lisp.net
Fri Jul 27 20:12:14 UTC 2007


Update of /project/pal/cvsroot/pal
In directory clnet:/tmp/cvs-serv3945

Modified Files:
	ffi.lisp pal.lisp todo.txt 
Log Message:
Bug fixes in ffi.lisp
Added some sounds in examples/teddy.lisp

--- /project/pal/cvsroot/pal/ffi.lisp	2007/07/24 12:55:06	1.13
+++ /project/pal/cvsroot/pal/ffi.lisp	2007/07/27 20:12:13	1.14
@@ -472,8 +472,8 @@
 
 (defmethod free-resource ((resource music))
   (when (music-music resource)
-    (setf (music-music resource) nil)
-    (free-music (music-music resource))))
+    (free-music (music-music resource))
+    (setf (music-music resource) nil)))
 
 (defmethod free-resource ((resource font))
   (when (font-image resource)
@@ -483,13 +483,13 @@
 
 (defmethod free-resource ((resource image))
   (when (> (image-texture resource) 0)
-    (setf (image-texture resource) 0)
-    (gl-delete-texture (image-texture resource))))
+    (gl-delete-texture (image-texture resource))
+    (setf (image-texture resource) 0)))
 
 (defmethod free-resource ((resource sample))
   (when (sample-chunk resource)
-    (setf (sample-chunk resource) nil)
-    (free-chunk (sample-chunk resource))))
+    (free-chunk (sample-chunk resource))
+    (setf (sample-chunk resource) nil)))
 
 (defun free-all-resources ()
   (dolist (r *resources*)
@@ -497,22 +497,6 @@
   (assert (null *resources*)))
 
 
-
-(cffi:defctype new-music :pointer)
-(defmethod cffi:translate-from-foreign (value (name (eql 'new-music)))
-  (assert (not (cffi:null-pointer-p value)))
-  (let ((music (make-music :music value)))
-    (register-resource music)
-    music))
-
-(cffi:defctype new-sample :pointer)
-(defmethod cffi:translate-from-foreign (value (name (eql 'new-sample)))
-  (assert (not (cffi:null-pointer-p value)))
-  (let ((sample (make-sample :chunk value)))
-    (register-resource sample)
-    sample))
-
-
 ;; Main SDL
 
 (cffi:defcfun ("SDL_Init" init) :int
@@ -609,7 +593,7 @@
 (cffi:defcfun ("Mix_FreeChunk" free-chunk) :void
   (chunk :pointer))
 
-(cffi:defcfun ("Mix_LoadWAV_RW" load-wav-rw) new-sample
+(cffi:defcfun ("Mix_LoadWAV_RW" load-wav-rw) :pointer
   (io :pointer) (int :int))
 
 (defun load-wav (file)
@@ -621,7 +605,7 @@
 (cffi:defcfun ("Mix_SetPosition" set-position) :int
   (channel :int) (angle :int16) (distance :uint8))
 
-(cffi:defcfun ("Mix_QuickLoad_RAW" quickload-raw) new-sample
+(cffi:defcfun ("Mix_QuickLoad_RAW" quickload-raw) :pointer
   (uint8-ptr :pointer) (length :uint32))
 
 (cffi:defcfun ("Mix_PlayChannelTimed" play-channel-timed) :int
@@ -632,7 +616,7 @@
 
 (cffi:defcfun ("Mix_HaltMusic" halt-music) :int)
 
-(cffi:defcfun ("Mix_LoadMUS" load-music) new-music
+(cffi:defcfun ("Mix_LoadMUS" load-music) :pointer
   (file :string))
 
 (cffi:defcfun ("Mix_PlayMusic" play-music) :int
--- /project/pal/cvsroot/pal/pal.lisp	2007/07/24 12:55:06	1.19
+++ /project/pal/cvsroot/pal/pal.lisp	2007/07/27 20:12:14	1.20
@@ -4,7 +4,7 @@
 ;; fix the fps
 ;; clean up the do-event
 ;; open quads and other optimisations
-;; test with latest cffi and sdl libs
+;; test with latest sdl libs
 
 
 (declaim (optimize (speed 3)
@@ -56,7 +56,7 @@
   (when *pal-running*
     (close-pal))
   (pal-ffi:init (logior pal-ffi:+init-video+ pal-ffi:+init-audio+))
-  (pal-ffi:open-audio 22050 pal-ffi:+audio-s16+ 2 2048)
+  (pal-ffi:open-audio 22050 pal-ffi:+audio-s16+ 0 2048)
   (pal-ffi:gl-set-attribute pal-ffi:+gl-depth-size+ 0)
   (pal-ffi:gl-set-attribute pal-ffi:+gl-doublebuffer+ 1)
   (pal-ffi:gl-pixel-store pal-ffi:+gl-pack-alignment+ 1)
@@ -699,15 +699,20 @@
 (defun load-sample (file &optional (volume 255))
   "Volume 0-255"
   (let ((sample (pal-ffi:load-wav (data-path file))))
-    (pal-ffi:volume-chunk (pal-ffi:sample-chunk sample) (1+ (truncate volume 2)))
-    sample))
+    (assert (not (cffi:null-pointer-p sample)))
+    (let ((sample (pal-ffi:register-resource (pal-ffi::make-sample :chunk sample))))
+      (pal-ffi:volume-chunk (pal-ffi:sample-chunk sample) (1+ (truncate volume 2)))
+      sample)))
 
 (declaim (inline play-sample))
 (defun play-sample (sample &key (loops nil) (angle 0) (volume 255))
-  "Angle is an integer between 0-360. Volume is an integer between 0-255."
-  (let ((channel (pal-ffi:play-channel -1 (pal-ffi:sample-chunk sample) (if (numberp loops)
-                                                                            loops
-                                                                            0))))
+  "Loops is: t = forever, nil = once, number = number of loops. Angle is an integer between 0-360. Volume is an integer between 0-255."
+  (let ((channel (pal-ffi:play-channel -1 (pal-ffi:sample-chunk sample) (cond
+                                                                          ((numberp loops)
+                                                                           loops)
+                                                                          ((eq t loops)
+                                                                           -1)
+                                                                          (t 0)))))
     (pal-ffi:set-position channel (truncate angle) (- 255 volume))
     channel))
 
@@ -720,15 +725,17 @@
 ;;; Music
 
 (defun load-music (file)
-  (pal-ffi:load-music (data-path file)))
+  (let ((music (pal-ffi:load-music (data-path file))))
+    (assert (not (cffi:null-pointer-p music)))
+    (let ((music (pal-ffi::make-music :music music)))
+      (pal-ffi:register-resource music))))
 
 (defun play-music (music &key (loops t) (volume 255))
   "Volume 0-255. Loops is: t = forever, nil = once, number = number of loops"
-  (let ((loops (truncate loops)))
-    (pal-ffi:volume-music (1+ (truncate volume 2)))
-    (pal-ffi:play-music (pal-ffi:music-music music) (cond ((eq loops t) -1)
-                                                          ((null loops) 0)
-                                                          (t loops)))))
+  (pal-ffi:volume-music (1+ (truncate volume 2)))
+  (pal-ffi:play-music (pal-ffi:music-music music) (cond ((eq loops t) -1)
+                                                        ((null loops) 0)
+                                                        (t (truncate loops)))))
 
 (defun set-music-volume (volume)
   "Volume 0-255"
--- /project/pal/cvsroot/pal/todo.txt	2007/07/21 16:34:16	1.13
+++ /project/pal/cvsroot/pal/todo.txt	2007/07/27 20:12:14	1.14
@@ -6,6 +6,9 @@
 
 - Image tiles and animation.
 
+- Add more complex sound/music handling functions, channel set volume/dir,
+  fade/etc. music.
+
 - Box/box/line/circle etc. overlap functions, faster v-dist.
 
 - Improved texture handling.




More information about the Pal-cvs mailing list