Some tentative attempts at optimisation. This, actually, makes no

difference in itself - because the world is immutable, this change
won't work without a different mechanism for generating the world
itself.
This commit is contained in:
Simon Brooke 2014-09-06 11:41:09 +01:00
parent 42e6cfac05
commit 9912f264fa

View file

@ -35,13 +35,14 @@
Flow comes from a higher cell to a lower only if the lower is the lowest neighbour of the higher." Flow comes from a higher cell to a lower only if the lower is the lowest neighbour of the higher."
[world cell] [world cell]
(cond (cond
(> (or (:altitude cell) 0) *sealevel*) (not (nil? (:flow cell))) cell
(<= (or (:altitude cell) 0) *sealevel*) cell
true
(merge cell (merge cell
{:flow (+ (:rainfall cell) {:flow (+ (:rainfall cell)
(apply + (apply +
(map (fn [neighbour] (:flow (flow world neighbour))) (map (fn [neighbour] (:flow (flow world neighbour)))
(flow-contributors world cell))))}) (flow-contributors world cell))))})))
true cell))
(defn flow-world (defn flow-world
"Return a world like this `world`, but with cells tagged with the amount of "Return a world like this `world`, but with cells tagged with the amount of