From 9f034400095966958802228cb115cf0edd7fa974 Mon Sep 17 00:00:00 2001 From: oakes Date: Sun, 25 May 2014 19:01:48 -0400 Subject: [PATCH] Clear the physics world during REPL development --- src/play_clj/core.clj | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/play_clj/core.clj b/src/play_clj/core.clj index 499c450..cd58ca3 100644 --- a/src/play_clj/core.clj +++ b/src/play_clj/core.clj @@ -82,6 +82,13 @@ :entities entities :options options :show (fn [] + ; if using a physics engine in a REPL, we need to forcibly remove + ; the entities and world so they are cleaned up properly + (when (:world @screen) + (update-screen! @screen (reset! entities [])) + (some-> @screen :world :object .dispose) + (update-fn! dissoc [:world])) + ; set the initial values in the screen map (update-fn! assoc [:total-time 0 :update-fn! update-fn! @@ -89,7 +96,9 @@ :on-timer on-timer :input-listeners (input-listeners options execute-fn!) :ui-listeners (ui-listeners options execute-fn!)]) + ; run :on-show (execute-fn! on-show) + ; update the physics contact listener if a :world was created (some->> (contact-listener @screen options execute-fn!) (vector :contact-listener) (update-fn! assoc)))