Skip to content
This repository has been archived by the owner on Jun 17, 2020. It is now read-only.

Commit

Permalink
Inline loop functions
Browse files Browse the repository at this point in the history
  • Loading branch information
harto committed Jan 21, 2013
1 parent 954105d commit d7a9b27
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 22 deletions.
18 changes: 15 additions & 3 deletions common/src/cljx/enoki/engine.cljx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
))

^:cljs (ns enoki.engine
(:require [enoki.graphics :as g]
(:require [goog.Timer :as timer]
[enoki.graphics :as g]
[enoki.util.logging] ; required for dependency resolution
)
(:require-macros [enoki.util.logging-macros :as log]))
Expand All @@ -24,11 +25,22 @@
(g/render display (fn [ctx] (render ctx state)))
(assoc-in env [:state] (update state)))

;; Environment-specific loop functions

(defn ^:clj loop-forever
"A naïve game loop implementation that calls `tick' as often as possible."
[tick env]
(loop [env env]
(Thread/sleep 1)
(recur (tick env))))

(defn ^:cljs loop-forever [tick env]
(timer/callOnce #(loop-forever tick (tick env)) 1))

(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]
(g/init-display! (:display env))
(log/info "Entering game loop")
(let [loop-forever (:loop-fn env)]
(loop-forever tick env)))
(loop-forever tick env))
9 changes: 0 additions & 9 deletions swing/src/enoki/engine_impl.clj

This file was deleted.

5 changes: 2 additions & 3 deletions swing/src/enoki/main.clj
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
;; Engine entry point for game implementations.

(ns enoki.main
(:require [enoki.engine :as engine]
[enoki.engine-impl :as impl]))
(:require [enoki.engine :as engine]))

(defn start
"Engine entry point"
[env]
(engine/start (assoc env :loop-fn impl/loop-forever)))
(engine/start env))
5 changes: 0 additions & 5 deletions web/src/cljs/enoki/engine_impl.cljs

This file was deleted.

3 changes: 1 addition & 2 deletions web/src/cljs/enoki/main.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
(ns enoki.main
(:require [clojure.browser.repl :as repl]
[enoki.engine :as engine]
[enoki.engine-impl :as impl]
[enoki.util.logging :as logging]))

(defn start
Expand All @@ -12,4 +11,4 @@
(repl/connect "http://localhost:9000/repl")
(logging/init!)
(logging/set-level! :info)
(engine/start (assoc env :loop-fn impl/loop-forever)))
(engine/start env))

0 comments on commit d7a9b27

Please sign in to comment.