Files
jak-project/goal_src/engine/util/smush-control-h.gc
T
Tyler Wilding 5f1ed7ab60 decomp: decompile *-obs files (#856)
* decomp: mostly finish `cam-master`

* decomp/scripts: lots of work in cam-states

* stash

* Merge remote-tracking branch 'water111/master' into decomp/camera-master

Updated submodule third-party/googletest

* decompiler: Add support for non power of 2 offsets for inline arr access

* decomp: mostly finish `cam-states` need to fix a macro issue

* blocked: `cam-master` decompiler crash when adding casts

* decomp: finish `cam-states-dbg`

* decomp: mostly finish `pov-camera` with the exception of joint-related code

* decomp: `cam-debug` finished decompiling, no way does this compile yet though

* decomp: considerable work done in `cam-layout`

* decomp: `cam-layout` almost done!

* decomp: `pov-camera` finished, TC tests will fail for now

* decomp: working on resolving issues

* decomp: cam-layout decompiling

* fixing more issues in cam-master...one event handler remains

* skip problematic function in `cam-master` for now

* gsrc: update res macros

* decomp: finish `cam-states`

* decomp: giving up on `cam-debug`

* tests: allow skipping state handlers in ref tests

* decomp: working through cam-layout bugs

* decomp: allow for shifting non-integers

* decomp: finalize `cam-layout` and `cam-master`

* decomp: finalize `cam-states`

* cleanup: bi-annual formatting of the casting files

* formatting

* decomp: start working on beach-obs

* blocked: `beach-obs` mostly finished, but handle cast issues and unknown `prebind` func signature

* blocked: `villagep-obs` done, `s6` not being referred to as `self`

* decomp: finish `citadel-obs`

* decomp: finish `darkcave-obs`

* blocked: need to allow `hud-h` to decompile properly (#f as static pointer)

* decomp: finish `jungle-obs`

* decomp: finish `village-obs`

* blocked: `misty-obs` handle cast issues

* decomp: finish `village2-obs`

* decomp: 1 function left in `swamp-obs`, particle related -- maybe we know now?

* decomp: finish `swamp-obs`

* blocked: `maincave-obs` handle casts

* decomp: finish `sunken-obs`

* blocked: `rolling-obs` handle casts and hud-parts

* decomp: finish `firecanyon-obs`

* decomp: finish `ogre-obs`

* blocked: `village3-obs` gives up type analysis!

* blocked: `snow-obs` has hud-parts and handle casts code

* decomp: finish `snow-flutflut-obs`

* blocked: `lavatube-obs` has s6-1 issue

* blocked: `title-obs` handle cast issues

* fixed post merge problems

* decomp: finish `jungleb-obs`

* blocked: `training-obs` has `s6-1` issue

* fix type consistency

* scripts: Extend update script to handle the game-text-id enum as well

* git: Update git attributes to effectively halve PR burden

* fixed `sound-play-by-name` signature

* fix particle definitions in firecanyon-obs

* fix func signature in racer-states

* update ref tests

* tests: update current ref tests

* tests: add `joint` to ref-tests

* tests: add `process-drawable` to ref-tests

* updated gsrc

* add back manual fix

* address most feedback, update source files

* get rid of forward declarations in `darkcave-obs`

Co-authored-by: ManDude <7569514+ManDude@users.noreply.github.com>
2021-11-05 21:29:32 -04:00

143 lines
4.8 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.
(deftype smush-control (structure)
((start-time int64 :offset-assert 0)
(period float :offset-assert 8)
(duration float :offset-assert 12)
(amp float :offset-assert 16)
(damp-amp float :offset-assert 20)
(damp-period float :offset-assert 24) ;; set a negative value here to flag as die on next update
(ticks float :offset-assert 28)
)
:pack-me
:method-count-assert 15
:size-assert #x20
:flag-assert #xf00000020
(:methods
(set-zero! (_type_) _type_ 9)
(update! (_type_) float 10)
(get-no-update (_type_) float 11)
(activate! (_type_ float int int float float) _type_ 12)
(nonzero-amplitude? (_type_) symbol 13)
(die-on-next-update! (_type_) _type_ 14)
)
)
(defmethod nonzero-amplitude? smush-control ((obj smush-control))
"Return #t if amp is not zero, #f otherwise"
(declare (inline))
(!= (-> obj amp) 0.0)
)
(defmethod set-zero! smush-control ((obj smush-control))
(set! (-> obj period) 0.0)
(set! (-> obj duration) 0.0)
(set! (-> obj amp) 0.0)
(set! (-> obj damp-amp) 0.0)
(set! (-> obj damp-period) 0.0)
(set! (-> obj ticks) 0.0)
obj
)
(defmethod update! smush-control ((obj smush-control))
"Run the smush control and return the result. Updates the internal state."
(cond
((nonzero-amplitude? obj)
(let* ((time-since-start (the float (- (-> *display* base-frame-counter) (-> obj 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 (-> obj period)))) (-> obj period))))
)
;; we completed a new period!
(when (>= (- time-since-start (-> obj ticks)) (-> obj period))
;; once per period updates of amp/period
(set! (-> obj amp) (* (-> obj amp) (-> obj damp-amp)))
(set! (-> obj period) (* (-> obj period) (-> obj damp-period)))
;; store the ticks that we did this on
(set! (-> obj 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 (< (-> obj damp-period) 0.0)
(set-zero! obj)
)
)
;; absolute duraction check
(if (>= time-since-start (-> obj duration))
(set-zero! obj)
)
;; sine term multiplied by amplitude, and scaled by how much is left to go.
(* (sin (/ (* DEGREES_PER_ROT time-since-period-start) (-> obj period)))
(* (-> obj amp)
(/ (- (-> obj duration) time-since-start) (-> obj duration)))
)
)
)
;; amplitude = 0, die.
(else 0.0)
)
)
(defmethod get-no-update smush-control ((obj smush-control))
"Get the value, but don't update internal state"
(cond
((nonzero-amplitude? obj)
(let* ((time-since-start (the float (- (-> *display* base-frame-counter) (-> obj start-time))))
(time-since-period-start (- time-since-start (* (the float (the int (/ time-since-start (-> obj period)))) (-> obj period))))
)
(* (sin (/ (* DEGREES_PER_ROT time-since-period-start) (-> obj period)))
(* (-> obj amp)
(/ (- (-> obj duration) time-since-start) (-> obj duration)))
)
)
)
;; amplitude = 0, die.
(else 0.0)
)
)
(defmethod die-on-next-update! smush-control ((obj smush-control))
"On the next call to update!, zero everything.
Calls to get-no-update will still work."
(if (nonzero-amplitude? obj)
(set! (-> obj damp-period) -1.0)
)
obj
)
(defmethod activate! smush-control ((obj 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 (-> obj amp)))
(fabs (get-no-update obj))
)
(set! (-> obj amp) arg0)
(set! (-> obj period) (the float arg1))
(set! (-> obj duration) (the float arg2))
(set! (-> obj damp-amp) arg3)
(set! (-> obj damp-period) arg4)
(set! (-> obj ticks) 0.0)
(set! (-> obj start-time) (-> *display* base-frame-counter))
)
obj
)