jak-project/goal_src/jak1/levels/sunken/sunken-fish.gc
Tyler Wilding c162c66118
g/j1: Cleanup all main issues in the formatter and format all of goal_src/jak1 (#3535)
This PR does two main things:
1. Work through the main low-hanging fruit issues in the formatter
keeping it from feeling mature and usable
2. Iterate and prove that point by formatting all of the Jak 1 code
base. **This has removed around 100K lines in total.**
- The decompiler will now format it's results for jak 1 to keep things
from drifting back to where they were. This is controlled by a new
config flag `format_code`.

How am I confident this hasn't broken anything?:
- I compiled the entire project and stored it's `out/jak1/obj` files
separately
- I then recompiled the project after formatting and wrote a script that
md5's each file and compares it (`compare-compilation-outputs.py`
- The results (eventually) were the same:

![Screenshot 2024-05-25
132900](https://github.com/open-goal/jak-project/assets/13153231/015e6f20-8d19-49b7-9951-97fa88ddc6c2)
> This proves that the only difference before and after is non-critical
whitespace for all code/macros that is actually in use.

I'm still aware of improvements that could be made to the formatter, as
well as general optimization of it's performance. But in general these
are for rare or non-critical situations in my opinion and I'll work
through them before doing Jak 2. The vast majority looks great and is
working properly at this point. Those known issues are the following if
you are curious:

![image](https://github.com/open-goal/jak-project/assets/13153231/0edfaba1-6d36-40f5-ab23-0642209867c4)
2024-06-05 22:17:31 -04:00

238 lines
11 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
(bundles "SUN.DGO")
(require "engine/common-obs/generic-obs.gc")
(require "engine/geometry/path.gc")
;; DECOMP BEGINS
(deftype sunkenfisha (process-drawable)
((path-u float)
(path-speed float)
(path-speed-seek-speed float)
(targ-path-speed float)
(path-normal-speed-lo float)
(path-normal-speed-hi float)
(path-dir float)
(change-path-dir-time time-frame)
(local-path-offset vector :inline)
(targ-local-path-offset vector :inline)
(local-path-offset-dir vector :inline)
(max-local-path-offset vector :inline)
(facing-rot vector :inline)
(path-trans-offset vector :inline))
(:methods
(sunkenfisha-method-20 (_type_) float)
(sunkenfisha-method-21 (_type_ vector float vector) vector)
(sunkenfisha-method-22 (_type_) none)
(sunkenfisha-method-23 (_type_) quaternion)
(sunkenfisha-method-24 (_type_) vector)
(sunkenfisha-method-25 (_type_) none)
(sunkenfisha-method-26 (_type_) float)
(sunkenfisha-method-27 (_type_) float))
(:states
sunkenfisha-idle))
(defskelgroup *sunkenfisha-red-yellow-sg*
sunkenfisha
sunkenfisha-red-yellow-lod0-jg
-1
((sunkenfisha-red-yellow-lod0-mg (meters 999999)))
:bounds (static-spherem 0 1.5 0 2.5))
(defskelgroup *sunkenfisha-yellow-blue-sg*
sunkenfisha
sunkenfisha-yellow-blue-lod0-jg
-1
((sunkenfisha-yellow-blue-lod0-mg (meters 999999)))
:bounds (static-spherem 0 1.5 0 2.5))
(defskelgroup *sunkenfisha-yellow-eye-sg*
sunkenfisha
sunkenfisha-yellow-eye-lod0-jg
-1
((sunkenfisha-yellow-eye-lod0-mg (meters 999999)))
:bounds (static-spherem 0 1.5 0 2.5))
(defmethod sunkenfisha-method-22 ((this sunkenfisha))
0
(none))
(defmethod sunkenfisha-method-21 ((this sunkenfisha) (arg0 vector) (arg1 float) (arg2 vector))
(eval-path-curve! (-> this path) arg0 arg1 'interp)
(vector+! arg0 arg0 (-> this path-trans-offset))
(let ((s2-0 (new 'stack-no-clear 'vector)))
(path-control-method-14 (-> this path) s2-0 arg1)
(let ((f0-2 (atan (-> s2-0 x) (-> s2-0 z)))
(s4-1 (new 'stack-no-clear 'vector)))
(vector-rotate-around-y! s4-1 arg2 f0-2)
(vector+! arg0 arg0 s4-1))))
(defmethod sunkenfisha-method-24 ((this sunkenfisha))
(let ((s4-0 (new 'stack-no-clear 'vector))
(s3-0 (new 'stack-no-clear 'matrix))
(gp-0 (new 'stack-no-clear 'vector)))
(vector-! s4-0 (-> this targ-local-path-offset) (-> this local-path-offset))
(when (>= (* 4096.0 (seconds-per-frame)) (vector-length s4-0))
(until (< (* 16384.0 (seconds-per-frame)) (vector-length s4-0))
(set! (-> this targ-local-path-offset x)
(rand-vu-float-range (- (-> this max-local-path-offset x)) (-> this max-local-path-offset x)))
(set! (-> this targ-local-path-offset y)
(rand-vu-float-range (- (-> this max-local-path-offset y)) (-> this max-local-path-offset y)))
(vector-! s4-0 (-> this targ-local-path-offset) (-> this local-path-offset))))
(vector-normalize! s4-0 1.0)
(matrix-from-two-vectors-max-angle-partial! s3-0
(-> this local-path-offset-dir)
s4-0
(* 16384.0 (seconds-per-frame))
0.1)
(vector-matrix*! (-> this local-path-offset-dir) (-> this local-path-offset-dir) s3-0)
(vector-normalize! (-> this local-path-offset-dir) 1.0)
(vector-float*! gp-0 (-> this local-path-offset-dir) (* 4096.0 (seconds-per-frame)))
(vector+! (-> this local-path-offset) (-> this local-path-offset) gp-0)))
(defmethod sunkenfisha-method-25 ((this sunkenfisha))
(let* ((f0-0 (-> this path-speed))
(f1-1 (seek f0-0 (-> this targ-path-speed) (* (-> this path-speed-seek-speed) (seconds-per-frame)))))
(set! (-> this path-speed) f1-1)
(let ((f30-0 (+ (-> this path-u) (* (-> this path-dir) f1-1 (seconds-per-frame)))))
(cond
((< f30-0 0.0) (set! f30-0 (- f30-0)) (sunkenfisha-method-20 this))
((< 1.0 f30-0) (+! f30-0 (* 2.0 (- 1.0 f30-0))) (sunkenfisha-method-20 this)))
(set! (-> this path-u) f30-0)))
(none))
(defmethod sunkenfisha-method-23 ((this sunkenfisha))
(let ((s5-0 (new 'stack-no-clear 'vector)))
(set-vector! s5-0 (- (vector-x-angle (-> this root transv))) (vector-y-angle (-> this root transv)) 0.0 1.0)
(set! (-> this facing-rot x) (deg-seek-smooth (-> this facing-rot x) (-> s5-0 x) (* 16384.0 (seconds-per-frame)) 0.1))
(set! (-> this facing-rot y) (deg-seek-smooth (-> this facing-rot y) (-> s5-0 y) (* 32768.0 (seconds-per-frame)) 0.1)))
(quaternion-zxy! (-> this root quat) (-> this facing-rot)))
(defmethod sunkenfisha-method-20 ((this sunkenfisha))
(set! (-> this path-dir) (- (-> this path-dir)))
(set! (-> this path-speed) 0.0)
(set! (-> this targ-path-speed) (rand-vu-float-range (-> this path-normal-speed-lo) (-> this path-normal-speed-hi)))
(set! (-> this change-path-dir-time) (+ (current-time) (rand-vu-int-range (seconds 5) (seconds 18))))
(set! (-> this targ-local-path-offset y) (* 0.5 (+ (-> this targ-local-path-offset y) (-> this local-path-offset y))))
(let* ((f0-8 (-> this local-path-offset x))
(f1-3 (- (-> this targ-local-path-offset x) f0-8)))
(when (< (fabs f1-3) 12288.0)
(if (>= f1-3 0.0)
(set! (-> this targ-local-path-offset x) (fmin (+ 12288.0 f0-8) (-> this max-local-path-offset x)))
(set! (-> this targ-local-path-offset x) (fmax (+ -12288.0 f0-8) (- (-> this max-local-path-offset x))))))))
(defstate sunkenfisha-idle (sunkenfisha)
:trans
(behavior ()
(local-vars (at-0 int))
(rlet ((vf0 :class vf)
(vf1 :class vf)
(vf2 :class vf))
(init-vf0-vector)
(if (>= (current-time) (-> self change-path-dir-time)) (sunkenfisha-method-20 self))
(sunkenfisha-method-24 self)
(sunkenfisha-method-25 self)
(let ((gp-0 (new 'stack-no-clear 'vector)))
(sunkenfisha-method-21 self gp-0 (-> self path-u) (-> self local-path-offset))
(vector-! (-> self root transv) gp-0 (-> self root trans))
(set! (-> self root trans quad) (-> gp-0 quad)))
(let ((v1-16 (-> self root transv)))
(.lvf vf1 (&-> (-> self root transv) quad))
(let ((f0-1 (-> *display* frames-per-second))) (.mov at-0 f0-1))
(.mov vf2 at-0)
(.mov.vf vf1 vf0 :mask #b1000)
(.mul.x.vf vf1 vf1 vf2 :mask #b111)
(.svf (&-> v1-16 quad) vf1))
(sunkenfisha-method-23 self)))
:code
(behavior ()
(loop
(ja-no-eval :group! sunkenfisha-idle-ja :num! (seek!) :frame-num 0.0)
(until (ja-done? 0)
(suspend)
(ja :num! (seek!)))))
:post ja-post)
(defmethod sunkenfisha-method-26 ((this sunkenfisha))
(set! (-> this root) (new 'process 'trsqv))
(process-drawable-from-entity! this (-> this entity))
(set-vector! (-> this root scale) 6.0 6.0 6.0 1.0)
(let ((v1-3 (rand-vu-int-count 3)))
(cond
((zero? v1-3) (initialize-skeleton this *sunkenfisha-red-yellow-sg* '()))
((= v1-3 1) (initialize-skeleton this *sunkenfisha-yellow-blue-sg* '()))
((= v1-3 2) (initialize-skeleton this *sunkenfisha-yellow-eye-sg* '()))))
(ja-channel-set! 1)
(let ((s5-0 (-> this skel root-channel 0)))
(joint-control-channel-group-eval! s5-0 (the-as art-joint-anim (-> this draw art-group data 6)) num-func-identity)
(set! (-> s5-0 frame-num) 0.0)))
(defmethod sunkenfisha-method-27 ((this sunkenfisha))
(local-vars (sv-16 res-tag) (sv-32 res-tag) (sv-48 res-tag))
(vector-reset! (-> this path-trans-offset))
(set! (-> this path-u) (rand-vu-float-range 0.0 1.0))
(if (zero? (rand-vu-int-count 2)) (set! (-> this path-dir) 1.0) (set! (-> this path-dir) -1.0))
(set-vector! (-> this max-local-path-offset) 16384.0 28672.0 0.0 1.0)
(set! sv-16 (new 'static 'res-tag))
(let ((v1-5 (res-lump-data (-> this entity) 'path-max-offset (pointer float) :tag-ptr (& sv-16))))
(when v1-5
(set! (-> this max-local-path-offset x) (-> v1-5 0))
(set! (-> this max-local-path-offset y) (-> v1-5 1))))
(set-vector! (-> this local-path-offset) 0.0 0.0 0.0 1.0)
(set! (-> this local-path-offset x)
(rand-vu-float-range (- (-> this max-local-path-offset x)) (-> this max-local-path-offset x)))
(set! (-> this local-path-offset y)
(rand-vu-float-range (- (-> this max-local-path-offset y)) (-> this max-local-path-offset y)))
(set! (-> this targ-local-path-offset quad) (-> this local-path-offset quad))
(set! (-> this targ-local-path-offset x)
(rand-vu-float-range (- (-> this max-local-path-offset x)) (-> this max-local-path-offset x)))
(set! (-> this targ-local-path-offset y)
(rand-vu-float-range (- (-> this max-local-path-offset y)) (-> this max-local-path-offset y)))
(vector-! (-> this local-path-offset-dir) (-> this targ-local-path-offset) (-> this local-path-offset))
(vector-normalize! (-> this local-path-offset-dir) 1.0)
(set! (-> this change-path-dir-time) (+ (current-time) (rand-vu-int-range (seconds 5) (seconds 18))))
(set! (-> this path) (new 'process 'curve-control this 'path -1000000000.0))
(logior! (-> this path flags) (path-control-flag display draw-line draw-point draw-text))
(set! sv-32 (new 'static 'res-tag))
(let ((v1-16 (res-lump-data (-> this entity) 'path-trans-offset (pointer float) :tag-ptr (& sv-32))))
(when v1-16
(+! (-> this path-trans-offset x) (-> v1-16 0))
(+! (-> this path-trans-offset y) (-> v1-16 1))
(+! (-> this path-trans-offset z) (-> v1-16 2))))
(if (< (-> this path curve num-cverts) 2) (go process-drawable-art-error "bad path"))
(let ((f28-0 8192.0)
(f30-0 26624.0))
(set! sv-48 (new 'static 'res-tag))
(let ((v1-23 (res-lump-data (-> this entity) 'speed (pointer float) :tag-ptr (& sv-48))))
(when v1-23
(set! f28-0 (-> v1-23 0))
(set! f30-0 (-> v1-23 1))))
(let ((f0-35 (path-distance (-> this path))))
(set! (-> this path-normal-speed-lo) (/ f28-0 f0-35))
(set! (-> this path-normal-speed-hi) (/ f30-0 f0-35))))
(set! (-> this path-speed-seek-speed) (* 2.0 (- (-> this path-normal-speed-hi) (-> this path-normal-speed-lo))))
(set! (-> this path-speed) (rand-vu-float-range (-> this path-normal-speed-lo) (-> this path-normal-speed-hi)))
(set! (-> this targ-path-speed) (-> this path-speed))
(let ((s4-0 (new 'stack-no-clear 'vector)))
(path-control-method-14 (-> this path) s4-0 (-> this path-u))
(set-vector! (-> this facing-rot) 0.0 (atan (-> s4-0 x) (-> s4-0 z)) 0.0 1.0))
(if (< (-> this path-dir) 0.0) (set! (-> this facing-rot y) (- (-> this facing-rot y)))))
(defbehavior sunkenfisha-init-by-other sunkenfisha ((arg0 entity-actor))
(set! (-> self entity) arg0)
(sunkenfisha-method-26 self)
(sunkenfisha-method-27 self)
(go sunkenfisha-idle)
(none))
(defmethod init-from-entity! ((this sunkenfisha) (arg0 entity-actor))
(sunkenfisha-method-26 this)
(sunkenfisha-method-27 this)
(let ((s5-0 (+ (res-lump-value (-> this entity) 'count uint128 :default (the-as uint128 1)) -1)))
(while (> (the-as int s5-0) 0)
(process-spawn sunkenfisha (-> this entity) :to this)
(+! s5-0 -1)))
(go sunkenfisha-idle)
(none))