Working on getting drainage to actually work - which, inter alia, means
further work on efficiency.
This commit is contained in:
parent
dffa617a38
commit
42e6cfac05
|
@ -93,24 +93,6 @@
|
|||
* `generations` an (integer) number of generations.
|
||||
|
||||
Return the final generation of the world."
|
||||
[world init-rules rules generations]
|
||||
(let [state {:world (transform-world world init-rules) :rules rules}]
|
||||
(:world
|
||||
(last
|
||||
(doall
|
||||
(take generations
|
||||
(iterate transform-world-state state)))))))
|
||||
|
||||
(defn run-world2
|
||||
"Doesn't work yet"
|
||||
[world init-rules rules generations]
|
||||
(with-local-vars [r (ref (transform-world world init-rules))]
|
||||
(dotimes [g generations]
|
||||
(dosync
|
||||
(ref-set r (transform-world (deref r) rules))))
|
||||
(deref r)))
|
||||
|
||||
(defn run-world3
|
||||
[world init-rules rules generations]
|
||||
(reduce (fn [world _iteration]
|
||||
(transform-world world rules))
|
||||
|
|
|
@ -2,9 +2,13 @@
|
|||
;; assumed to have altitudes already set from a heighmap.
|
||||
|
||||
(ns mw-engine.drainage
|
||||
(:require
|
||||
[clojure.core.reducers :as r])
|
||||
(:use mw-engine.utils
|
||||
mw-engine.world))
|
||||
|
||||
(def ^:dynamic *sealevel* 10)
|
||||
|
||||
(defn rain-world
|
||||
"Simulate rainfall on this `world`. TODO: Doesn't really work just now - should
|
||||
rain more on west-facing slopes, and less to the east of high ground"
|
||||
|
@ -16,12 +20,13 @@
|
|||
`cell` and for which this cell is the lowest neighbour"
|
||||
[world cell]
|
||||
(remove nil?
|
||||
(map
|
||||
(into []
|
||||
(r/map
|
||||
(fn [n]
|
||||
(cond (= cell (get-least-cell (get-neighbours world n) :altitude)) n))
|
||||
(get-neighbours-with-property-value world (:x cell) (:y cell) 1
|
||||
:altitude
|
||||
(or (:altitude cell) 0) >))))
|
||||
(or (:altitude cell) 0) >)))))
|
||||
|
||||
(defn flow
|
||||
"Compute the total flow upstream of this `cell` in this `world`, and return a cell identical
|
||||
|
@ -29,11 +34,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*)
|
||||
(merge cell
|
||||
{:flow (+ (:rainfall cell)
|
||||
(apply +
|
||||
(map (fn [neighbour] (:flow (flow world neighbour)))
|
||||
(flow-contributors world cell))))}))
|
||||
(flow-contributors world cell))))})
|
||||
true cell))
|
||||
|
||||
(defn flow-world
|
||||
"Return a world like this `world`, but with cells tagged with the amount of
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
([world function]
|
||||
(map-world world function nil))
|
||||
([world function additional-args]
|
||||
(into [] ;; vectors are more efficient for scanning, which we do a lot.
|
||||
(into []
|
||||
(r/map (fn [row]
|
||||
(into [] (r/map
|
||||
#(apply function
|
||||
|
|
Loading…
Reference in a new issue