Files
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

82 lines
3.5 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
(bundles "ENGINE.CGO" "GAME.CGO")
(require "engine/math/vector.gc")
(require "engine/physics/trajectory-h.gc")
(require "engine/debug/debug-h.gc")
;; DECOMP BEGINS
(defmethod eval-position! ((this trajectory) (time float) (result vector))
"Evaluate the position of the object at a give time"
(set! (-> result quad) (-> this initial-position quad))
(+! (-> result x) (* time (-> this initial-velocity x)))
(+! (-> result y) (* time (-> this initial-velocity y)))
(+! (-> result z) (* time (-> this initial-velocity z)))
(+! (-> result y) (* 0.5 time time (-> this gravity)))
result)
(defmethod eval-velocity! ((this trajectory) (time float) (result vector))
"Evaluate the velocity of the object at a given time"
(set! (-> result quad) (-> this initial-velocity quad))
(+! (-> result y) (* time (-> this gravity)))
result)
(defmethod setup-from-to-duration! ((this trajectory) (from vector) (to vector) (duration float) (grav float))
"Set up a trajectory that goes from->to in the given duration"
(set! (-> this initial-position quad) (-> from quad))
(set! (-> this gravity) grav)
(set! (-> this time) duration)
;; the velocity we need in xz to make it in time
(let ((xz-vel (/ (vector-vector-xz-distance to from) duration)))
;; our velocity will point along from -> to
(vector-! (-> this initial-velocity) to from)
;; but have magnitude that we calculated above.
(vector-xz-normalize! (-> this initial-velocity) xz-vel))
;; solve for the y velocity that makes us land at the right height.
(set! (-> this initial-velocity y) (- (/ (- (-> to y) (-> from y)) duration) (* 0.5 duration (-> this gravity))))
0
(none))
(defmethod setup-from-to-xz-vel! ((this trajectory) (from vector) (to vector) (xz-vel float) (grav float))
"Set up a trajectory that goes from->to with the given velocity"
;; just solve for the duration and use the previous
(let ((duration (/ (vector-vector-xz-distance to from) xz-vel))) (setup-from-to-duration! this from to duration grav))
0
(none))
(defmethod setup-from-to-y-vel! ((this trajectory) (from vector) (to vector) (y-vel float) (grav float))
"Set up a trajectory with the given initial y velocity."
(let* ((f0-0 y-vel)
(f1-3 (- (* f0-0 f0-0) (* 2.0 (- (-> from y) (-> to y)) grav)))
(f0-3 900.0))
(when (>= f1-3 0.0)
(let ((f0-4 (sqrtf f1-3))) (set! f0-3 (fmax (/ (- (- y-vel) f0-4) grav) (/ (+ (- y-vel) f0-4) grav)))))
(setup-from-to-duration! this from to f0-3 grav))
0
(none))
(defmethod setup-from-to-height! ((this trajectory) (arg0 vector) (arg1 vector) (arg2 float) (arg3 float))
"Setup a trajectory that reaches a given height"
(let* ((f1-2 (+ arg2 (fmax (-> arg0 y) (-> arg1 y))))
(f1-5 (* 2.0 (- (-> arg0 y) f1-2) arg3))
(f0-3 4096.0))
(if (< 0.0 f1-5) (set! f0-3 (sqrtf f1-5)))
(setup-from-to-y-vel! this arg0 arg1 f0-3 arg3))
0
(none))
(defmethod debug-draw! ((this trajectory))
"Draw the trajectory"
(let ((prev-pos (new 'stack-no-clear 'vector))
(pos (new 'stack-no-clear 'vector))
(num-segments 10))
(set! (-> pos quad) (-> this initial-position quad))
(dotimes (s2-0 num-segments)
(set! (-> prev-pos quad) (-> pos quad))
(let ((t-eval (* (-> this time) (/ (+ 1.0 (the float s2-0)) (the float num-segments)))))
(eval-position! this t-eval pos))
(add-debug-line #t (bucket-id debug-no-zbuf) prev-pos pos (new 'static 'rgba :r #xff :a #x80) #f (the-as rgba -1))))
0
(none))