File tree 1 file changed +14
-12
lines changed
1 file changed +14
-12
lines changed Original file line number Diff line number Diff line change 297
297
(raf-step! c)
298
298
c))
299
299
300
+ (defonce tick-loop (atom nil ))
300
301
301
302
(defn start! []
302
303
(swap! app-state merge (make-game @app-state default-size ))
303
- (defonce tick-loop
304
- (go-loop [tick 0 ]
305
- (<! (timeout (:tick-ms @app-state)))
306
- (<! raf-chan)
307
- (let [app @app-state
308
- move-count (count (:moves app))
309
- tick (if (>= tick move-count) 0 tick)]
310
- (swap! app-state assoc :tick tick)
311
- (<! (paint-canvas! app tick))
312
- (if (or (zero? move-count) (= tick (dec move-count)))
313
- (recur 0 )
314
- (recur (inc tick)))))))
304
+ (when (nil? @tick-loop)
305
+ (reset! tick-loop
306
+ (go-loop [tick 0 ]
307
+ (<! (timeout (:tick-ms @app-state)))
308
+ (<! raf-chan)
309
+ (let [app @app-state
310
+ move-count (count (:moves app))
311
+ tick (if (>= tick move-count) 0 tick)]
312
+ (swap! app-state assoc :tick tick)
313
+ (<! (paint-canvas! app tick))
314
+ (if (or (zero? move-count) (= tick (dec move-count)))
315
+ (recur 0 )
316
+ (recur (inc tick))))))))
315
317
316
318
317
319
(defn get-camera! [skip-howto?]
You can’t perform that action at this time.
0 commit comments