oakes / play-clj

A Clojure game library
The Unlicense
939 stars 73 forks source link

Emacs workflow questions #56

Closed bobbywilson0 closed 9 years ago

bobbywilson0 commented 9 years ago

I have been using emacs messing around with play-clj, and a pretty basic question has come up. All do respect to the Nightmod and Nightcode editors, I am a bit more familiar with emacs and I feel like the answers to these questions may be useful to others as well.

When using cider repl and eval-ing (-main) it boots up the app, but I find that if I make a change, I don't know how to get that change to update in the launched app. If I eval (-main) in the cider repl again, I get an error. IllegalStateException Only one OpenAL context may be instantiated at any one time. org.lwjgl.openal.AL.create (AL.java:113), I have tried C-c C-k on both the desktop launcher and the src-common/hello_world/core.clj. This doesn't seem to update the app either.

oakes commented 9 years ago

Depending on what you're trying to reload, you may need to restart the game. You can do this by typing the following:

(on-gl (set-screen! hello-world main-screen))

Currently, due to how it is implemented, screen functions like :on-key-down that you add after starting your game will not be recognized until it is restarted using that command. Modifications to existing screen functions don't require this, however. Let me know if there are any other issues.

bobbywilson0 commented 9 years ago

Correct me if I am wrong. I have some code from the tutorial like so:

(defscreen main-screen
  :on-show
  (fn [screen entities]
    (update! screen :renderer (stage))
    (assoc (texture "Clojure-icon.gif")
      :x 150 :y 50 :width 100 :height 200))
...
)

if I change :width to 200, and run eval the following in cider: (on-gl (set-screen! hello-world main-screen)) it doesn't update. However, if I do something like (e! identity main-screen :width 200) it works exactly as I want. The trouble is that ideally I can update my application code and re-eval to get updates, without having to do an update via e! and then change my code, and eventually restart it. Any thoughts on other things to try? Thanks for the help!

oakes commented 9 years ago

Before calling set-screen!, did you reload your namespace?

bobbywilson0 commented 9 years ago
hello-world.core> (in-ns 'hello-world.core)
# Namespace hello-world.core 
hello-world.core> (on-gl (set-screen! hello-world main-screen))
nil

I am doing this, but yeah I don't see an update. Is there another way to reload the namespace that would be more appropriate?

oakes commented 9 years ago

Well in-ns is just switching to the namespace, not reloading it. I'm not sure how you reload a namespace with emacs, but in Nightcode there is a "Reload" button that does this.

bobbywilson0 commented 9 years ago

Ok, I think I have enough to consider this closed and be useful to someone else. In emacs, to update the code that is currently running, you need to run C-c C-k in the buffer that you are changing code, and then in your cider repl, (on-gl (set-screen! hello-world main-screen)) where "hello-world" is your namespace.