mirror of
https://github.com/open-goal/jak-project
synced 2026-07-03 04:53:35 -04:00
c162c66118
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:  > 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: 
98 lines
3.8 KiB
Common Lisp
98 lines
3.8 KiB
Common Lisp
;;-*-Lisp-*-
|
|
(in-package goal)
|
|
(bundles "ENGINE.CGO" "GAME.CGO")
|
|
(require "engine/level/bsp.gc")
|
|
(require "engine/draw/draw-node-h.gc")
|
|
|
|
;; The "drawable tree" represents a BVH for a specific render.
|
|
;; Typically, levels will have ~10 drawable trees. There will be a tree for
|
|
;; tfrag, a tree for actors, a tree for tie,
|
|
|
|
;; This file contains common functions for all drawable trees.
|
|
|
|
;; DECOMP BEGINS
|
|
|
|
(defmethod draw ((this drawable-tree-array) (arg0 drawable-tree-array) (arg1 display-frame))
|
|
"Draw a drawable tree array. If the current level is set to special or special-vis, the draw is skipped."
|
|
(let ((v1-1 (-> (scratchpad-object terrain-context) bsp lev-index)))
|
|
(case (-> *level* level v1-1 display?)
|
|
(('special 'special-vis #f))
|
|
(else (dotimes (s3-0 (-> this length)) (draw (-> this trees s3-0) (-> arg0 trees s3-0) arg1)))))
|
|
0
|
|
(none))
|
|
|
|
(defmethod collect-stats ((this drawable-tree-array))
|
|
(dotimes (s5-0 (-> this length))
|
|
(collect-stats (-> this trees s5-0)))
|
|
0
|
|
(none))
|
|
|
|
(defmethod debug-draw ((this drawable-tree-array) (arg0 drawable) (arg1 display-frame))
|
|
(dotimes (s3-0 (-> this length))
|
|
(debug-draw (-> this trees s3-0) (-> (the-as drawable-tree-array arg0) trees s3-0) arg1))
|
|
0
|
|
(none))
|
|
|
|
(defmethod unpack-vis ((this drawable-tree) (arg0 (pointer int8)) (arg1 (pointer int8)))
|
|
"Copy our visibility data from arg1 to arg0, unpacking it."
|
|
(local-vars (t5-1 int))
|
|
;; grab the first array
|
|
(let* ((v1-0 (the-as drawable-inline-array-node (-> this data 0)))
|
|
;; first elt in top array
|
|
(a3-1 (/ (-> v1-0 data 0 id) 8))
|
|
;; number in first array (8 or fewer)
|
|
(t0-0 (-> v1-0 length))
|
|
;; offset in destination
|
|
(v1-1 (&+ arg0 a3-1))
|
|
;; number of bytes
|
|
(a3-3 (/ (+ t0-0 7) 8)))
|
|
;; copy the data!
|
|
;;(mem-print (the (pointer uint32) arg1) 10)
|
|
(dotimes (t0-1 a3-3)
|
|
(let ((t1-0 (-> arg1 0)))
|
|
;;(format 0 "top-copy: #x~X~%" t1-0)
|
|
(set! arg1 (&-> arg1 1))
|
|
(set! (-> v1-1 0) t1-0))
|
|
(set! v1-1 (&-> v1-1 1))))
|
|
;; now, the remaining arrays, excluding the final which isn't a draw node array.
|
|
(let ((v1-5 (+ (-> this length) -1)))
|
|
(when (nonzero? v1-5)
|
|
(dotimes (a3-5 v1-5)
|
|
;; pointer to this array
|
|
(let* ((t0-4 (-> this data a3-5))
|
|
;; pointer to next depth array
|
|
(t2-0 (-> this data (+ a3-5 1)))
|
|
;; id of first in prev
|
|
(t1-5 (/ (-> (the-as drawable-inline-array-node t0-4) data 0 id) 8))
|
|
;; id of first in next
|
|
(t2-2 (/ (-> (the-as drawable-inline-array-node t2-0) data 0 id) 8))
|
|
;; number of nodes in this one
|
|
(t0-5 (-> (the-as drawable-inline-array-node t0-4) length))
|
|
;; output for prev level
|
|
(t1-6 (&+ arg0 t1-5))
|
|
;; output for next level
|
|
(t2-3 (&+ arg0 t2-2)))
|
|
(while #t
|
|
;; load the vis byte for the one in this array
|
|
(let ((t3-0 (-> t1-6 0)))
|
|
;; inc vis ptr.
|
|
(set! t1-6 (&-> t1-6 1))
|
|
;; vis mask bit. (init at highest)
|
|
(let ((t4-0 128))
|
|
(label cfg-7)
|
|
;; check if we're visible
|
|
(b! (zero? (logand t3-0 t4-0)) cfg-9 :delay (set! t5-1 (-> arg1 0)))
|
|
;; we are visible. write 8 in the output
|
|
(set! arg1 (&-> arg1 1))
|
|
(set! (-> t2-3 0) t5-1)
|
|
(label cfg-9)
|
|
(+! t0-5 -1)
|
|
;; check if we've done all nodes
|
|
(b! (zero? t0-5) cfg-12 :delay (.sra t4-0 t4-0 1))
|
|
;; check if we're done with this byte and inc output.
|
|
(b! (nonzero? t4-0) cfg-7 :delay (set! t2-3 (&-> t2-3 1)))))))
|
|
(label cfg-12)
|
|
(nop!)
|
|
0)))
|
|
arg1)
|