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

110 lines
4.3 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
(bundles "ENGINE.CGO" "GAME.CGO")
(require "engine/level/bsp.gc")
(require "engine/draw/draw-node-h.gc")
;; DECOMP BEGINS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Draw Node Collisions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; The collision stuff is a bit weird.
;; The method takes an integer argument. For some types, you must provide a length and calling the method
;; will automatically run on all the brothers of the node. For other types, you don't have to provide a length.
;; The output of the collision are stored in the collide-list that's passed through all the methods.
;; For an unknown reason, the input to the collision query (the box we're colliding with) is not.
;; It's stored in *collide-work*
(defmethod collide-with-box ((this draw-node) (arg0 int) (arg1 collide-list))
"Find collisions with the box in the current collision query, add results to collide-list."
;; loop over ourself and our brothers
(dotimes (s3-0 arg0)
(if (collide-cache-using-box-test (-> this bsphere)) ;; do we collide with the bounding sphere?
;; if so, do the collision check with the geometry.
(collide-with-box (-> this child) (the-as int (-> this child-count)) arg1))
(&+! this 32))
0
(none))
(defmethod collide-y-probe ((this draw-node) (arg0 int) (arg1 collide-list))
(dotimes (s3-0 arg0)
(if (collide-cache-using-y-probe-test (-> this bsphere))
(collide-y-probe (-> this child) (the-as int (-> this child-count)) arg1))
(&+! this 32))
0
(none))
(defmethod collide-ray ((this draw-node) (arg0 int) (arg1 collide-list))
(dotimes (s3-0 arg0)
(if (collide-cache-using-line-sphere-test (-> this bsphere))
(collide-ray (-> this child) (the-as int (-> this child-count)) arg1))
(&+! this 32))
0
(none))
(defmethod collect-ambients ((this draw-node) (arg0 sphere) (arg1 int) (arg2 ambient-list))
(dotimes (s2-0 arg1)
(if (spheres-overlap? arg0 (the-as sphere (-> this bsphere)))
(collect-ambients (-> this child) arg0 (the-as int (-> this child-count)) arg2))
(&+! this 32))
0
(none))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Drawable Inline Array Node
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; This class is a convenient wrapper around an inline-array of draw-nodes.
;; It lets you treat this array like a normal drawable (at least for collisions).
(defmethod inspect ((this drawable-inline-array-node))
"Custom inspect for drawable-inline-array-node to print our nodes."
(format #t "[~8x] ~A~%" this (-> this type))
(format #t "~Tlength: ~D~%" (-> this length))
(format #t "~Tdata[~D]: @ #x~X~%" (-> this length) (-> this data))
(dotimes (s5-0 (-> this length))
(format #t "~T [~D] ~A~%" s5-0 (-> this data s5-0)))
this)
(defmethod mem-usage ((this drawable-inline-array-node) (arg0 memory-usage-block) (arg1 int))
"Compute the memory usage of a drawable-inline-array-node. Only counts the nodes, doesn't count the node children."
(set! (-> arg0 length) (max 62 (-> arg0 length)))
(set! (-> arg0 data 61 name) "draw-node")
(+! (-> arg0 data 61 count) (-> this length))
(let ((v1-6 (asize-of this))) (+! (-> arg0 data 61 used) v1-6) (+! (-> arg0 data 61 total) (logand -16 (+ v1-6 15))))
this)
(defmethod asize-of ((this drawable-inline-array-node))
(the-as int (+ (-> drawable-inline-array-node size) (* (+ (-> this length) -1) 32))))
(defmethod collide-with-box ((this drawable-inline-array-node) (arg0 int) (arg1 collide-list))
;; call on the first in the array, then it will loop through all the brothers.
(collide-with-box (the-as drawable (-> this data)) (-> this length) arg1)
0
(none))
(defmethod collide-y-probe ((this drawable-inline-array-node) (arg0 int) (arg1 collide-list))
(collide-y-probe (the-as drawable (-> this data)) (-> this length) arg1)
0
(none))
(defmethod collide-ray ((this drawable-inline-array-node) (arg0 int) (arg1 collide-list))
(collide-ray (the-as drawable (-> this data)) (-> this length) arg1)
0
(none))
(defmethod collect-ambients ((this drawable-inline-array-node) (arg0 sphere) (arg1 int) (arg2 ambient-list))
(collect-ambients (the-as drawable (-> this data)) arg0 (-> this length) arg2)
0
(none))
;;;;;;;;;;;;;;;;;;;;;;;;
;; DRAW NODE CULL
;;;;;;;;;;;;;;;;;;;;;;;;
;; TODO: waiting on tfrag/tie stuff to worry about this.
(define-extern draw-node-cull (function pointer pointer (inline-array draw-node) int none))