hopefully made math faster.
This commit is contained in:
@@ -1,19 +1,22 @@
|
|||||||
(ns advent.tween)
|
(ns advent.tween)
|
||||||
|
|
||||||
(defn ease-in-expo [power t start delta duration]
|
(set! *unchecked-math* :warn-on-boxed)
|
||||||
(let [pct-done (/ t duration)
|
|
||||||
|
(defn ease-in-expo-maker [^double power ]
|
||||||
|
(fn ^double [^double t ^double start ^double delta ^double duration]
|
||||||
|
(let [pct-done (/ t duration)
|
||||||
pct-done (Math/pow pct-done power)]
|
pct-done (Math/pow pct-done power)]
|
||||||
(+ start
|
(+ start
|
||||||
(* delta pct-done))))
|
(* delta pct-done)))))
|
||||||
|
|
||||||
(def ease-linear (partial ease-in-expo 1.0))
|
(def ease-linear (ease-in-expo-maker 1.0))
|
||||||
(def ease-in-quadratic (partial ease-in-expo 2.0))
|
(def ease-in-quadratic (ease-in-expo-maker 2.0))
|
||||||
(def ease-in-cubic (partial ease-in-expo 3.0))
|
(def ease-in-cubic (ease-in-expo-maker 3.0))
|
||||||
(def ease-in-quartic (partial ease-in-expo 4.0))
|
(def ease-in-quartic (ease-in-expo-maker 4.0))
|
||||||
(def ease-in-quintic (partial ease-in-expo 5.0))
|
(def ease-in-quintic (ease-in-expo-maker 5.0))
|
||||||
(def ease-in-dectic (partial ease-in-expo 10.0))
|
(def ease-in-dectic (ease-in-expo-maker 10.0))
|
||||||
|
|
||||||
(defn ease-in-out-quadratic [t start delta duration]
|
(defn ease-in-out-quadratic [^double t ^double start ^double delta ^double duration]
|
||||||
(let [t (/ t (/ duration 2))]
|
(let [t (/ t (/ duration 2))]
|
||||||
(if (< t 1)
|
(if (< t 1)
|
||||||
(+ (* (/ delta 2)
|
(+ (* (/ delta 2)
|
||||||
@@ -25,27 +28,28 @@
|
|||||||
start)))))
|
start)))))
|
||||||
|
|
||||||
(defn ease-in-out-quintic ^double [^double t ^double start ^double delta ^double duration]
|
(defn ease-in-out-quintic ^double [^double t ^double start ^double delta ^double duration]
|
||||||
(binding [*unchecked-math* true]
|
(let [t (/ t (/ duration (double 2.0)))]
|
||||||
(let [t (/ t (/ duration (double 2.0)))]
|
(if (< t (double 1))
|
||||||
(if (< t (double 1))
|
(let [result (+ (* (/ delta (double 2.0))
|
||||||
(let [result (+ (* (/ delta (double 2.0))
|
t t t t t) start)]
|
||||||
t t t t t) start)]
|
result)
|
||||||
result)
|
|
||||||
|
|
||||||
(let [t (- t (double 2.0))
|
(let [t (- t (double 2.0))
|
||||||
result (+ (* (/ (- delta) (double 2.0))
|
result (+ (* (/ (- delta) (double 2.0))
|
||||||
(- (* t t t t) (double 2.0)))
|
(- (* t t t t) (double 2.0)))
|
||||||
start)]
|
start)]
|
||||||
result
|
result))))
|
||||||
)))))
|
|
||||||
|
|
||||||
(defn ease-out-quadratic [t start delta duration]
|
(defn ease-out-quadratic ^double [^double t ^double start ^double delta ^double duration]
|
||||||
(let [t (/ t duration)]
|
(let [t (/ t duration)]
|
||||||
(+ (* (- delta) t (- t 2)) start)))
|
(unchecked-add (-> (unchecked-subtract 1 delta)
|
||||||
|
(unchecked-multiply t)
|
||||||
|
(unchecked-multiply (unchecked-subtract t 2)))
|
||||||
|
start)))
|
||||||
|
|
||||||
(defn ease-out-cubic [t start delta duration]
|
(defn ease-out-cubic ^double [^double t ^double start ^double delta ^double duration]
|
||||||
(let [t (dec (/ t duration))]
|
(let [t (unchecked-subtract (/ t duration) 1)]
|
||||||
(+ (* delta (inc (* t t t))) start)))
|
(unchecked-add (unchecked-multiply delta (unchecked-add 1 (Math/pow t 3))) start)))
|
||||||
|
|
||||||
(defn tween [id screen path start end duration & {:keys [finish ease entities]}]
|
(defn tween [id screen path start end duration & {:keys [finish ease entities]}]
|
||||||
(let [ease (or ease ease-linear)
|
(let [ease (or ease ease-linear)
|
||||||
@@ -54,11 +58,11 @@
|
|||||||
start (if (and entities (= start :current))
|
start (if (and entities (= start :current))
|
||||||
(get-in entities path)
|
(get-in entities path)
|
||||||
start)
|
start)
|
||||||
delta (- end start)
|
delta (unchecked-subtract ^double end ^double start)
|
||||||
]
|
]
|
||||||
(fn [e total-time]
|
(fn [e ^double total-time]
|
||||||
(let [delta-time (- total-time start-time)
|
(let [delta-time (- total-time ^double start-time)
|
||||||
pct-done (min (/ delta-time duration) 1.0)
|
pct-done (min (/ delta-time ^double duration) 1.0)
|
||||||
new-val (ease delta-time start delta duration)
|
new-val (ease delta-time start delta duration)
|
||||||
e (assoc-in e path (if (= 1.0 pct-done)
|
e (assoc-in e path (if (= 1.0 pct-done)
|
||||||
end
|
end
|
||||||
@@ -66,4 +70,5 @@
|
|||||||
|
|
||||||
(if (= 1.0 pct-done)
|
(if (= 1.0 pct-done)
|
||||||
(finish (update-in e [:tweens] dissoc id))
|
(finish (update-in e [:tweens] dissoc id))
|
||||||
e)))))
|
e))
|
||||||
|
)))
|
||||||
|
|||||||
@@ -35,15 +35,15 @@
|
|||||||
|
|
||||||
(def selected-save (atom nil))
|
(def selected-save (atom nil))
|
||||||
|
|
||||||
(defn current-music-volume [& [factor]]
|
(defn current-music-volume [& [^double factor]]
|
||||||
(* (Math/pow (/ (:music-volume @settings) 100.0) 2)
|
(-> (Math/pow (unchecked-multiply (:music-volume @settings) 0.01) 2)
|
||||||
0.25
|
(unchecked-multiply 0.25)
|
||||||
(or factor 1.0)))
|
(unchecked-multiply (or factor 1.0))))
|
||||||
|
|
||||||
(defn current-sound-volume [& [factor]]
|
(defn current-sound-volume [& [factor]]
|
||||||
(* (Math/pow (/ (:sound-volume @settings) 100.0) 2)
|
(-> (Math/pow (unchecked-multiply (:sound-volume @settings) 0.01) 2)
|
||||||
0.5
|
(unchecked-multiply 0.5)
|
||||||
(or factor 1.0)))
|
(unchecked-multiply (or factor 1.0))))
|
||||||
|
|
||||||
(defn cursor [filename which]
|
(defn cursor [filename which]
|
||||||
(let [scale 4
|
(let [scale 4
|
||||||
|
|||||||
Reference in New Issue
Block a user