mirror of
https://github.com/richardharrington/robotwar.git
synced 2024-05-28 23:41:31 +00:00
separated 'animate' into two namespaces: 'terminal' and 'browser'
This commit is contained in:
parent
2074f589a5
commit
b4b962096b
17
src/robotwar/browser.clj
Normal file
17
src/robotwar/browser.clj
Normal file
|
@ -0,0 +1,17 @@
|
|||
(ns robotwar.browser
|
||||
(:use [robotwar.constants]))
|
||||
|
||||
(defn worlds-for-browser
|
||||
"builds a sequence of worlds with the robots' brains
|
||||
removed, for more compact transmission by json.
|
||||
Fast-forward factor will be dynamically added by animation
|
||||
function in browser.
|
||||
TODO: remove some unnecessary robot fields if we need to
|
||||
for speed (we're going to keep them in now for diagnostic
|
||||
purposes in the browser)"
|
||||
[worlds]
|
||||
(map (fn [world]
|
||||
(assoc world :robots (mapv #(dissoc % :brain) (:robots world))))
|
||||
worlds))
|
||||
|
||||
|
|
@ -4,7 +4,8 @@
|
|||
[robotwar.world :as world]
|
||||
[robotwar.register :as register]
|
||||
[robotwar.robot :as robot]
|
||||
[robotwar.animate :as animate]))
|
||||
[robotwar.terminal :as terminal]
|
||||
[robotwar.browser :as browser]))
|
||||
|
||||
; this is a hacky place for messing with stuff.
|
||||
|
||||
|
@ -17,12 +18,12 @@
|
|||
(defn combined-worlds []
|
||||
(world/build-combined-worlds world))
|
||||
(defn worlds-for-terminal-display [fast-forward]
|
||||
(animate/worlds-for-terminal (combined-worlds) fast-forward))
|
||||
(terminal/worlds-for-terminal (combined-worlds) fast-forward))
|
||||
(defn make-it-so [fast-forward fps]
|
||||
(animate/animate (worlds-for-terminal-display fast-forward) 25 25 fps))
|
||||
(terminal/animate (worlds-for-terminal-display fast-forward) 25 25 fps))
|
||||
|
||||
(defn worlds-for-browser-display []
|
||||
(animate/worlds-for-browser (combined-worlds)))
|
||||
(browser/worlds-for-browser (combined-worlds)))
|
||||
|
||||
(def rr register/read-register)
|
||||
(def wr register/write-register)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
(ns robotwar.animate
|
||||
(ns robotwar.terminal
|
||||
(:use [clojure.string :only [join]]
|
||||
[clojure.pprint :only [pprint]]
|
||||
[robotwar.constants])
|
||||
|
@ -17,19 +17,6 @@
|
|||
:timestamp (int (* idx tick-duration 1000))}))
|
||||
worlds)))
|
||||
|
||||
(defn worlds-for-browser
|
||||
"builds a sequence of worlds with the robots' brains
|
||||
removed, for more compact transmission by json.
|
||||
Fast-forward factor will be dynamically added by animation
|
||||
function in browser.
|
||||
TODO: remove some unnecessary robot fields if we need to
|
||||
for speed (we're going to keep them in now for diagnostic
|
||||
purposes in the browser)"
|
||||
[worlds]
|
||||
(map (fn [world]
|
||||
(assoc world :robots (mapv #(dissoc % :brain) (:robots world))))
|
||||
worlds))
|
||||
|
||||
(defn near-point [[pos-x pos-y] [x y]]
|
||||
(and (= (int pos-x) x)
|
||||
(= (int pos-y) y)))
|
Loading…
Reference in New Issue
Block a user