From 9912f264faa84c393abb3ee2beff814cb1609859 Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Sat, 6 Sep 2014 11:41:09 +0100 Subject: [PATCH] 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. --- src/mw_engine/drainage.clj | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/mw_engine/drainage.clj b/src/mw_engine/drainage.clj index e50f6ad..e8d5919 100644 --- a/src/mw_engine/drainage.clj +++ b/src/mw_engine/drainage.clj @@ -35,13 +35,14 @@ Flow comes from a higher cell to a lower only if the lower is the lowest neighbour of the higher." [world cell] (cond - (> (or (:altitude cell) 0) *sealevel*) + (not (nil? (:flow cell))) cell + (<= (or (:altitude cell) 0) *sealevel*) cell + true (merge cell {:flow (+ (:rainfall cell) (apply + (map (fn [neighbour] (:flow (flow world neighbour))) - (flow-contributors world cell))))}) - true cell)) + (flow-contributors world cell))))}))) (defn flow-world "Return a world like this `world`, but with cells tagged with the amount of