Skip to content

Commit

Permalink
foo
Browse files Browse the repository at this point in the history
  • Loading branch information
David O'Toole committed Mar 8, 2010
1 parent 1e55034 commit 58ffabb
Show file tree
Hide file tree
Showing 49 changed files with 1,128 additions and 64 deletions.
96 changes: 81 additions & 15 deletions console.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ disabled."
"Generate an all-purpose sequence number."
(+ x (incf *sequence-number*)))

;;; Physics timestep callback

;; These must be set before initialization.

(defvar *dt* 10)

(defvar *physics-function* nil)

;;; Mixer channels

(defvar *channels* 64 "Number of audio mixer channels to use.")
Expand Down Expand Up @@ -129,7 +137,7 @@ and the like."
;; TODO why does this crash:
;; (show-widgets))

;;; Key repeat
;;; Key repeat emulation

(defvar *key-table* (make-hash-table :test 'equal))

Expand Down Expand Up @@ -534,12 +542,15 @@ window. Set this in the game startup file.")
"Initialize the console, open a window, and play.
We want to process all inputs, update the game state, then update the
display."
(if *fullscreen*
(sdl:window *screen-width* *screen-height*
:title-caption *window-title*
:flags sdl:SDL-FULLSCREEN)
(sdl:window *screen-width* *screen-height*
:title-caption *window-title*))
(let ((fps (make-instance 'sdl:fps-unlocked :dt *dt* :ps-fn *physics-function*)))
(if *fullscreen*
(sdl:window *screen-width* *screen-height*
:fps fps
:title-caption *window-title*
:flags sdl:SDL-FULLSCREEN)
(sdl:window *screen-width* *screen-height*
:fps fps
:title-caption *window-title*)))
(reset-joystick)
(sdl:clear-display sdl:*black*)
(show-widgets)
Expand Down Expand Up @@ -606,12 +617,12 @@ display."
(setf (gethash event *key-table*) -1)))
(break-events event)))))
(:idle ()
(when *timer-p*
(if *timer-p*
(if (zerop *clock*)
(progn
(sdl:clear-display sdl:*black*)
;; send held events
(when *held-keys*
(when *held-keys*
(send-held-events))
;; send timer event
(dispatch-event *timer-event*)
Expand All @@ -622,7 +633,15 @@ display."
(show-widgets)
(sdl:update-display)
(setf *clock* *timer-interval*))
(decf *clock*)))))))
(decf *clock*))
;; clean this up. these two cases aren't that different.
(progn
(sdl:clear-display sdl:*black*)
(when *held-keys*
(send-held-events))
(show-widgets)
(sdl:update-display)))))))


;;; The .xe2rc user init file

Expand Down Expand Up @@ -1273,6 +1292,52 @@ The default destination is the main window."
(sdl:draw-rectangle-* x y width height :color (find-resource-object color)
:surface destination))

;;; Audio

(defvar *frequency* 44100)

(defvar *output-chunksize* 128)

(defvar *output-channels* 2)

(defvar *sample-format* SDL-CFFI::AUDIO-S16LSB)

