mirror of
https://github.com/open-goal/jak-project.git
synced 2024-10-20 11:26:18 -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>
111 lines
2.9 KiB
Common Lisp
111 lines
2.9 KiB
Common Lisp
;;-*-Lisp-*-
|
|
(in-package goal)
|
|
|
|
;; name: smush-control-h.gc
|
|
;; name in dgo: smush-control-h
|
|
;; dgos: ENGINE, GAME
|
|
|
|
;; DECOMP BEGINS
|
|
|
|
(deftype smush-control (structure)
|
|
((start-time time-frame)
|
|
(period float)
|
|
(duration float)
|
|
(amp float)
|
|
(damp-amp float)
|
|
(damp-period float)
|
|
(ticks float)
|
|
)
|
|
:pack-me
|
|
(:methods
|
|
(set-zero! (_type_) _type_)
|
|
(update! (_type_) float)
|
|
(get-no-update (_type_) float)
|
|
(activate! (_type_ float int int float float clock) _type_)
|
|
(nonzero-amplitude? (_type_) symbol)
|
|
(die-on-next-update! (_type_) _type_)
|
|
)
|
|
)
|
|
|
|
|
|
(defmethod nonzero-amplitude? ((this smush-control))
|
|
(!= (-> 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))
|
|
(cond
|
|
((!= (-> this amp) 0.0)
|
|
(let* ((f30-0 (the float (- (current-time) (-> this start-time))))
|
|
(f0-2 (-> this period))
|
|
(f28-0 (- f30-0 (* (the float (the int (/ f30-0 f0-2))) f0-2)))
|
|
)
|
|
(when (>= (- f30-0 (-> this ticks)) (-> this period))
|
|
(set! (-> this amp) (* (-> this amp) (-> this damp-amp)))
|
|
(set! (-> this period) (* (-> this period) (-> this damp-period)))
|
|
(set! (-> this ticks) f30-0)
|
|
(if (< (-> this damp-period) 0.0)
|
|
(set-zero! this)
|
|
)
|
|
)
|
|
(if (>= f30-0 (-> this duration))
|
|
(set-zero! this)
|
|
)
|
|
(* (sin (/ (* 65536.0 f28-0) (-> this period)))
|
|
(* (-> this amp) (/ (- (-> this duration) f30-0) (-> this duration)))
|
|
)
|
|
)
|
|
)
|
|
(else
|
|
0.0
|
|
)
|
|
)
|
|
)
|
|
|
|
(defmethod get-no-update ((this smush-control))
|
|
(cond
|
|
((!= (-> this amp) 0.0)
|
|
(let* ((f30-0 (the float (- (current-time) (-> this start-time))))
|
|
(f0-2 (-> this period))
|
|
(f0-4 (- f30-0 (* (the float (the int (/ f30-0 f0-2))) f0-2)))
|
|
)
|
|
(* (sin (/ (* 65536.0 f0-4) (-> this period)))
|
|
(* (-> this amp) (/ (- (-> this duration) f30-0) (-> this duration)))
|
|
)
|
|
)
|
|
)
|
|
(else
|
|
0.0
|
|
)
|
|
)
|
|
)
|
|
|
|
(defmethod die-on-next-update! ((this smush-control))
|
|
(if (!= (-> this amp) 0.0)
|
|
(set! (-> this damp-period) -1.0)
|
|
)
|
|
this
|
|
)
|
|
|
|
(defmethod activate! ((this smush-control) (arg0 float) (arg1 int) (arg2 int) (arg3 float) (arg4 float) (arg5 clock))
|
|
(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! (-> this start-time) (-> arg5 frame-counter))
|
|
)
|
|
this
|
|
)
|