Create do-sim function which integrates discrete and continuous processing broken up by external events
This commit is contained in:
parent
2ddec2370e
commit
7033ac5c9b
|
@ -19,8 +19,24 @@
|
|||
:image "res/man.png" :name :man})))
|
||||
:timestamp-last (u/timestamp)})
|
||||
|
||||
(defn update-gs [input]
|
||||
(let [man (first (gs/q :name :man))]
|
||||
(defn do-sim [gs tsstart tsend fntln fncontinuous fndiscrete]
|
||||
(gs/update-gs gs
|
||||
(loop [ts tsstart eventhandled false]
|
||||
(let [[tsev events] (-> (fntln) (subseq (if eventhandled > >=) ts) first)]
|
||||
(if (= tsev ts)
|
||||
(do
|
||||
(fndiscrete tsev events)
|
||||
(recur ts true))
|
||||
(if-not (= ts tsend)
|
||||
(let [tsstop (fncontinuous ts (or tsev tsend))]
|
||||
(recur tsstop false))))))))
|
||||
|
||||
(defn update-gs-from [tsstart tsend]
|
||||
tsend)
|
||||
|
||||
(defn update-gs-at [ts inputs]
|
||||
(let [input (last inputs)
|
||||
man (first (gs/q :name :man))]
|
||||
(gs/update-entity (assoc man :x (:mousex input) :y (:mousey input)))))
|
||||
|
||||
(defn render-gs [gs]
|
||||
|
@ -41,7 +57,7 @@
|
|||
screents (+ screentslast (- ts (:timestamp-last screen)))
|
||||
tln (:tln screen)
|
||||
gslast (tln/timeline-last-value tln)
|
||||
gsnext (gs/update-gs gslast (update-gs input))
|
||||
gsnext (do-sim gslast screentslast screents (fn [] inputtln) update-gs-from update-gs-at)
|
||||
tlnnext (tln/timeline-insert tln screents gsnext)
|
||||
screennext (assoc screen :timestamp-last ts :tln tlnnext)]
|
||||
(scr/update-screen screen screennext)))))
|
||||
|
|
Loading…
Reference in a new issue