Skip to content

Instantly share code, notes, and snippets.

@thomcc
Created March 25, 2012 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomcc/2200308 to your computer and use it in GitHub Desktop.
Save thomcc/2200308 to your computer and use it in GitHub Desktop.
slow rendering code
(defn draw [{{[px py :as pos] :pos h :health s :score sees :sees, lv :level :as play} :player,
{:keys [points width height monsters seen]} :level, msgs :messages}]
(set! (.-font ctx) "12px monospace")
(doto ctx (set-fill "black") (.fillRect 0 0 canv-width canv-height))
(let [mpts (set (map :pos monsters))]
(loop [yy (dec height)]
(when-not (neg? yy)
(loop [xx (dec width)]
(when-not (neg? xx)
(let [p [xx yy],
type (cond (= p pos) :player,
(mpts p) :monster
:else (points p)),
ch (char-rep type),
co (cond (not (seen p)) "black",
(not (sees p)) (mem-color-rep type),
:else (color-rep type))]
(doto ctx
(set-fill co)
(.fillText ch (* xx 11) (* yy 11)))
(recur (dec xx)))))
(recur (dec yy))))))
;; generated js:
dunjeon_cljs.client.main.draw = function(a) {
var b = cljs.core.truth_(cljs.core.seq_QMARK_.call(null, a)) ? cljs.core.apply.call(null, cljs.core.hash_map, a) : a, a = cljs.core.get.call(null, b, "\ufdd0'player"), c = cljs.core.truth_(cljs.core.seq_QMARK_.call(null, a)) ? cljs.core.apply.call(null, cljs.core.hash_map, a) : a, a = cljs.core.get.call(null, c, "\ufdd0'pos");
cljs.core.nth.call(null, a, 0, null);
cljs.core.nth.call(null, a, 1, null);
cljs.core.get.call(null, c, "\ufdd0'health");
cljs.core.get.call(null, c, "\ufdd0'score");
var d = cljs.core.get.call(null, c, "\ufdd0'sees");
cljs.core.get.call(null, c, "\ufdd0'level");
var c = cljs.core.get.call(null, b, "\ufdd0'level"), e = cljs.core.truth_(cljs.core.seq_QMARK_.call(null, c)) ? cljs.core.apply.call(null, cljs.core.hash_map, c) : c, c = cljs.core.get.call(null, e, "\ufdd0'seen"), f = cljs.core.get.call(null, e, "\ufdd0'monsters"), g = cljs.core.get.call(null, e, "\ufdd0'height"), h = cljs.core.get.call(null, e, "\ufdd0'width"), e = cljs.core.get.call(null, e, "\ufdd0'points");
cljs.core.get.call(null, b, "\ufdd0'messages");
dunjeon_cljs.client.main.ctx.font = "12px monospace";
b = dunjeon_cljs.client.main.ctx;
dunjeon_cljs.client.main.set_fill.call(null, b, "black");
b.fillRect(0, 0, dunjeon_cljs.client.main.canv_width, dunjeon_cljs.client.main.canv_height);
b = cljs.core.set.call(null, cljs.core.map.call(null, "\ufdd0'pos", f));
for(g -= 1;;) {
if(cljs.core.truth_(0 > g)) {
return null
}
for(f = h - 1;!cljs.core.truth_(0 > f);) {
var i = cljs.core.Vector.fromArray([f, g]), j = cljs.core.truth_(cljs.core._EQ_.call(null, i, a)) ? "\ufdd0'player" : cljs.core.truth_(b.call(null, i)) ? "\ufdd0'monster" : cljs.core.truth_("\ufdd0'else") ? e.call(null, i) : null, k = dunjeon_cljs.client.main.char_rep.call(null, j), i = cljs.core.truth_(cljs.core.not.call(null, c.call(null, i))) ? "black" : cljs.core.truth_(cljs.core.not.call(null, d.call(null, i))) ? dunjeon_cljs.client.main.mem_color_rep.call(null, j) : cljs.core.truth_("\ufdd0'else") ?
dunjeon_cljs.client.main.color_rep.call(null, j) : null, j = dunjeon_cljs.client.main.ctx;
dunjeon_cljs.client.main.set_fill.call(null, j, i);
j.fillText(k, 11 * f, 11 * g);
f -= 1
}
g -= 1
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment