comparison clojure/com/aurellem/gb_driver.clj @ 81:db8e0a563c8e

generated intro
author Robert McIntyre <rlm@mit.edu>
date Fri, 09 Mar 2012 01:43:25 -0600
parents 7ab48d728ee4
children 04d539d26bdc
comparison
equal deleted inserted replaced
80:ad6ebe886a21 81:db8e0a563c8e
4 (:import org.apache.commons.io.FileUtils) 4 (:import org.apache.commons.io.FileUtils)
5 (:import (java.nio IntBuffer ByteOrder))) 5 (:import (java.nio IntBuffer ByteOrder)))
6 6
7 (Gb/loadVBA) 7 (Gb/loadVBA)
8 8
9 (def ^:dynamic *max-history* 1e4) 9 (def ^:dynamic *max-history* 2e4)
10 10
11 (def ^:dynamic *backup-saves-to-disk* true) 11 (def ^:dynamic *backup-saves-to-disk* true)
12 12
13 (def ^:dynamic *save-history* true) 13 (def ^:dynamic *save-history* true)
14 14
134 134
135 (defn rewind 135 (defn rewind
136 ([] (rewind 1)) 136 ([] (rewind 1))
137 ([n] (goto (- @current-frame n)))) 137 ([n] (goto (- @current-frame n))))
138 138
139 (defn backup-state [frame] 139 (defn backup-state
140 [frame]
140 (let [save (save-state)] 141 (let [save (save-state)]
141 (swap! history #(assoc % frame save)) 142 (swap! history #(assoc % frame save))
142 (store-save-to-disk save) 143 ;;(store-save-to-disk save)
143 (if (> (count @history) *max-history*) 144 (if (> (count @history) *max-history*)
144 (swap! history #(dissoc % (first (first %))))))) 145 (swap! history #(dissoc % (first (first %)))))))
145 146
146 (defn advance [] 147 (defn advance []
147 (if *save-history* 148 (if *save-history*
154 (advance) 155 (advance)
155 (if (number? mask-or-buttons) 156 (if (number? mask-or-buttons)
156 (Gb/step mask-or-buttons) 157 (Gb/step mask-or-buttons)
157 (Gb/step (button-mask mask-or-buttons))))) 158 (Gb/step (button-mask mask-or-buttons)))))
158 159
160 (defn play-moves
161 ([start moves]
162 (goto start)
163 (dorun (map step moves)))
164 ([moves]
165 (dorun (map step moves))))
166
159 (defn play 167 (defn play
160 ([] (play Integer/MAX_VALUE)) 168 ([] (play Integer/MAX_VALUE))
161 ([n] (dorun (dotimes [_ n] (step))))) 169 ([n] (dorun (dotimes [_ n] (step)))))
162 170
163 (defmacro without-saves [& forms] 171 (defmacro without-saves [& forms]