sand.flan takes the def/defonce split

The colours were the report: edited, re-evaluated, unchanged, because
defvar had said init-once and meant it. They are a def now, and so is
gravity, which is a number to turn while the sand falls, and game-data,
which is a file to edit and see re-read.

The grid, the velocity field and the arena stay defonce: they are what
the running game is, and a re-run that emptied them would be a restart
wearing a re-run's name. current-color is the same argument about a
smaller thing -- a brush you picked is a brush you keep.
This commit is contained in:
Joseph Ferano 2026-09-21 07:34:43 +07:00
parent 9cfe7e7218
commit 0a8dc1d82b

View File

@ -12,8 +12,8 @@
(defn dyn->f64 [v f64] f64 v) (defn dyn->f64 [v f64] f64 v)
(defn dyn->u32 [v i64] u32 (u32 v)) (defn dyn->u32 [v i64] u32 (u32 v))
(defvar gravity dyn 0.05) (def gravity dyn 0.05)
(defvar colors dyn (def colors dyn
(let [v (vec-new dyn)] (let [v (vec-new dyn)]
(push v 0xFFF00FFF) (push v 0xFFF00FFF)
(push v 0x3B6E8CFF) (push v 0x3B6E8CFF)
@ -21,9 +21,9 @@
(push v 0xCC6B1FFF) (push v 0xCC6B1FFF)
v)) v))
(defvar grid [rows [cols u32]]) (defonce grid [rows [cols u32]])
(defvar velocity [rows [cols f32]]) (defonce velocity [rows [cols f32]])
(defvar current-color dyn 0) (defonce current-color dyn 0)
(defn clear-grid [] () (defn clear-grid [] ()
(set grid (zeroed)) (set grid (zeroed))
@ -112,8 +112,8 @@
(rl/get-color c)))))) (rl/get-color c))))))
(rl/draw-fps 20 20)) (rl/draw-fps 20 20))
(defvar frame Allocator (arena-new 262144)) (defonce frame Allocator (arena-new 262144))
(defvar game-data dyn (def game-data dyn
(handler-case (edn/read-file "game-data.edn") (handler-case (edn/read-file "game-data.edn")
[(FileError [c] nil)])) [(FileError [c] nil)]))