Re: Hygenic approach for using Java2D from Clojure?
Here are some ideas I used in Indyvon (https://bitbucket.org/kryshen/ indyvon). * Methods that modify graphics context (java.awt.Graphics2D instance) are wrapped in with- macros, e.g. with-color sets the current color to the specified value, executes body in try block, and resets the color to the original value in the finally clause. * Graphics context is passed between rendering functions via thread- local bindings rather than an argument. * To be sure that some function will not leave the graphics context in a changed state a copy made using Graphics.create() could be passed instead of the original. * Rendering could be done in parallel using separate offscreen buffers for each thread. In Indyvon rendering is mainly done on the AWT event dispatching thread except parts of the scene wrapped in async-layer are rendered on separate threads. On the event dispatching thread the last finished rendering of async-layer is copied. Triple buffering is used to avoid locking. * Geometry objects (java.awt.geom) could be used locally as transients and converted to persistent structures upon returning. Another approach would be to create an object clone every time before doing modifications. -- Mikhail -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Hygenic approach for using Java2D from Clojure?
Hi, I'd like to use Java2D objects in a Clojure application. I understand that these mutable objects will be operating in a Clojure environment where immutability is the order of the day, and this is likely to cause problems. Can someone point me to some good examples of, or techniques for safely using mutable Java objects in Clojure--especially with Clojure parallel programming constructs in mind. Thanks in advance, Stu -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en