vydd / sketch

A Common Lisp framework for the creation of electronic art, visual design, game prototyping, game making, computer graphics, exploration of human-computer interaction, and more.
MIT License
1.4k stars 67 forks source link

Adds define-start-function #65

Closed Gleefre closed 1 year ago

Gleefre commented 1 year ago

After thinking about https://github.com/vydd/sketch/issues/58 I have come up with define-start-function which can be used like this:

(define-start-function start game (:resizable t :title "Sketchy game"))

Opening & closing other libraries (like sdl2-mixer):

(defmethod setup ((game game) &key &allow-other-keys)
  (sdl2-mixer:init-sound))

(defmethod kit.sdl2:close-window :before ((game game))
  (sdl2-mixer:quit-sound))

Under sbcl it can be saved to executable:

(defun)
(save-lisp-and-die "game.bin" :toplevel #'start :executable t)

Or it can be used with asdf:make (specify in asdf:defsystem). With deploy:

(asdf:defsystem "game"
  ; system definition
  :defsystem-depends-on (:deploy)
  :build-operation #-darwin "deploy-op" #+darwin "osx-app-deploy-op"
  :build-pathname "game"
  :entry-point "game:start")

Or without:

(asdf:defsystem "game"
  ; system definition
  :build-operation "program-op"
  :build-pathname "game"
  :entry-point "game:start")

And a simple build.lisp script:

(ql:quickload '(:deploy :game))
;; with `deploy`: it ships foreign dependencies, but you should not ship OpenGL
(deploy:define-library cl-opengl-bindings::opengl :dont-deploy t)
(asdf:make :game)
(quit)

I'm not sure that this is a flexible way to define start function: this macro doesn't have a body and naming is not good as well. Probably make-executable could be added.

Probable macro should be renamed: it shadows kit.sdl2:define-start-function right now.

Gleefre commented 1 year ago

I have added the possibility to use the function in a live image by passing optional parameter T. So now (start t) won't assume it is in the deployed environment, it won't run in the sdl's main thread e.t.c.

I can't think of any more improvements, so I'll make the pull request as ready.

Gleefre commented 1 year ago

I'll rewrite the define-start-function macro and will open a new PR.