Files
jak-project/goal_src/jak1/engine/target/sidekick.gc
T
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

182 lines
8.6 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
(bundles "ENGINE.CGO" "GAME.CGO")
(require "engine/common-obs/process-drawable.gc")
(require "engine/target/target-util.gc")
;; DECOMP BEGINS
(define *sidekick-remap*
'(("run-to-stance-left" "run-to-stance")
("run-to-stance-loop-left" "run-to-stance-loop")
("stance-loop-left" "stance-loop")
("run-to-stance-right" "run-to-stance")
("run-to-stance-loop-right" "run-to-stance-loop")
("stance-loop-right" "stance-loop")
("run-to-stance-up" "run-to-stance")
("run-to-stance-loop-up" "run-to-stance-loop")
("stance-loop-up" "stance-loop")
("run-to-stance-down" "run-to-stance")
("run-to-stance-loop-down" "run-to-stance-loop")
("stance-loop-down" "stance-loop")
("run-right" "run")
("run-left" "run")
("walk-right" "walk")
("walk-left" "walk")
("edge-grab-stance1" "edge-grab-stance1" "edge-grab-stance1-alt")
("pole-cycle" "pole-cycle" "pole-cycle2")))
(defun cspace<-cspace+quaternion! ((arg0 cspace) (arg1 cspace) (arg2 quaternion))
(rlet ((Q :class vf)
(vf0 :class vf)
(vf1 :class vf)
(vf2 :class vf)
(vf3 :class vf)
(vf4 :class vf)
(vf5 :class vf))
(init-vf0-vector)
(let ((s5-0 (-> arg0 bone transform)))
(quaternion->matrix s5-0 arg2)
(.lvf vf1 (&-> (new 'static 'vector :x 1.0 :y 1.0 :z 1.0 :w 1.0) quad))
(.lvf vf2 (&-> (-> arg1 bone) transform vector 3 quad))
(.lvf vf3 (&-> s5-0 vector 0 quad))
(.lvf vf4 (&-> s5-0 vector 1 quad))
(.lvf vf5 (&-> s5-0 vector 2 quad))
(.div.vf Q vf0 vf2 :fsf #b11 :ftf #b11)
(.wait.vf)
(.mul.vf vf2 vf2 Q :mask #b111)
(.mov.vf vf2 vf0 :mask #b1000)
(.mul.x.vf vf3 vf3 vf1)
(.mul.y.vf vf4 vf4 vf1)
(.mul.z.vf vf5 vf5 vf1)
(.svf (&-> s5-0 vector 3 quad) vf2)
(.svf (&-> s5-0 vector 0 quad) vf3)
(.svf (&-> s5-0 vector 1 quad) vf4)
(.svf (&-> s5-0 vector 2 quad) vf5)
s5-0)))
(defstate sidekick-clone (sidekick)
:event
(behavior ((proc process) (argc int) (message symbol) (block event-message-block))
(local-vars (v0-0 object))
(case message
(('matrix)
(case (-> block param 0)
(('play-anim)
(set! v0-0 (-> self node-list data))
(set! (-> (the-as (inline-array cspace) v0-0) 0 param0) cspace<-cspace+quaternion!)
(set! (-> (the-as (inline-array cspace) v0-0) 0 param1) (the-as basic (-> self parent-override 0 node-list data)))
(set! (-> (the-as (inline-array cspace) v0-0) 0 param2) (the-as basic (-> self parent-override 0 control quat))))
(('copy-parent)
(set! v0-0 (-> self node-list data))
(set! (-> (the-as (inline-array cspace) v0-0) 0 param0) cspace<-cspace!)
(set! (-> (the-as (inline-array cspace) v0-0) 0 param1) (the-as basic (-> self parent-override 0 node-list data)))
(set! (-> (the-as (inline-array cspace) v0-0) 0 param2) #f))
(else
(set! v0-0 (-> self node-list data))
(set! (-> (the-as (inline-array cspace) v0-0) 0 param0) cspace<-cspace+quaternion!)
(set! (-> (the-as (inline-array cspace) v0-0) 0 param1)
(the-as basic (-> self parent-override 0 control unknown-cspace10 parent)))
(set! (-> (the-as (inline-array cspace) v0-0) 0 param2) (the-as basic (-> self parent-override 0 control quat)))))
v0-0)
(('shadow) (set! v0-0 (-> block param 0)) (set! (-> self shadow-in-movie?) (the-as symbol v0-0)) v0-0)
(('blend-shape)
(cond
((-> block param 0)
(set! v0-0 (logior (-> self skel status) (janim-status blerc)))
(set! (-> self skel status) (the-as janim-status v0-0)))
(else
(set! v0-0 (logclear (-> self skel status) (janim-status blerc)))
(set! (-> self skel status) (the-as janim-status v0-0))))
v0-0)))
:code looping-code
:post
(behavior ()
(let ((v1-0 'process-drawable-art-error)
(a0-0 (-> self parent-override)))
(when (!= (-> (if a0-0 (-> a0-0 0 self-override)) next-state name) v1-0)
(quaternion-copy! (-> self root quat) (-> self parent-override 0 control quat))
(set! (-> self anim-seed) (-> self parent-override 0 anim-seed))
(set! (-> self draw status) (-> self parent-override 0 draw status))
(joint-control-copy! (-> self skel) (-> self parent-override 0 skel))
(joint-control-remap! (-> self skel)
(-> self draw art-group)
(-> self parent-override 0 draw art-group)
*sidekick-remap*
(the-as int (-> self anim-seed))
"")
(let ((v1-22 (-> self parent-override 0 draw color-mult quad))) (set! (-> self draw color-mult quad) v1-22))
(with-pc ;; duh!
(when (pc-cheats? (-> *pc-settings* cheats) sidekick-blue)
(set! (-> self draw color-mult x) (set! (-> self draw color-mult y) 0.1))))
(let ((v1-26 (-> self parent-override 0 draw color-emissive quad))) (set! (-> self draw color-emissive quad) v1-26))
(set! (-> self draw secondary-interp) (-> self parent-override 0 draw secondary-interp))
(if *debug-segment*
(add-frame (-> *display* frames (-> *display* on-screen) frame profile-bar 0)
'draw
(new 'static 'rgba :r #x40 :b #x40 :a #x80)))
(do-joint-math! self)
(if *debug-segment*
(add-frame (-> *display* frames (-> *display* on-screen) frame profile-bar 0) 'draw (new 'static 'rgba :r #x80 :a #x80)))
(vector<-cspace! (-> self draw origin) (-> self node-list data (-> self draw origin-joint-index)))))
(when *display-sidekick-stats*
(format *stdcon* "~%")
(debug-print-channels (-> self skel) (the-as symbol *stdcon*))
(add-debug-sphere *display-sidekick-stats*
(bucket-id debug-no-zbuf)
(-> self parent-override 0 control unknown-cspace10 parent bone transform vector 3)
409.6
(new 'static 'rgba :g #xff :a #x80))
(add-debug-sphere *display-sidekick-stats*
(bucket-id debug-no-zbuf)
(-> self node-list data 3 bone transform vector 3)
409.6
(new 'static 'rgba :r #xff :g #xff :a #x80))
(add-debug-sphere *display-sidekick-stats*
(bucket-id debug-no-zbuf)
(-> self draw origin)
409.6
(new 'static 'rgba :r #xff :g #x80 :a #x80)))
(set! (-> self draw shadow) (the-as shadow-geo (if (and (movie?) (-> self shadow-in-movie?)) sidekick-shadow-mg)))
(let ((a0-26 (-> self skel effect))) (if a0-26 (effect-control-method-9 a0-26)))
(if (logtest? (-> self skel status) (janim-status blerc blerc-done)) (merc-blend-shape self))
(if (logtest? (-> self skel status) (janim-status eye-done eye)) (merc-eye-anim self))))
(defskelgroup *sidekick-sg*
sidekick
sidekick-lod0-jg
-1
((sidekick-lod0-mg (meters 999999)))
:bounds (static-spherem 0 0 0 3)
:longest-edge (meters 1)
:shadow sidekick-shadow-mg
:texture-level 2
:sort 1)
(defbehavior init-sidekick sidekick ()
(logior! (-> self mask) (process-mask sidekick))
(set! (-> self root) (new 'process 'trsqv))
(vector-identity! (-> self root scale))
(quaternion-identity! (-> self root quat))
(initialize-skeleton self *sidekick-sg* '())
(set! (-> self draw origin-joint-index) (the-as uint 6))
(set! (-> self draw shadow-joint-index) (the-as uint 6))
(set! (-> self draw shadow-ctrl) *target-shadow-control*)
(logior! (-> self skel status) (janim-status eye))
(#when PC_PORT
;; daxter can be killed mid-blerc, leaving blerc modifications in the merc data.
;; once sidekick is restarted, the blerc-done flag will be lost, so the modifications will
;; to work around this, just set blerc-done on spawn. it will run blerc with 0's on the
;; first frame when daxter is drawn, clearing blerc data.
(logior! (-> self skel status) (janim-status blerc-done)))
(let ((v1-14 (-> self node-list data)))
(set! (-> v1-14 0 param0) cspace<-cspace+quaternion!)
(set! (-> v1-14 0 param1) (the-as basic (-> self parent-override 0 control unknown-cspace10 parent)))
(set! (-> v1-14 0 param2) (the-as basic (-> self parent-override 0 control quat))))
(set! (-> self shadow-in-movie?) #t)
(go sidekick-clone)
(none))
(defun starts ()
(send-event *target* 'sidekick #t))