(defun cffi-sample-type (sdl-sample-type)
(ecase sdl-sample-type
(SDL-CFFI::AUDIO-U8 :uint8) ; Unsigned 8-bit samples
(SDL-CFFI::AUDIO-S8 :int8) ; Signed 8-bit samples
(SDL-CFFI::AUDIO-U16LSB :uint16) ; Unsigned 16-bit samples, in little-endian byte order
(SDL-CFFI::AUDIO-S16LSB :int16) ; Signed 16-bit samples, in little-endian byte order
;; (SDL-CFFI::AUDIO-U16MSB nil) ; Unsigned 16-bit samples, in big-endian byte order
;; (SDL-CFFI::AUDIO-S16MSB nil) ; Signed 16-bit samples, in big-endian byte order
(SDL-CFFI::AUDIO-U16 :uint16) ; same as SDL(SDL-CFFI::AUDIO-U16LSB (for backwards compatability probably)
(SDL-CFFI::AUDIO-S16 :int16) ; same as SDL(SDL-CFFI::AUDIO-S16LSB (for backwards compatability probably)
(SDL-CFFI::AUDIO-U16SYS :uint16) ; Unsigned 16-bit samples, in system byte order
(SDL-CFFI::AUDIO-S16SYS :int16) ; Signed 16-bit samples, in system byte order
))

(defun cffi-chunk-buffer (chunk)
(sdl:fp chunk))

(defun convert-cffi-sample (chunk)
(let* ((input-buffer (cffi-chunk-buffer chunk))
(type (cffi-sample-type *sample-format*))
(size (length (cffi:mem-ref input-buffer type))))
(assert (eq *sample-format* SDL-CFFI::AUDIO-S16LSB)) ;; for now
(let ((output-buffer (make-array size)))
(prog1 output-buffer
(dotimes (n size)
(setf (aref output-buffer n)
(/ (float (cffi:mem-aref input-buffer type n))
32768.0)))))))

;(defun convert-internal-audio (input-buffer output-stream)

;; (REGISTER-MUSIC-MIXER
;; (lambda (user stream len)
;; 'FILL-THE-AUDIO-OUTPUT-BUFFER))


;;; Engine status

(defun quit (&optional shutdown)
Expand All @@ -1286,11 +1351,9 @@ The default destination is the main window."
(setf *next-module* module-name)
(sdl:push-quit-event))

(defparameter *audio-chunksize* 512)

(defvar *copyright-text*
"XE2 Game Engine
Copyright (C) 2006, 2007, 2008, 2009 David O'Toole
Copyright (C) 2006, 2007, 2008, 2009, 2010 David O'Toole
<[email protected]>
This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -1334,7 +1397,7 @@ and its .startup resource is loaded."
(loop while (and (not *quitting*)
*next-module*)
do (unwind-protect
;; dynamically load libs (needed for GNU/Linux)
;; dynamically load libs (needed for GNU/Lpinux)
(progn (cffi:define-foreign-library sdl
(:darwin (:or (:framework "SDL")
(:default "libSDL")))
Expand Down Expand Up @@ -1385,7 +1448,10 @@ and its .startup resource is loaded."
(initialize-colors)
(when *use-sound*
;; try opening sound
(when (null (sdl-mixer:open-audio :chunksize *audio-chunksize*))
(when (null (sdl-mixer:open-audio :frequency *frequency*
:chunksize *output-chunksize*
:format *sample-format*
:channels *output-channels*))
;; if that didn't work, disable effects/music
(message "Could not open audio driver. Disabling sound effects and music.")
(setf *use-sound* nil))
Expand Down
37 changes: 37 additions & 0 deletions drez/drez.lisp
Original file line number Diff line number Diff line change
@@ -1 +1,38 @@
;;; drez.lisp --- 7DRL

;; Copyright (C) 2010 David O'Toole

;; Author: David O'Toole <[email protected]>
;; Keywords:

;; 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/>.

;;; Commentary:

;;

;;; Code:

(defpackage :drez
(:documentation "dRez is a hybrid dance engine game in Common Lisp.")
(:use :xe2 :common-lisp)
(:export drez))

(in-package :drez)




;;; drez.lisp ends here

35 changes: 26 additions & 9 deletions drez/drez.org
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,26 @@

DEE-rezz

* Links
* Tasks

** TODO review luke's mixer.lisp
** TODO create standard variables for sdl-mixer output format configuration
*** TODO frequency
** TODO convert SDL sample buffers into internal format
*** TODO (sdl:fp chunk) gets the buffer pointer from a chunk loaded with load-sample
*** TODO http://common-lisp.net/project/cffi/manual/cffi-manual.html#Accessing-Foreign-Memory
*** http://common-lisp.net/project/cffi/manual/cffi-manual.html#Built_002dIn-Types
*** TODO http://lispbuilder.sourceforge.net/lispbuilder-sdl-mixer.html#+default-format+
** TODO convert internal format to SDL output stream, see also register-mixer or whatever http://lispbuilder.sourceforge.net/lispbuilder-sdl-mixer.html#register-music-mixer
** TODO resampler http://en.wikipedia.org/wiki/Interpolation

** TODO Read "Fix your timestep" article
** TODO Decouple physics from framerate: http://code.google.com/p/lispbuilder/wiki/UsingLispbuilderSDL#Frame_Rate_and_Timestep
** TODO Find/create bd, snare, hihat samples
** TODO Code event/sequencer basics
** DONE Decouple physics from framerate: http://code.google.com/p/lispbuilder/wiki/UsingLispbuilderSDL#Frame_Rate_and_Timestep
CLOSED: [2010-02-22 Mon 11:55]
** TODO Find/create bd, snare, hihat samples
** TODO Basic UI/button config
** TODO Design blocky font
** TODO Add scalable font support

* Thoughts

Expand All @@ -29,13 +42,17 @@
** Piano roll edit ui
** simfiles ideas, i.e. beats plus freestyling game

* Tasks
* Music representation

** TODO Reexamine old music code.... ligeti, ecaspace
** TODO Decide on music event data format, simple hierarchical OSC-ish namespace?
** TODO Find some external programs to create and process basic samples.
** Mixing

- (sdl:fp chunk) gets the buffer pointer from a chunk loaded with load-sample
- http://lispbuilder.sourceforge.net/lispbuilder-sdl-mixer.html#register-music-mixer

** Timing
- ticks
- beats per minute

* Music representation
** Events
*** One possibility: (start-time &rest p-fields)
*** Another: (integer-tick type &rest p-fields)
Expand Down
2 changes: 1 addition & 1 deletion forest/base.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
(add-hook 'xe2:*initialization-hook*
#'(lambda ()
(xe2:enable-timer)
(xe2:set-frame-rate 15)
(xe2:set-frame-rate 10)
(xe2:set-timer-interval 0)
(xe2:enable-held-keys 1 3)))

Expand Down
2 changes: 1 addition & 1 deletion void/void.pak
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@

(:name "black-thunder" :type :music :file "black0999.ogg" :properties (:volume 18))

(:name "blast-lisp" :type :lisp :file "blast.lisp" :properties (:autoload t))
(:name "void-lisp" :type :lisp :file "void.lisp" :properties (:autoload t))
(:name "effect-lisp" :type :lisp :file "effect.lisp" :properties (:autoload t))
(:name "terrain-lisp" :type :lisp :file "terrain.lisp" :properties (:autoload t))
(:name "sector-lisp" :type :lisp :file "sector.lisp" :properties (:autoload t))
Expand Down
77 changes: 39 additions & 38 deletions xe2.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -61,44 +61,45 @@
(:nicknames :xe2)
(:use :common-lisp :clon)
(:export *default-frame-width* *default-frame-height* =viewport=
=equipment= *default-world-axis-size* *default-world-z-size*
=browser= install-widgets *initialization-hook* initialize-engine
split-string-on-lines message *screen-width* transform-method-body
roll-under make-stat =formatter= initialize-colors
*standard-categories* *default-action-points* =world= roll
bind-key-to-method *colors* get-color =prompt= =menu-item=
=direction-chooser= define-method *default-font* *startup*
field-value set-field-value object-fields dispatch-event run
*user-init-file-name* distance icon-resource icon-image
*compass-directions* *compass-opposites* find-resource-property
compose-blank-fields font-width font-height *browser* browser
set-browser transform-field-reference *screen-height* =inventory=
formatted-line-width formatted-line-height formatted-string-height
formatted-string-width get-color create-image draw-image play
define-prototype has-field defcell *choose-direction-menu*
set-field-options field-option-value index-resource find-module-path
index-module load-image-resource load-lisp-resource *executable*
*resource-handlers* load-resource find-resource find-resource-object
*colors* *world* load-user-init-file *module-directories*
resource-to-plist make-event =widget= *active-widgets*
bind-key-to-prompt-insertion make-field-initializer clone
make-field-initializer-body make-key-modifier-symbol make-key-string
normalize-event make-keyword make-object queue-head queue-max
queue-count *sender* make-special-variable-name field-reference-p
null-parent *message-send-symbol-suffix* *x11-color-data*
object-name object-parent send send-super send-queue self
opposite-direction object-address-string object step-in-direction
direction-to =cell= plasma-rect subdivide-rect render-plasma
add-hook run-hook queue-tail make-queue queue unqueue queue-message
queued-messages-p unqueue-message send-queue field-value
random-direction load-font-resource draw-string-solid read-pak
*resource-table* initialize-resource-table percent-of-time
render-formatted-paragraph make-formatted-string draw-string-shaded
render-formatted-string render-formatted-line resource
font-text-extents write-sexp-to-file with-message-sender
*message-sender* =textbox= read-sexp-from-file write-pak *grammar*
one-of left-hand-side right-hand-side expansions generate
send-event-to-widgets play-music halt-music seek-music
*frequency* *output-chunksize* *output-channels*
*dt* *physics-function* =equipment= *default-world-axis-size*
*default-world-z-size* =browser= install-widgets
*initialization-hook* initialize-engine split-string-on-lines
message *screen-width* transform-method-body roll-under make-stat
=formatter= initialize-colors *standard-categories*
*default-action-points* =world= roll bind-key-to-method *colors*
get-color =prompt= =menu-item= =direction-chooser= define-method
*default-font* *startup* field-value set-field-value object-fields
dispatch-event run *user-init-file-name* distance icon-resource
icon-image *compass-directions* *compass-opposites*
find-resource-property compose-blank-fields font-width font-height
*browser* browser set-browser transform-field-reference
*screen-height* =inventory= formatted-line-width
formatted-line-height formatted-string-height formatted-string-width
get-color create-image draw-image play define-prototype has-field
defcell *choose-direction-menu* set-field-options field-option-value
index-resource find-module-path index-module load-image-resource
load-lisp-resource *executable* *resource-handlers* load-resource
find-resource find-resource-object *colors* *world*
load-user-init-file *module-directories* resource-to-plist
make-event =widget= *active-widgets* bind-key-to-prompt-insertion
make-field-initializer clone make-field-initializer-body
make-key-modifier-symbol make-key-string normalize-event
make-keyword make-object queue-head queue-max queue-count *sender*
make-special-variable-name field-reference-p null-parent
*message-send-symbol-suffix* *x11-color-data* object-name
object-parent send send-super send-queue self opposite-direction
object-address-string object step-in-direction direction-to =cell=
plasma-rect subdivide-rect render-plasma add-hook run-hook
queue-tail make-queue queue unqueue queue-message queued-messages-p
unqueue-message send-queue field-value random-direction
load-font-resource draw-string-solid read-pak *resource-table*
initialize-resource-table percent-of-time render-formatted-paragraph
make-formatted-string draw-string-shaded render-formatted-string
render-formatted-line resource font-text-extents write-sexp-to-file
with-message-sender *message-sender* =textbox= read-sexp-from-file
write-pak *grammar* one-of left-hand-side right-hand-side expansions
generate send-event-to-widgets play-music halt-music seek-music
*joystick-mapping* *generic-joystick-mapping* *ps3-joystick-mapping*
draw-resource-image *event-handler-function* *use-sound*
trace-rectangle trace-row trace-column trace-octagon trace-line
Expand Down
Binary file modified xiobreak/xiobreak.xcf
Binary file not shown.
Loading

0 comments on commit 58ffabb

Please sign in to comment.