Sunday, 15 January 2012

opengl - Clojure editing code while running split into different files -



opengl - Clojure editing code while running split into different files -

i've been trying test opengl in clojure lwjgl library. started off code:

(ns test.core (:import [org.lwjgl.opengl display displaymode gl11])) (defn init-window [width height title] (display/setdisplaymode (displaymode. width height)) (display/settitle title) (display/create)) (defn update [] (gl11/glclearcolor 0 0 0 0) (gl11/glclear gl11/gl_color_buffer_bit)) (defn run [] (init-window 800 600 "test") (while (not (display/iscloserequested)) (update) (display/update)) (display/destroy)) (defn -main [& args] (.start (thread. run)))

this worked in emacs, nrepl plugin, start , while running alter (eg phone call glclearcolor).

i decided split 2 seperate files, reuse init-window function :

(ns copengl.core (:import [org.lwjgl.opengl display displaymode gl11])) (defn init-window [width height title] (display/setdisplaymode (displaymode. width height)) (display/settitle title) (display/create)) (defn mainloop [{:keys [update-fn]}] (while (not (display/iscloserequested)) (update-fn) (display/update)) (display/destroy)) (defn run [data] (init-window (:width data) (:height data) (:title data)) (mainloop data)) (defn start [data] (.start (thread. (partial run data))))

and in seperate file

(ns test.core (:import [org.lwjgl.opengl display displaymode gl11]) (:require [copengl.core :as starter])) (def -main [& args] (starter/start {:width 800 :height 600 :title "test" :update-fn update})

this, however, not allow me alter while running. have close window execute -main 1 time again see change.

so far have tried putting these lastly 2 excerpts of code 1 file did not work. however, if alter phone call update-fn name of update function (update) when in same file alter things while running.

i'm guessing because when create map update function in passes actual function , if redefine update using nrepl plugin evaluate there no effect because mainloop function using function - not looking symbol update , using that.

is there way have code split between 2 files whilst still beingness able alter code while running?

pass var update instead of function contained in var update putting #' in front end of var name. cause contents of update function looked in var every time called.

(def -main [& args] (starter/start {:width 800 :height 600 :title "test" :update-fn #'update})

this has slight cost performance why not default though it's useful in cases , cost slight.

opengl emacs clojure lwjgl nrepl

No comments:

Post a Comment