diff --git a/common/src/cljx/enoki/engine.cljx b/common/src/cljx/enoki/engine.cljx index 7eed37b..20568a9 100644 --- a/common/src/cljx/enoki/engine.cljx +++ b/common/src/cljx/enoki/engine.cljx @@ -12,29 +12,18 @@ ) (:require-macros [enoki.util.logging-macros :as log])) -(def get-display - "Function that returns the graphics display" - (atom nil)) - -(defn- init-platform-bindings! - "Populates the environment with various platform-specific functions." - [{:keys [display]}] - (log/info "Establishing platform-specific bindings") - (reset! get-display (constantly display))) - -(defn render [display state] - (-> (g/context display) +(defn render [ctx state] + (-> ctx (g/clear!) (g/draw-text! "Hello, world" 10 20))) -(defn tick [state] - (render (@get-display) state)) +(defn tick [{:keys [state display]}] + (render (g/context display) state)) (defn start "Enters the game loop. This function might return immediately or once the game loop is exited, depending on the implementation of loop-fn." - [env initial-state] - (init-platform-bindings! env) + [env] (log/info "Entering game loop") (let [loop-forever (:loop-fn env)] - (loop-forever tick initial-state))) + (loop-forever tick env))) diff --git a/swing/src/enoki/engine_impl.clj b/swing/src/enoki/engine_impl.clj index 3c36ad9..97c332b 100644 --- a/swing/src/enoki/engine_impl.clj +++ b/swing/src/enoki/engine_impl.clj @@ -3,7 +3,7 @@ (defn loop-forever "A naïve game loop implementation that sleeps for 1 millisecond between calls to `tick'." - [tick initial-state] - (loop [state initial-state] + [tick env] + (loop [env env] (Thread/sleep 1) - (recur (tick state)))) + (recur (tick env)))) diff --git a/swing/src/enoki/main.clj b/swing/src/enoki/main.clj index d9abe2d..a0e30a6 100644 --- a/swing/src/enoki/main.clj +++ b/swing/src/enoki/main.clj @@ -6,5 +6,5 @@ (defn start "Engine entry point" - [env initial-state] - (engine/start (assoc env :loop-fn impl/loop-forever) initial-state)) + [env] + (engine/start (assoc env :loop-fn impl/loop-forever))) diff --git a/swing/src/game/swing/main.clj b/swing/src/game/swing/main.clj index 5759a54..be0218d 100644 --- a/swing/src/game/swing/main.clj +++ b/swing/src/game/swing/main.clj @@ -17,8 +17,8 @@ (defn init [] (let [screen (create-screen)] (seesaw/invoke-now (seesaw/show! (create-frame screen))) - (enoki/start {:display (gfx/->JComponentDisplay screen)} - {}))) + (enoki/start {:display (gfx/->JComponentDisplay screen) + :state {}}))) (defn -main [& args] (init)) diff --git a/web/src/cljs/enoki/engine_impl.cljs b/web/src/cljs/enoki/engine_impl.cljs index 1a8f64d..b3fe7a0 100644 --- a/web/src/cljs/enoki/engine_impl.cljs +++ b/web/src/cljs/enoki/engine_impl.cljs @@ -1,5 +1,5 @@ (ns enoki.engine-impl (:require [goog.Timer :as timer])) -(defn loop-forever [tick state] - (timer/callOnce #(loop-forever tick (tick state)) 1)) +(defn loop-forever [tick env] + (timer/callOnce #(loop-forever tick (tick env)) 1)) diff --git a/web/src/cljs/enoki/main.cljs b/web/src/cljs/enoki/main.cljs index aa6b20a..efaa60e 100644 --- a/web/src/cljs/enoki/main.cljs +++ b/web/src/cljs/enoki/main.cljs @@ -8,8 +8,8 @@ (defn start "Engine entry point" - [env initial-state] + [env] (repl/connect "http://localhost:9000/repl") (logging/init!) (logging/set-level! :info) - (engine/start (assoc env :loop-fn impl/loop-forever) initial-state)) + (engine/start (assoc env :loop-fn impl/loop-forever))) diff --git a/web/src/cljs/game/web/main.cljs b/web/src/cljs/game/web/main.cljs index 30ed537..b2e468f 100644 --- a/web/src/cljs/game/web/main.cljs +++ b/web/src/cljs/game/web/main.cljs @@ -4,5 +4,5 @@ [enoki.util.dom :as dom])) (defn ^:export init [] - (enoki/start {:display (gfx/->CanvasDisplay (dom/get-element "screen"))} - {})) + (enoki/start {:display (gfx/->CanvasDisplay (dom/get-element "screen")) + :state {}}))