(in-package :uxul-world)
(defparameter *cfont* nil)
-(defparameter *zoomx* 1.0)
-(defparameter *zoomy* 1.0)
+(defvar *zoomx* 1.0)
+(defvar *zoomy* 1.0)
+(defvar *offset*)
+(defvar *ptr*)
(defun run-testing-room ()
(start-game :room-function #'make-testing-room))
(defun start-game (&key (music nil)
(room-function #'make-additional-testing-room)
(15-fps nil))
+ (declare (ignore music))
"Start the Game: Call room-function for getting the room-object to
run. Music is ignored so far. 15-fps makes only every second frame be
drawn (for very slow computers)"
(let ((*graphics-table* (make-hash-table :test #'equal))
(*spritesheet-id* (load-spritesheet))
+ (*buffer-id* (car (gl:gen-buffers 1)))
(*zoomx* (/ 1.0 +screen-width+))
- (*zoomxi* (/ .01 +screen-width+))
+ (zoomxi (/ .01 +screen-width+))
(*zoomy* (/ 1.0 +screen-height+))
- (*zoomyi* (/ .01 +screen-height+))
- (*zoom-ash* 0))
+ (zoomyi (/ .01 +screen-height+)))
(if 15-fps
(setf (sdl:frame-rate) 15)
(setf (sdl:frame-rate) 30))
((sdl:key= key :SDL-KEY-ESCAPE)
(sdl:push-quit-event))
((sdl:key= key :SDL-KEY-U)
- (incf *zoomx* *zoomxi*)
- (incf *zoomy* *zoomyi*))
+ (incf *zoomx* zoomxi)
+ (incf *zoomy* zoomyi))
((sdl:key= key :SDL-KEY-D)
- (decf *zoomx* *zoomxi*)
- (decf *zoomy* *zoomyi*))
+ (decf *zoomx* zoomxi)
+ (decf *zoomy* zoomyi))
(T
(on-key-down *current-room* key))))
(:mouse-button-down-event
(:button btn)
(cond
((= btn sdl:mouse-wheel-up)
- (incf *zoomx* *zoomxi*) (incf *zoomy* *zoomyi*))
+ (incf *zoomx* zoomxi) (incf *zoomy* zoomyi))
((= btn sdl:mouse-wheel-down)
- (decf *zoomx* *zoomxi*) (decf *zoomy* *zoomyi*))))
+ (decf *zoomx* zoomxi) (decf *zoomy* zoomyi))))
(:key-up-event (:key key)
(on-key-up *current-room* key))
(:idle
- (progn
(invoke *current-room*)
(when 15-fps
(invoke *current-room*))
+ (let ((float-size (cffi:foreign-type-size :float))
+ (obj-num 0))
+ (dolist (i (get-objects *current-room*
+ 'uxul-world::game-object))
+ (and (redraw i) (visible i) (incf obj-num)))
+
(gl:clear :color-buffer-bit :depth-buffer-bit)
- (gl:enable :texture-2d)
- (gl:enable :blend)
+ (gl:enable :texture-2d :blend)
(gl:blend-func :src-alpha :one-minus-src-alpha)
(gl:load-identity)
- (draw *current-room*)
+ (gl:bind-buffer :array-buffer *buffer-id*)
+ (%gl:buffer-data :array-buffer
+ (* float-size
+ 4 ; vertices per sprite
+ 4 ; components per vertice
+ obj-num)
+ (cffi:null-pointer) :stream-draw)
+ (gl:with-mapped-buffer
+ (p :array-buffer :write-only)
+ (let ((*ptr* p) (*offset* 0))
+ (draw *current-room*)))
+ (%gl:tex-coord-pointer 2 :float
+ (* 4 ; components per vertex
+ float-size)
+ (cffi:null-pointer))
+ (%gl:vertex-pointer 2 :float
+ (* 4 ; components per vertex
+ (cffi::foreign-type-size :float))
+ (cffi:make-pointer (* 2
+ float-size)))
+ (gl:enable-client-state :texture-coord-array)
+ (gl:enable-client-state :vertex-array)
+ (gl:bind-texture :texture-2d *spritesheet-id*)
+ (%gl:draw-arrays :quads 0 (* 4 obj-num))
+ (gl:disable-client-state :vertex-array)
+ (gl:disable-client-state :texture-coord-array)
(gl:flush)
+ (gl:bind-buffer :array-buffer 0)
(sdl:update-display)))))))
+
;; ;; For Debugging
;; (defun preview-animation (frameskip &rest images)
(destructuring-bind (x1 y1 x2 y2) imgs\r
(setf x (- x +screen-width+))\r
(setf y (- y +screen-height+))\r
- (gl:bind-texture :texture-2d *spritesheet-id*)\r
- (gl:with-primitive :quads\r
- (gl:tex-coord x1 y1) (gl:vertex x (+ y h))\r
- (gl:tex-coord x2 y1) (gl:vertex (+ x w) (+ y h))\r
- (gl:tex-coord x2 y2) (gl:vertex (+ x w) y)\r
- (gl:tex-coord x1 y2) (gl:vertex x y))))\r
-\r
+ ;(gl:bind-texture :texture-2d *spritesheet-id*)\r
+ (macrolet ((writedown (&rest vars)\r
+ `(progn\r
+ ,@(mapcar #'(lambda (var)\r
+ `(setf (cffi:mem-aref uxul-world::*ptr* :float (1- (incf uxul-world::*offset*))) (float ,var 0.0))) vars))))\r
+ (writedown x1 y1 x (+ y h)\r
+ x2 y1 (+ x w) (+ y h)\r
+ x2 y2 (+ x w) y\r
+ x1 y2 x y))))
\ No newline at end of file