jak-project/goal_src/jak2/engine/util/sync-info.gc

624 lines
19 KiB
Common Lisp
Raw Normal View History

;;-*-Lisp-*-
(in-package goal)
;; name: sync-info.gc
;; name in dgo: sync-info
;; dgos: ENGINE, GAME
;; DECOMP BEGINS
(defmethod initialize! sync-info ((obj sync-info) (arg0 sync-info-params))
"Set up a sync-info from params."
(format 0 "ERROR: Invalid call to sync-info::initialize!~%")
(none)
)
(defmethod get-current-phase-no-mod sync-info ((obj sync-info))
"Get the current value, with no fancy modifications."
(with-pp
(let* ((v1-0 (-> obj period))
(f0-1 (the float v1-0))
(f1-2 (+ (the float (mod (the-as uint (-> pp clock frame-counter)) v1-0)) (-> obj offset)))
)
(/ (- f1-2 (* (the float (the int (/ f1-2 f0-1))) f0-1)) f0-1)
)
)
)
(defmethod get-phase-offset sync-info ((obj sync-info))
"Get the offset, as a fraction of period"
(/ (-> obj offset) (the float (-> obj period)))
)
(defmethod sync-now! sync-info ((obj sync-info) (arg0 float))
"Adjust our offset so our current phase is the given phase."
(with-pp
(let* ((a2-0 (-> obj period))
(f0-1 (the float a2-0))
(v1-0 (- arg0 (* (the float (the int (/ arg0 f0-1))) f0-1)))
(f1-4 (+ (the float (mod (the-as uint (-> pp clock frame-counter)) a2-0)) (-> obj offset)))
(f1-6 (/ (- f1-4 (* (the float (the int (/ f1-4 f0-1))) f0-1)) f0-1))
(f1-10 (+ (* (- v1-0 f1-6) f0-1) f0-1 (-> obj offset)))
)
(set! (-> obj offset) (- f1-10 (* (the float (the int (/ f1-10 f0-1))) f0-1)))
)
0
(none)
)
)
(defmethod get-norm! sync-info ((obj sync-info) (arg0 int))
"Get the current value, from 0 to 1."
(format 0 "ERROR: Unsupported sync-info::get-norm!~%")
0.0
)
(defmethod get-scaled-val! sync-info ((obj sync-info) (arg0 float) (arg1 int))
"Multiples result of `get-norm!` by the provided float"
(* (get-norm! obj arg1) arg0)
)
(defmethod get-timeframe-offset! sync-info ((obj sync-info) (arg0 time-frame))
"Get the difference between the given time-frame and when this sync-info is at 0."
(with-pp
(if (zero? arg0)
(set! arg0 (-> pp clock frame-counter))
)
(let* ((v1-4 (-> obj period))
(f0-1 (the float v1-4))
(f1-2 (+ (the float (mod arg0 (the-as time-frame v1-4))) (-> obj offset)))
)
(+ arg0 (the int (- f0-1 (* (/ (- f1-2 (* (the float (the int (/ f1-2 f0-1))) f0-1)) f0-1) f0-1))))
)
)
)
(defmethod initialize! sync-linear ((obj sync-linear) (arg0 sync-info-params))
"Set up a sync-info from params."
(local-vars (sv-16 res-tag))
(if (!= (-> arg0 sync-type) 'sync-linear)
(format
0
"ERROR: <SW> Using wrong sync params in sync-linear::initialize (got ~A)! Fix this!~%"
(-> arg0 sync-type)
)
)
(set! (-> obj sync-flags) (-> arg0 sync-flags))
(let ((s4-0 (the-as int (-> arg0 period)))
(f30-0 (-> arg0 percent))
)
(let ((a0-3 (-> arg0 entity)))
(when a0-3
(set! sv-16 (new 'static 'res-tag))
(let ((v1-6 (res-lump-data (the-as res-lump a0-3) 'sync pointer :tag-ptr (& sv-16))))
(when v1-6
(set! s4-0 (the int (* 300.0 (-> (the-as (pointer float) v1-6)))))
(set! f30-0 (-> (the-as (pointer float) v1-6) 1))
)
)
)
)
(set! (-> obj period) (the-as uint s4-0))
(let* ((f0-4 (the float s4-0))
(f1-1 (* f30-0 f0-4))
)
(set! (-> obj offset) (- f1-1 (* (the float (the int (/ f1-1 f0-4))) f0-4)))
)
)
(none)
)
(defmethod get-norm! sync-linear ((obj sync-linear) (arg0 int))
"Get the current value, from 0 to 1."
(with-pp
(if (zero? arg0)
(set! arg0 (the-as int (-> pp clock frame-counter)))
)
(let* ((v1-4 (-> obj period))
(f0-1 (the float v1-4))
)
(cond
((logtest? (-> obj sync-flags) (sync-flags pong))
(let* ((f1-0 2.0)
(f2-2 (+ (the float (mod arg0 (the-as int v1-4))) (-> obj offset)))
(f0-3 (* f1-0 (/ (- f2-2 (* (the float (the int (/ f2-2 f0-1))) f0-1)) f0-1)))
)
(if (>= f0-3 1.0)
(set! f0-3 (- 2.0 f0-3))
)
f0-3
)
)
(else
(let ((f1-5 (+ (the float (mod arg0 (the-as int v1-4))) (-> obj offset))))
(/ (- f1-5 (* (the float (the int (/ f1-5 f0-1))) f0-1)) f0-1)
)
)
)
)
)
)
(defmethod get-scaled-val! sync-linear ((obj sync-linear) (arg0 float) (arg1 int))
"Multiples result of `get-norm!` by the provided float"
(* (get-norm! obj arg1) arg0)
)
(defmethod initialize! sync-eased ((obj sync-eased) (arg0 sync-info-params))
"Set up a sync-info from params."
(local-vars (sv-16 res-tag))
(if (!= (-> arg0 sync-type) 'sync-eased)
(format
0
"ERROR: <SW> Using wrong sync params in sync-eased::initialize (got ~A)! Fix this!~%"
(-> arg0 sync-type)
)
)
(set! (-> obj sync-flags) (-> arg0 sync-flags))
(let ((s5-0 (the-as int (-> arg0 period)))
(f22-0 (-> arg0 percent))
(f24-0 (-> arg0 pause-in))
(f26-0 (-> arg0 pause-out))
(f30-0 (-> arg0 ease-in))
(f28-0 (-> arg0 ease-out))
)
(let ((a0-3 (-> arg0 entity)))
(when a0-3
(set! sv-16 (new 'static 'res-tag))
(let ((v1-6 (res-lump-data (the-as res-lump a0-3) 'sync (pointer float) :tag-ptr (& sv-16))))
(when v1-6
(set! s5-0 (the int (* 300.0 (-> v1-6 0))))
(set! f22-0 (-> v1-6 1))
(when (>= (-> sv-16 elt-count) (the-as uint 4))
(set! f30-0 (-> v1-6 2))
(set! f28-0 (-> v1-6 3))
(when (>= (-> sv-16 elt-count) (the-as uint 6))
(set! f24-0 (-> v1-6 4))
(set! f26-0 (-> v1-6 5))
)
)
)
)
)
)
(set! (-> obj period) (the-as uint s5-0))
(let* ((f0-4 (the float s5-0))
(f1-1 (* f22-0 f0-4))
)
(set! (-> obj offset) (- f1-1 (* (the float (the int (/ f1-1 f0-4))) f0-4)))
)
(cond
((< f26-0 0.0)
(set! f26-0 0.0)
)
((< 1.0 f26-0)
(set! f26-0 1.0)
)
)
(cond
((< f24-0 0.0)
(set! f24-0 0.0)
)
((< (- 1.0 f26-0) f24-0)
(set! f24-0 (- 1.0 f26-0))
)
)
(let ((f0-14 (the float s5-0)))
(set! (-> obj pause-in) (* f24-0 f0-14))
(set! (-> obj pause-out) (* f26-0 f0-14))
)
(if (< f30-0 0.0)
(set! f30-0 0.0)
)
(if (< 1.0 f30-0)
(set! f30-0 1.0)
)
(if (< f28-0 0.001)
(set! f28-0 0.001)
)
(if (< 1.0 f28-0)
(set! f28-0 1.0)
)
(let ((f0-20 (+ f30-0 f28-0)))
(when (< 1.0 f0-20)
(set! f0-20 1.0)
(set! f30-0 (- 1.0 f28-0))
)
(let* ((f1-6 (- 1.0 f0-20))
(f0-21 f30-0)
(f1-7 (+ f30-0 f1-6))
(f2-3 (* f0-21 f0-21))
(f3-3 (+ (* 2.0 f0-21 (- f1-7 f0-21)) f2-3))
(f4-3 (/ f0-21 (- 1.0 f1-7)))
(f3-4 (+ (* (- 1.0 f1-7) (- 1.0 f1-7) f4-3) f3-3))
)
(set! (-> obj tlo) f0-21)
(set! (-> obj thi) f1-7)
(set! (-> obj ylo) f2-3)
(set! (-> obj m2) f4-3)
(set! (-> obj yend) f3-4)
)
)
)
(none)
)
(defmethod get-norm! sync-eased ((obj sync-eased) (arg0 int))
"Get the current value, from 0 to 1."
(with-pp
(if (zero? arg0)
(set! arg0 (the-as int (-> pp clock frame-counter)))
)
(let* ((v1-4 (-> obj period))
(f3-0 (the float v1-4))
(f0-1 (-> obj pause-in))
(f2-0 (-> obj pause-out))
(f1-1 (* 0.5 (- f3-0 (+ f0-1 f2-0))))
)
(the int (+ f0-1 f2-0 f3-0))
(cond
((logtest? (-> obj sync-flags) (sync-flags pong))
(let* ((f4-7 (+ (the float (mod arg0 (the-as int v1-4))) (-> obj offset)))
(f3-2 (- f4-7 (* (the float (the int (/ f4-7 f3-0))) f3-0)))
(v1-6 #f)
)
(when (>= f3-2 (+ f1-1 f0-1))
(set! v1-6 #t)
(set! f3-2 (- f3-2 (+ f1-1 f0-1)))
f0-1
(set! f0-1 f2-0)
)
(cond
((< f3-2 f0-1)
(set! f3-2 f0-1)
)
((< (+ f0-1 f1-1) f3-2)
(set! f3-2 (+ f0-1 f1-1))
)
)
(let* ((f0-3 (/ (- f3-2 f0-1) f1-1))
(f1-2 (-> obj tlo))
(f0-8 (/ (cond
((< f0-3 f1-2)
(* f0-3 f0-3)
)
((< f0-3 (-> obj thi))
(+ (* 2.0 f1-2 (- f0-3 f1-2)) (-> obj ylo))
)
(else
(let ((f1-5 (- 1.0 f0-3)))
(- (-> obj yend) (* f1-5 f1-5 (-> obj m2)))
)
)
)
(-> obj yend)
)
)
)
(if v1-6
(set! f0-8 (- 1.0 f0-8))
)
f0-8
)
)
)
(else
(format 0 "ERROR: <SW> Attempting to use sync-eased in unsupported non-pong mode.~%")
0.0
)
)
)
)
)
(defmethod get-scaled-val! sync-eased ((obj sync-eased) (arg0 float) (arg1 int))
"Multiples result of `get-norm!` by the provided float"
(* (get-norm! obj arg1) arg0)
)
(defmethod initialize! sync-paused ((obj sync-paused) (arg0 sync-info-params))
"Set up a sync-info from params."
(local-vars (sv-16 res-tag))
(if (!= (-> arg0 sync-type) 'sync-paused)
(format
0
"ERROR: <SW> Using wrong sync params in sync-paused::initialize (got ~A)! Fix this!~%"
(-> arg0 sync-type)
)
)
(set! (-> obj sync-flags) (-> arg0 sync-flags))
(let ((s5-0 (the-as int (-> arg0 period)))
(f26-0 (-> arg0 percent))
(f28-0 (-> arg0 pause-in))
(f30-0 (-> arg0 pause-out))
)
(let ((a0-3 (-> arg0 entity)))
(when a0-3
(set! sv-16 (new 'static 'res-tag))
(let ((v1-6 (res-lump-data (the-as res-lump a0-3) 'sync (pointer float) :tag-ptr (& sv-16))))
(when v1-6
(set! s5-0 (the int (* 300.0 (-> v1-6 0))))
(set! f26-0 (-> v1-6 1))
(when (>= (-> sv-16 elt-count) (the-as uint 4))
(set! f28-0 (-> v1-6 2))
(set! f30-0 (-> v1-6 3))
)
)
)
)
)
(set! (-> obj period) (the-as uint s5-0))
(let* ((f0-4 (the float s5-0))
(f1-1 (* f26-0 f0-4))
)
(set! (-> obj offset) (- f1-1 (* (the float (the int (/ f1-1 f0-4))) f0-4)))
)
(cond
((< f30-0 0.0)
(set! f30-0 0.0)
)
((< 1.0 f30-0)
(set! f30-0 1.0)
)
)
(cond
((< f28-0 0.0)
(set! f28-0 0.0)
)
((< (- 1.0 f30-0) f28-0)
(set! f28-0 (- 1.0 f30-0))
)
)
(let ((f0-14 (the float s5-0)))
(set! (-> obj pause-in) (* f28-0 f0-14))
(set! (-> obj pause-out) (* f30-0 f0-14))
)
)
(none)
)
(defmethod get-norm! sync-paused ((obj sync-paused) (arg0 int))
"Get the current value, from 0 to 1."
(with-pp
(if (zero? arg0)
(set! arg0 (the-as int (-> pp clock frame-counter)))
)
(let* ((v1-4 (-> obj period))
(f2-0 (the float v1-4))
(f0-1 (-> obj pause-in))
(f1-0 (-> obj pause-out))
)
(the int (+ f0-1 f1-0 f2-0))
(cond
((logtest? (-> obj sync-flags) (sync-flags pong))
(let* ((f3-5 (+ (the float (mod arg0 (the-as int v1-4))) (-> obj offset)))
(f3-6 (- f3-5 (* (the float (the int (/ f3-5 f2-0))) f2-0)))
(f2-2 (* 0.5 (- f2-0 (+ f0-1 f1-0))))
(v1-7 #f)
)
(when (>= f3-6 (+ f2-2 f0-1))
(set! v1-7 #t)
(set! f3-6 (- f3-6 (+ f2-2 f0-1)))
(set! f0-1 f1-0)
)
(let* ((f1-1 (/ (- f3-6 f0-1) f2-2))
(f0-5 (fmax 0.0 (fmin 1.0 f1-1)))
)
(if v1-7
(set! f0-5 (- 1.0 f0-5))
)
f0-5
)
)
)
(else
(let* ((f3-9 (+ (the float (mod arg0 (the-as int v1-4))) (-> obj offset)))
(f3-10 (- f3-9 (* (the float (the int (/ f3-9 f2-0))) f2-0)))
(f1-5 (- f2-0 (+ f0-1 f1-0)))
(f1-6 (/ (- f3-10 f0-1) f1-5))
)
(fmax 0.0 (fmin 1.0 f1-6))
)
)
)
)
)
)
(defmethod get-scaled-val! sync-paused ((obj sync-paused) (arg0 float) (arg1 int))
"Multiples result of `get-norm!` by the provided float"
(* (get-norm! obj arg1) arg0)
)
(defmethod set-params! delayed-rand-float ((obj delayed-rand-float) (arg0 int) (arg1 int) (arg2 float))
(set! (-> obj min-time) arg0)
(set! (-> obj max-time) arg1)
(set! (-> obj max-val) (* 0.5 arg2))
(set! (-> obj start-time) 0)
(set! (-> obj timer) 0)
(set! (-> obj value) 0.0)
(-> obj value)
)
(defmethod reset! delayed-rand-float ((obj delayed-rand-float))
(with-pp
(set! (-> obj start-time) (-> pp clock frame-counter))
(set! (-> obj timer) (rand-vu-int-range (-> obj min-time) (-> obj max-time)))
(set! (-> obj value) (rand-vu-float-range (- (-> obj max-val)) (-> obj max-val)))
)
)
(defmethod update! delayed-rand-float ((obj delayed-rand-float))
(with-pp
(if (>= (- (-> pp clock frame-counter) (-> obj start-time)) (-> obj timer))
(reset! obj)
)
(-> obj value)
)
)
(defmethod update-and-clear! delayed-rand-float ((obj delayed-rand-float))
(with-pp
(if (>= (- (-> pp clock frame-counter) (-> obj start-time)) (-> obj timer))
(reset! obj)
(set! (-> obj value) 0.0)
)
(-> obj value)
(none)
)
)
(defmethod set-params! oscillating-float ((obj oscillating-float) (arg0 float) (arg1 float) (arg2 float) (arg3 float))
(set! (-> obj value) arg0)
(set! (-> obj target) arg0)
(set! (-> obj vel) 0.0)
(set! (-> obj max-vel) arg2)
(set! (-> obj damping) arg3)
(set! (-> obj accel) arg1)
(-> obj value)
)
(defmethod update! oscillating-float ((obj oscillating-float) (arg0 float))
(with-pp
(let ((f0-3 (* (- (+ (-> obj target) arg0) (-> obj value)) (* (-> obj accel) (-> pp clock time-adjust-ratio)))))
(+! (-> obj vel) f0-3)
)
(set! (-> obj vel) (fmin (-> obj max-vel) (fmax (- (-> obj max-vel)) (-> obj vel))))
(set! (-> obj vel) (* (-> obj vel) (-> obj damping)))
(+! (-> obj value) (* (-> obj vel) (-> pp clock time-adjust-ratio)))
(-> obj value)
)
)
(defmethod set-params! bouncing-float ((obj bouncing-float)
(arg0 float)
(arg1 float)
(arg2 float)
(arg3 float)
(arg4 float)
(arg5 float)
(arg6 float)
)
(set-params! (-> obj osc) arg0 arg4 arg5 arg6)
(set! (-> obj max-value) arg1)
(set! (-> obj min-value) arg2)
(set! (-> obj elasticity) arg3)
(set! (-> obj state) 0)
(-> obj osc value)
)
(defmethod update! bouncing-float ((obj bouncing-float) (arg0 float))
(update! (-> obj osc) arg0)
(set! (-> obj state) 0)
(when (>= (-> obj osc value) (-> obj max-value))
(set! (-> obj osc value) (-> obj max-value))
(if (< 0.0 (-> obj osc vel))
(set! (-> obj osc vel) (* (-> obj osc vel) (- (-> obj elasticity))))
)
(set! (-> obj state) 1)
)
(when (>= (-> obj min-value) (-> obj osc value))
(set! (-> obj osc value) (-> obj min-value))
(if (< (-> obj osc vel) 0.0)
(set! (-> obj osc vel) (* (-> obj osc vel) (- (-> obj elasticity))))
)
(set! (-> obj state) -1)
)
(-> obj osc value)
)
(defmethod at-min? bouncing-float ((obj bouncing-float))
(= (-> obj state) -1)
)
(defmethod at-max? bouncing-float ((obj bouncing-float))
(= (-> obj state) 1)
)
(defmethod set-params! delayed-rand-vector ((obj delayed-rand-vector) (arg0 int) (arg1 int) (arg2 float) (arg3 float))
(set! (-> obj min-time) arg0)
(set! (-> obj max-time) arg1)
(set! (-> obj xz-max) (* 0.5 arg2))
(set! (-> obj y-max) (* 0.5 arg3))
(set! (-> obj start-time) 0)
(set! (-> obj timer) 0)
(vector-reset! (-> obj value))
(-> obj value)
)
(defmethod update-now! delayed-rand-vector ((obj delayed-rand-vector))
(with-pp
(set! (-> obj start-time) (-> pp clock frame-counter))
(set! (-> obj timer) (rand-vu-int-range (-> obj min-time) (-> obj max-time)))
(set! (-> obj value x) (rand-vu-float-range (- (-> obj xz-max)) (-> obj xz-max)))
(set! (-> obj value y) (rand-vu-float-range (- (-> obj y-max)) (-> obj y-max)))
(set! (-> obj value z) (rand-vu-float-range (- (-> obj xz-max)) (-> obj xz-max)))
(-> obj value)
)
)
(defmethod update-with-delay! delayed-rand-vector ((obj delayed-rand-vector))
(with-pp
(if (>= (- (-> pp clock frame-counter) (-> obj start-time)) (-> obj timer))
(update-now! obj)
)
(-> obj value)
)
)
(defmethod update-with-delay-or-reset! delayed-rand-vector ((obj delayed-rand-vector))
(with-pp
(if (>= (- (-> pp clock frame-counter) (-> obj start-time)) (-> obj timer))
(update-now! obj)
(vector-reset! (-> obj value))
)
(-> obj value)
)
)
(defmethod set-params! oscillating-vector ((obj oscillating-vector) (arg0 vector) (arg1 float) (arg2 float) (arg3 float))
(cond
(arg0
(set! (-> obj value quad) (-> arg0 quad))
(set! (-> obj target quad) (-> arg0 quad))
)
(else
(vector-reset! (-> obj value))
(vector-reset! (-> obj target))
)
)
(vector-reset! (-> obj vel))
(set! (-> obj max-vel) arg2)
(set! (-> obj damping) arg3)
(set! (-> obj accel) arg1)
(-> obj value)
)
(defmethod update! oscillating-vector ((obj oscillating-vector) (arg0 vector))
(with-pp
(let ((v1-0 (new 'stack-no-clear 'vector)))
(cond
(arg0
(vector+! v1-0 (-> obj target) arg0)
(vector-! v1-0 v1-0 (-> obj value))
)
(else
(vector-! v1-0 (-> obj target) (-> obj value))
)
)
(vector-float*! v1-0 v1-0 (* (-> obj accel) (-> pp clock time-adjust-ratio)))
(vector+! (-> obj vel) (-> obj vel) v1-0)
(let ((f0-2 (vector-length (-> obj vel))))
(if (< (-> obj max-vel) f0-2)
(vector-float*! (-> obj vel) (-> obj vel) (/ (-> obj max-vel) f0-2))
)
)
(vector-float*! (-> obj vel) (-> obj vel) (-> obj damping))
(vector-float*! v1-0 (-> obj vel) (-> pp clock time-adjust-ratio))
(vector+! (-> obj value) (-> obj value) v1-0)
)
(-> obj value)
)
)