On 04/01/2008, Luke J Crook <[EMAIL PROTECTED]> wrote:
> Elliott Slaughter wrote:

Cool.

As it happens I've been playing with lispbuilder-sdl writing a
component based engine. The main loop is pretty simple, it just
updates a list of active objects. Each object has a set of components.
One controls animation and drawing, another is physics movement and
collision, a third is the AI or player controls and logic for each
entity.

What's nice is you can stop the game, add or remove objects and so on,
and then restart the engine. When I'm using lispworks I can do that
without stopping the engine using the repl in lispworks and starting
the engine in emacs. Presumably theres some way to do that in slime
and have to repl's on the same lisp?

I'm currently making a pong type game and I aim to make that part of a
tutorial on using lispbuilder-sdl for dynamic game programming.

The code is at
http://code.google.com/p/lisp-game-engine/

but it's not really documented or finished yet.

-- from dgp.lisp

(defun engine-init()
  "sets up the game engine and returns"
  (if *engine-active*
      (error "engine-init was already called"))
  (sdl:init-sdl)
  (sdl:init-sub-systems)
  (setf (sdl:frame-rate) 60) ; Set target framerate (or 0 for unlimited)
  ;;; TODO handle full screen here
  (sdl:window *WINDOW-WIDTH* *WINDOW-HEIGHT* :title-caption "Game
engine" :icon-caption "Game engine")
  ;;; init other stuff we want available
  (sdl:initialise-default-font)
  (setf (sdl:frame-rate) 60) ; Set target framerate (or 0 for unlimited)
  (setf *engine-active* t))

(defun engine-quit()
  "shut sdl down and clean up everything that engine-init did"
  (if (null *engine-active*)
      (error "engine-init was not called"))
  (sprites:flush-image-cache)
  (setf *active-game-objects* nil) ; free all game objects to the
garbage collector
  (sdl:quit-sub-systems)
  (sdl:quit-sdl)
  (setf *engine-active* nil))

(defun engine-run()
  "The main game engine loop, it updates objects then draws them"
  (if (null *engine-active*)
      (error "engine-init was not called"))
  (sdl:with-events  ()
    (:quit-event () t)

;;; I've cut out the keyboard handling here for clarity

    (:idle () ;; redraw screen on idle
           ;; fill the background
           (sdl:clear-display *BG-COLOR*)

           ;; Do stuff here!

           (show-frame-rate)
           ;; Update the whole screen
           (sdl:update-display))))


So basically a typical session looks like this

(engine-init)

add some objects the the active object list

(engine-run)

starts the game going (press escape to get back to the repl)

rewrite some code, add or remove objects and so on

(engine-run)

Until you want to clean up everything

(engine-quit)

It would be fairly easy I think to add a REPL to main game screen
using our font stuff if that would be useful. It would be pretty handy
for full screen debugging.

Justin Heyes-Jones
_______________________________________________
application-builder mailing list
application-builder@lispniks.com
http://www.lispniks.com/mailman/listinfo/application-builder

Reply via email to