ztellman / penumbra

not under active development - idiomatic opengl bindings for clojure
354 stars 43 forks source link

Update Loop #4

Closed elliottslaughter closed 15 years ago

elliottslaughter commented 15 years ago

Hi,

I've been looking at the code in window.clj and I'm wondering if you might be able to add a simple update loop. The only function you currently provide which gets called on a frequent basis is draw, and it would be nice if update could get called independently of the refresh rate (e.g. update at 60 fps but draw at 30 fps). And since you hide the state ref itself, it is difficult for me to set up my own independent update loop without modifying your code.

The following patch is an example of what I'm thinking of. Feel free to use it.

diff --git a/src/penumbra/window.clj b/src/penumbra/window.clj
index 18a5953..90234d0 100644
--- a/src/penumbra/window.clj
+++ b/src/penumbra/window.clj
@@ -129,4 +129,7 @@
                         (. frame dispose))) start))))
         (.add canvas)
         (.setSize 640 480)
-        (.show)))))
+        (.show))
+      (.start (new Thread #(while true
+                             (try-call canvas state fns :update)
+                             (. Thread sleep 20)))))))
elliottslaughter commented 15 years ago

Never mind, I just did another read through your code and found where you put the update function.

Still, it might be nice to keep seperate draw and update loop timings. (Not a high priority though.)

ztellman commented 15 years ago

It's a good idea, so I did it. See a demo at http://gist.github.com/188865