mirror of
https://github.com/open-goal/jak-project.git
synced 2024-10-20 21:27:52 -04:00
cd68cb671e
Major change to how `deftype` shows up in our code: - the decompiler will no longer emit the `offset-assert`, `method-count-assert`, `size-assert` and `flag-assert` parameters. There are extremely few cases where having this in the decompiled code is helpful, as the types there come from `all-types` which already has those parameters. This also doesn't break type consistency because: - the asserts aren't compared. - the first step of the test uses `all-types`, which has the asserts, which will throw an error if they're bad. - the decompiler won't emit the `heap-base` parameter unless necessary now. - the decompiler will try its hardest to turn a fixed-offset field into an `overlay-at` field. It falls back to the old offset if all else fails. - `overlay-at` now supports field "dereferencing" to specify the offset that's within a field that's a structure, e.g.: ```lisp (deftype foobar (structure) ((vec vector :inline) (flags int32 :overlay-at (-> vec w)) ) ) ``` in this structure, the offset of `flags` will be 12 because that is the final offset of `vec`'s `w` field within this structure. - **removed ID from all method declarations.** IDs are only ever automatically assigned now. Fixes #3068. - added an `:overlay` parameter to method declarations, in order to declare a new method that goes on top of a previously-defined method. Syntax is `:overlay <method-name>`. Please do not ever use this. - added `state-methods` list parameter. This lets you quickly specify a list of states to be put in the method table. Same syntax as the `states` list parameter. The decompiler will try to put as many states in this as it can without messing with the method ID order. Also changes `defmethod` to make the first type definition (before the arguments) optional. The type can now be inferred from the first argument. Fixes #3093. --------- Co-authored-by: Hat Kid <6624576+Hat-Kid@users.noreply.github.com>
134 lines
4.3 KiB
Common Lisp
134 lines
4.3 KiB
Common Lisp
;;-*-Lisp-*-
|
|
(in-package goal)
|
|
|
|
;; name: smush-control-h.gc
|
|
;; name in dgo: smush-control-h
|
|
;; dgos: GAME, ENGINE
|
|
|
|
;; A "smush-control" generates a damped sinusoidal floating point value.
|
|
;; - on each full period, the amplitude and period are changed (multiplied)
|
|
;; - there is a maximum duration.
|
|
;; - the amplitude is additionally linearly scaled to go to zero over the duration.
|
|
|
|
;; DECOMP BEGINS
|
|
|
|
(deftype smush-control (structure)
|
|
((start-time time-frame)
|
|
(period float)
|
|
(duration float)
|
|
(amp float)
|
|
(damp-amp float)
|
|
(damp-period float) ;; set a negative value here to flag as die on next update
|
|
(ticks float)
|
|
)
|
|
:pack-me
|
|
(:methods
|
|
(set-zero! (_type_) _type_)
|
|
(update! (_type_) float)
|
|
(get-no-update (_type_) float)
|
|
(activate! (_type_ float int int float float) _type_)
|
|
(nonzero-amplitude? (_type_) symbol)
|
|
(die-on-next-update! (_type_) _type_)
|
|
)
|
|
)
|
|
|
|
|
|
(defmethod nonzero-amplitude? ((this smush-control))
|
|
"Return #t if amp is not zero, #f otherwise"
|
|
(declare (inline))
|
|
|
|
(!= (-> this amp) 0.0)
|
|
)
|
|
|
|
(defmethod set-zero! ((this smush-control))
|
|
(set! (-> this period) 0.0)
|
|
(set! (-> this duration) 0.0)
|
|
(set! (-> this amp) 0.0)
|
|
(set! (-> this damp-amp) 0.0)
|
|
(set! (-> this damp-period) 0.0)
|
|
(set! (-> this ticks) 0.0)
|
|
this
|
|
)
|
|
|
|
(defmethod update! ((this smush-control))
|
|
"Run the smush control and return the result. Updates the internal state."
|
|
|
|
(cond
|
|
((nonzero-amplitude? this)
|
|
(let* ((time-since-start (the float (- (-> *display* base-frame-counter) (-> this start-time))))
|
|
;; use float to int rounding to figure out offset into the current period.
|
|
(time-since-period-start (- time-since-start (* (the float (the int (/ time-since-start (-> this period)))) (-> this period))))
|
|
)
|
|
;; we completed a new period!
|
|
(when (>= (- time-since-start (-> this ticks)) (-> this period))
|
|
;; once per period updates of amp/period
|
|
(set! (-> this amp) (* (-> this amp) (-> this damp-amp)))
|
|
(set! (-> this period) (* (-> this period) (-> this damp-period)))
|
|
;; store the ticks that we did this on
|
|
(set! (-> this ticks) time-since-start)
|
|
;; you can set damp-period to a negative number to indicate
|
|
;; that it should die on the next update. Do that here.
|
|
(if (< (-> this damp-period) 0.0)
|
|
(set-zero! this)
|
|
)
|
|
)
|
|
|
|
;; absolute duraction check
|
|
(if (>= time-since-start (-> this duration))
|
|
(set-zero! this)
|
|
)
|
|
;; sine term multiplied by amplitude, and scaled by how much is left to go.
|
|
(* (sin (/ (* DEGREES_PER_ROT time-since-period-start) (-> this period)))
|
|
(* (-> this amp)
|
|
(/ (- (-> this duration) time-since-start) (-> this duration)))
|
|
)
|
|
)
|
|
)
|
|
;; amplitude = 0, die.
|
|
(else 0.0)
|
|
)
|
|
)
|
|
|
|
(defmethod get-no-update ((this smush-control))
|
|
"Get the value, but don't update internal state"
|
|
|
|
(cond
|
|
((nonzero-amplitude? this)
|
|
(let* ((time-since-start (the float (- (-> *display* base-frame-counter) (-> this start-time))))
|
|
(time-since-period-start (- time-since-start (* (the float (the int (/ time-since-start (-> this period)))) (-> this period))))
|
|
)
|
|
(* (sin (/ (* DEGREES_PER_ROT time-since-period-start) (-> this period)))
|
|
(* (-> this amp)
|
|
(/ (- (-> this duration) time-since-start) (-> this duration)))
|
|
)
|
|
)
|
|
)
|
|
;; amplitude = 0, die.
|
|
(else 0.0)
|
|
)
|
|
)
|
|
|
|
(defmethod die-on-next-update! ((this smush-control))
|
|
"On the next call to update!, zero everything.
|
|
Calls to get-no-update will still work."
|
|
|
|
(if (nonzero-amplitude? this)
|
|
(set! (-> this damp-period) -1.0)
|
|
)
|
|
this
|
|
)
|
|
|
|
(defmethod activate! ((this smush-control) (arg0 float) (arg1 int) (arg2 int) (arg3 float) (arg4 float))
|
|
"Activate the smush! This only activates if the ongoing smush is mostly done."
|
|
(when (>= (fabs (* 0.2 (-> this amp))) (fabs (get-no-update this)))
|
|
(set! (-> this amp) arg0)
|
|
(set! (-> this period) (the float arg1))
|
|
(set! (-> this duration) (the float arg2))
|
|
(set! (-> this damp-amp) arg3)
|
|
(set! (-> this damp-period) arg4)
|
|
(set! (-> this ticks) 0.0)
|
|
(set-time! (-> this start-time))
|
|
)
|
|
this
|
|
)
|