From a5aa5964cdb4b5a8311ef0614a4df9a7b65e151a Mon Sep 17 00:00:00 2001 From: Abhinav Sarkar Date: Wed, 25 Sep 2013 23:24:43 +0530 Subject: [PATCH] Fixed the issue with switching tab causing the ball to go out of boundaries --- resources/public/index.html | 15 ++++++++------- src/cljs/frpong/core.cljs | 25 +++++++++++++++++++------ src/cljs/frpong/helpers.cljs | 12 ++++++++++++ 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/resources/public/index.html b/resources/public/index.html index f5f239c..50ec202 100644 --- a/resources/public/index.html +++ b/resources/public/index.html @@ -8,13 +8,14 @@ -
FPS:
-
Position:
-
Velocity:
- - - - +
Frame:
+
FPS:
+
Position:
+
Velocity:
+ + + + diff --git a/src/cljs/frpong/core.cljs b/src/cljs/frpong/core.cljs index ad50067..4849ba5 100644 --- a/src/cljs/frpong/core.cljs +++ b/src/cljs/frpong/core.cljs @@ -1,5 +1,5 @@ (ns frpong.core - (:require [frpong.helpers :as h] + (:require [frpong.helpers :as h :refer [log]] [cljs.core.async :as async :refer [! chan put! close! sliding-buffer dropping-buffer timeout]] [domina :as dom :refer [log]] @@ -32,6 +32,16 @@ (defn abs [x] (.abs js/Math x)) +(defn tick-chan [frame-chan] + (let [c (chan)] + (go + (loop [prev (! c t)) + (recur t)))) + c)) + (defn positioner [tick-chan vel-chan pos-chan-in pos-chan-out] (go-loop (let [tick (! c (- ts start)) (recur ts))))) c)) + +(defn dropping-chan [source n] + (let [c (chan)] + (go + (loop [count 0] + (if (= count 0) + (>! c (