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

Commit

Permalink
Event-based rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
harto committed Jan 21, 2013
1 parent d7a9b27 commit 50cf428
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
11 changes: 4 additions & 7 deletions common/src/cljx/enoki/engine.cljx
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
;; Core engine functionality

^:clj (ns enoki.engine
(:require [enoki.graphics :as g]
(:require [enoki.event :as e]
[enoki.graphics :as g]
[enoki.util.logging] ; required for dependency resolution
[enoki.util.logging-macros :as log]
))

^:cljs (ns enoki.engine
(:require [goog.Timer :as timer]
[enoki.event :as e]
[enoki.graphics :as g]
[enoki.util.logging] ; required for dependency resolution
)
(:require-macros [enoki.util.logging-macros :as log]))

(defn render [ctx state]
(-> ctx
(g/clear!)
(g/draw-text! "Hello, world" 10 20)))

(defn update [state]
state)

(defn tick [{:keys [state display] :as env}]
(g/render display (fn [ctx] (render ctx state)))
(g/render display (fn [ctx] (e/broadcast :render state ctx)))
(assoc-in env [:state] (update state)))

;; Environment-specific loop functions
Expand Down
13 changes: 13 additions & 0 deletions common/src/cljx/game/main.cljx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(ns game.main
(:require [enoki.main :as enoki]
[enoki.event :as e]
[enoki.graphics :as g]))

(defn render [state ctx]
(-> ctx
(g/clear!)
(g/draw-text! "Hello again, world" 10 20)))

(defn start [env]
(e/subscribe! :render (fn [_ state ctx] (render state ctx)))
(enoki/start env))
7 changes: 3 additions & 4 deletions swing/src/game/swing/main.clj
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
(ns game.swing.main
(:require [enoki.main :as enoki]
(:require [game.main :as game]
[enoki.graphics.java2d :as gfx]))


(defn init []
(enoki/start {:display (gfx/create-display)
:state {}}))
(game/start {:display (gfx/create-display)
:state {}}))

(defn -main [& args]
(init))
6 changes: 3 additions & 3 deletions web/src/cljs/game/web/main.cljs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
(ns game.web.main
(:require [enoki.main :as enoki]
(:require [game.main :as game]
[enoki.graphics.canvas :as gfx]
[enoki.util.dom :as dom]))

(defn ^:export init []
(enoki/start {:display (gfx/->CanvasDisplay (dom/get-element "screen"))
:state {}}))
(game/start {:display (gfx/->CanvasDisplay (dom/get-element "screen"))
:state {}}))

0 comments on commit 50cf428

Please sign in to comment.