jak-project/goal_src/jak1/engine/anim/aligner.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

122 lines
5.8 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
(bundles "ENGINE.CGO" "GAME.CGO")
(require "engine/anim/aligner-h.gc")
(require "engine/common-obs/process-drawable.gc")
;; DECOMP BEGINS
;; ERROR: Unsupported inline assembly instruction kind - [lw ra, return-from-thread(s7)]
;; ERROR: Unsupported inline assembly instruction kind - [jr ra]
(defmethod compute-alignment! ((this align-control))
(local-vars (a0-9 symbol) (s7-0 none) (ra-0 int))
(with-pp
(let ((s5-0 (-> this process skel active-channels)))
(dotimes (s4-0 s5-0)
(let* ((a0-3 (-> this process skel channel s4-0))
(v1-5 (-> a0-3 frame-group))
(a0-4 (-> a0-3 command))
(a1-0 'stack)
(a2-0 (= a0-4 a1-0)))
(cond
((or a2-0 (begin (set! a1-0 'stack1) (= a0-4 a1-0))))
(else
(when (!= (-> v1-5 type) art-joint-anim)
;; og:preserve-this
(go process-drawable-art-error "align joint-anim")
(abandon-thread)
0))))))
(let* ((a0-8 (-> this process skel root-channel 0))
(v1-16 (-> a0-8 frame-group))
(f0-0 (-> a0-8 frame-num)))
(= (-> a0-8 num-func) num-func-loop!)
(cond
((or (not v1-16) (!= (-> this frame-group) v1-16)) (set! a0-9 #t))
((= (-> a0-8 num-func) num-func-loop!) (set! a0-9 (< (* (-> a0-8 param 0) (- f0-0 (-> this frame-num))) 0.0)))
(else (set! a0-9 (= f0-0 0.0))))
(if a0-9 (logior! (-> this flags) (align-flags disabled)) (logclear! (-> this flags) (align-flags disabled)))
(set! (-> this frame-group) v1-16)
(set! (-> this frame-num) f0-0))
(mem-copy! (the-as pointer (-> this transform 1)) (the-as pointer (-> this transform)) 48)
(quaternion-copy! (the-as quaternion (-> this transform 1 rot)) (-> this align quat))
(set! (-> this transform 1 scale quad) (-> this align scale quad))
(let* ((a2-5 (-> this matrix 1 vector))
(a3-0 (-> this matrix))
(v1-19 (-> a3-0 0 vector 0 quad))
(a0-18 (-> a3-0 0 vector 1 quad))
(a1-12 (-> a3-0 0 vector 2 quad))
(a3-1 (-> a3-0 0 vector 3 quad)))
(set! (-> a2-5 0 quad) v1-19)
(set! (-> a2-5 1 quad) a0-18)
(set! (-> a2-5 2 quad) a1-12)
(set! (-> a2-5 3 quad) a3-1))
(let ((s5-1 (-> this process node-list data 1)))
(cspace<-matrix-no-push-joint! s5-1 (-> this process skel))
(let* ((v1-23 (-> this matrix))
(a3-2 (-> s5-1 bone transform))
(a0-21 (-> a3-2 vector 0 quad))
(a1-14 (-> a3-2 vector 1 quad))
(a2-6 (-> a3-2 vector 2 quad))
(a3-3 (-> a3-2 vector 3 quad)))
(set! (-> v1-23 0 vector 0 quad) a0-21)
(set! (-> v1-23 0 vector 1 quad) a1-14)
(set! (-> v1-23 0 vector 2 quad) a2-6)
(set! (-> v1-23 0 vector 3 quad) a3-3))
(vector*! (the-as vector (-> this transform)) (-> s5-1 bone transform vector 3) (-> this process root scale)))
(vector-! (the-as vector (-> this delta)) (the-as vector (-> this transform)) (the-as vector (-> this transform 1)))
(set-vector! (-> this align scale)
(vector-length (the-as vector (-> this matrix)))
(vector-length (-> this matrix 0 vector 1))
(vector-length (-> this matrix 0 vector 2))
1.0)
(vector-! (-> this delta scale) (-> this align scale) (-> this transform 1 scale))
(let ((a2-8 (matrix-inv-scale! (new 'stack-no-clear 'matrix) (-> this align scale))))
(quaternion-normalize! (matrix->quaternion (-> this align quat) (matrix*! a2-8 (the-as matrix (-> this matrix)) a2-8))))
(let ((a1-24 (quaternion-inverse! (new 'stack-no-clear 'quaternion) (the-as quaternion (-> this transform 1 rot)))))
(quaternion-normalize! (quaternion*! (-> this delta quat) a1-24 (-> this align quat))))
(-> this delta)))
(defmethod first-transform ((this align-control))
(the-as transform (-> this transform)))
(defmethod snd-transform ((this align-control))
(-> this transform 1))
(defmethod align! ((this align-control) (arg0 align-opts) (arg1 float) (arg2 float) (arg3 float))
(when (not (logtest? (-> this flags) (align-flags disabled)))
(let* ((a0-1 (-> this process))
(t9-0 (method-of-object a0-1 apply-alignment))
(v1-4 (-> this delta))
(t1-0 (new 'stack-no-clear 'vector)))
(set! (-> t1-0 x) arg1)
(set! (-> t1-0 y) arg2)
(set! (-> t1-0 z) arg3)
(set! (-> t1-0 w) 1.0)
(t9-0 a0-1 arg0 v1-4 t1-0)))
(-> this process root))
(defmethod set-and-limit-velocity ((this trsqv) (arg0 int) (arg1 vector) (arg2 float))
(let ((gp-0 (-> this transv)))
(when (logtest? arg0 4)
(set! (-> gp-0 x) (-> arg1 x))
(set! (-> gp-0 z) (-> arg1 z))
(let ((f0-4 (fmin (* (vector-xz-length arg1) (-> *display* frames-per-second)) arg2))) (vector-xz-normalize! gp-0 f0-4))))
this)
(defmethod align-vel-and-quat-only! ((this align-control) (arg0 align-opts) (arg1 vector) (arg2 int) (arg3 float) (arg4 float))
(when (not (logtest? (-> this flags) (align-flags disabled)))
(let ((s5-0 (-> this delta)))
(let ((s3-0 (-> this process root transv)))
(if (logtest? arg0 (align-opts adjust-y-vel))
(set! (-> s3-0 y) (* (-> s5-0 trans y) arg3 (-> *display* frames-per-second))))
(when (logtest? arg0 (align-opts adjust-xz-vel))
(set! (-> s3-0 x) (-> arg1 x))
(set! (-> s3-0 z) (-> arg1 z))
(let ((f0-8 (* (fmin (vector-xz-length arg1) (* (vector-xz-length (-> s5-0 trans)) arg4)) (-> *display* frames-per-second)))
(t9-2 vector-xz-normalize!))
(set! (-> this last-speed) f0-8)
(t9-2 s3-0 f0-8))))
(if (logtest? arg0 (align-opts adjust-quat))
(quaternion-normalize! (quaternion*! (-> this process root quat) (-> this process root quat) (-> s5-0 quat))))))
(-> this process root))