mirror of
https://github.com/open-goal/jak-project
synced 2026-08-11 03:26:33 -04:00
cd68cb671e
Major change to how `deftype` shows up in our code: - the decompiler will no longer emit the `offset-assert`, `method-count-assert`, `size-assert` and `flag-assert` parameters. There are extremely few cases where having this in the decompiled code is helpful, as the types there come from `all-types` which already has those parameters. This also doesn't break type consistency because: - the asserts aren't compared. - the first step of the test uses `all-types`, which has the asserts, which will throw an error if they're bad. - the decompiler won't emit the `heap-base` parameter unless necessary now. - the decompiler will try its hardest to turn a fixed-offset field into an `overlay-at` field. It falls back to the old offset if all else fails. - `overlay-at` now supports field "dereferencing" to specify the offset that's within a field that's a structure, e.g.: ```lisp (deftype foobar (structure) ((vec vector :inline) (flags int32 :overlay-at (-> vec w)) ) ) ``` in this structure, the offset of `flags` will be 12 because that is the final offset of `vec`'s `w` field within this structure. - **removed ID from all method declarations.** IDs are only ever automatically assigned now. Fixes #3068. - added an `:overlay` parameter to method declarations, in order to declare a new method that goes on top of a previously-defined method. Syntax is `:overlay <method-name>`. Please do not ever use this. - added `state-methods` list parameter. This lets you quickly specify a list of states to be put in the method table. Same syntax as the `states` list parameter. The decompiler will try to put as many states in this as it can without messing with the method ID order. Also changes `defmethod` to make the first type definition (before the arguments) optional. The type can now be inferred from the first argument. Fixes #3093. --------- Co-authored-by: Hat Kid <6624576+Hat-Kid@users.noreply.github.com>
254 lines
8.7 KiB
Common Lisp
254 lines
8.7 KiB
Common Lisp
;;-*-Lisp-*-
|
|
(in-package goal)
|
|
|
|
;; name: height-map.gc
|
|
;; name in dgo: height-map
|
|
;; dgos: CWI
|
|
|
|
;; DECOMP BEGINS
|
|
|
|
(defmethod debug-print ((this xz-height-map))
|
|
(format #t "(define *traffic-height-map*~%")
|
|
(format #t " (static-height-map~%")
|
|
(format
|
|
#t
|
|
" :offset ((meters ~M) (meters ~M) (meters ~M))~%"
|
|
(-> this x-offset)
|
|
(-> this y-offset)
|
|
(-> this z-offset)
|
|
)
|
|
(format #t " :x-spacing (meters ~M)~%" (/ 1.0 (-> this x-inv-spacing)))
|
|
(format #t " :z-spacing (meters ~M)~%" (/ 1.0 (-> this z-inv-spacing)))
|
|
(format #t " :y-scale (meters ~M)~%" (-> this y-scale))
|
|
(format #t " :x-dim ~d~%" (-> this x-dim))
|
|
(format #t " :z-dim ~d~%" (-> this z-dim))
|
|
(format #t " :data~%")
|
|
(format #t " (~%")
|
|
(let ((s5-0 0))
|
|
(dotimes (s4-0 (-> this z-dim))
|
|
(dotimes (s3-0 (-> this x-dim))
|
|
(format #t " ~2d" (-> this data s5-0))
|
|
(+! s5-0 1)
|
|
)
|
|
(format #t "~%")
|
|
)
|
|
)
|
|
(format #t "~T)~%")
|
|
(format #t " )~%")
|
|
(format #t " )~%~%")
|
|
0
|
|
(none)
|
|
)
|
|
|
|
(defmethod debug-add-offset ((this xz-height-map) (arg0 vector) (arg1 int))
|
|
"Add an offset to the given point, likely for debugging purposes."
|
|
(let ((v1-1 (the int (+ 0.5 (* (- (-> arg0 x) (-> this x-offset)) (-> this x-inv-spacing)))))
|
|
(a1-1 (the int (+ 0.5 (* (- (-> arg0 z) (-> this z-offset)) (-> this z-inv-spacing)))))
|
|
)
|
|
(when (and (>= v1-1 0) (< v1-1 (-> this x-dim)) (>= a1-1 0) (< a1-1 (-> this z-dim)))
|
|
(let ((v1-2 (+ v1-1 (* a1-1 (-> this x-dim)))))
|
|
(+! (-> this data v1-2) arg1)
|
|
)
|
|
)
|
|
)
|
|
0
|
|
(none)
|
|
)
|
|
|
|
(defmethod debug-draw-at-point ((this xz-height-map) (arg0 vector))
|
|
(let ((v1-1 (the int (+ 0.5 (* (- (-> arg0 x) (-> this x-offset)) (-> this x-inv-spacing)))))
|
|
(a1-1 (the int (+ 0.5 (* (- (-> arg0 z) (-> this z-offset)) (-> this z-inv-spacing)))))
|
|
(a2-1 (-> this x-dim))
|
|
(a3-0 (-> this z-dim))
|
|
)
|
|
(when (and (>= v1-1 0) (< v1-1 a2-1) (>= a1-1 0) (< a1-1 a3-0))
|
|
(let* ((a2-3 (+ v1-1 (* a1-1 a2-1)))
|
|
(gp-0 (-> this data a2-3))
|
|
(s5-0 (new 'stack-no-clear 'vector))
|
|
)
|
|
(set! (-> s5-0 x) (+ (-> this x-offset) (/ (the float v1-1) (-> this x-inv-spacing))))
|
|
(set! (-> s5-0 y) 0.0)
|
|
(set! (-> s5-0 z) (+ (-> this z-offset) (/ (the float a1-1) (-> this z-inv-spacing))))
|
|
(set! (-> s5-0 y) (get-height-at-point this s5-0))
|
|
(let ((s4-0 add-debug-text-3d)
|
|
(s3-0 #t)
|
|
(s2-0 318)
|
|
)
|
|
(format (clear *temp-string*) "~D" gp-0)
|
|
(s4-0
|
|
s3-0
|
|
(the-as bucket-id s2-0)
|
|
*temp-string*
|
|
s5-0
|
|
(font-color white)
|
|
(new 'static 'vector2h :data (new 'static 'array int16 2 0 16))
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
0
|
|
(none)
|
|
)
|
|
|
|
(defmethod get-height-at-point ((this xz-height-map) (arg0 vector))
|
|
(let* ((f0-1 (fmax 0.0 (* (-> this x-inv-spacing) (- (-> arg0 x) (-> this x-offset)))))
|
|
(f2-4 (fmax 0.0 (* (-> this z-inv-spacing) (- (-> arg0 z) (-> this z-offset)))))
|
|
(a2-0 (the int f0-1))
|
|
(a1-1 (the int f2-4))
|
|
(f1-7 (- f0-1 (the float a2-0)))
|
|
(f0-4 (- f2-4 (the float a1-1)))
|
|
(v1-0 (-> this x-dim))
|
|
(a3-0 (-> this z-dim))
|
|
(a1-7
|
|
(the-as
|
|
(pointer int8)
|
|
(+ (+ (min a2-0 (+ v1-0 -2)) (* (min a1-1 (+ a3-0 -2)) v1-0) 0) (the-as int (the-as pointer (-> this data))))
|
|
)
|
|
)
|
|
(f3-3 (the float (-> a1-7 0)))
|
|
(f4-1 (the float (-> a1-7 1)))
|
|
(f2-8 (the float (-> a1-7 v1-0)))
|
|
(f5-1 (the float (-> a1-7 (+ v1-0 1))))
|
|
(f3-5 (+ (* f3-3 (- 1.0 f1-7)) (* f4-1 f1-7)))
|
|
(f1-9 (+ (* f2-8 (- 1.0 f1-7)) (* f5-1 f1-7)))
|
|
)
|
|
(+ (* (+ (* f3-5 (- 1.0 f0-4)) (* f1-9 f0-4)) (-> this y-scale)) (-> this y-offset))
|
|
)
|
|
)
|
|
|
|
(defun point-in-bbox? ((arg0 bounding-box) (arg1 vector))
|
|
(and (>= (-> arg1 x) (-> arg0 min x))
|
|
(>= (-> arg1 y) (-> arg0 min y))
|
|
(>= (-> arg1 z) (-> arg0 min z))
|
|
(>= (-> arg0 max x) (-> arg1 x))
|
|
(>= (-> arg0 max y) (-> arg1 y))
|
|
(>= (-> arg0 max z) (-> arg1 z))
|
|
)
|
|
)
|
|
|
|
(defmethod debug-draw-mesh ((this xz-height-map) (arg0 vector))
|
|
(local-vars (sv-80 int) (sv-96 int))
|
|
(rlet ((vf0 :class vf))
|
|
(init-vf0-vector)
|
|
(let ((s5-0 (new 'stack-no-clear 'matrix)))
|
|
(mem-copy! (the-as pointer (-> s5-0 vector 2)) (the-as pointer arg0) 32)
|
|
(.svf (&-> (-> s5-0 vector) 0 quad) vf0)
|
|
(let ((f30-0 (/ 1.0 (-> this z-inv-spacing)))
|
|
(f28-0 (/ 1.0 (-> this x-inv-spacing)))
|
|
(s4-0 (-> this x-dim))
|
|
(s3-0 (-> this z-dim))
|
|
)
|
|
(let ((s2-0 (&-> (-> this data) 0)))
|
|
(set! (-> s5-0 vector 0 z) (-> this z-offset))
|
|
(countdown (s1-0 s3-0)
|
|
(let ((s0-0 s2-0))
|
|
(set! (-> s5-0 vector 0 x) (-> this x-offset))
|
|
(set! (-> s5-0 vector 0 y) (+ (-> this y-offset) (* (the float (-> s0-0 0)) (-> this y-scale))))
|
|
(set! sv-80 (+ s4-0 -1))
|
|
(while (nonzero? sv-80)
|
|
(set! sv-80 (+ sv-80 -1))
|
|
(set! (-> s5-0 vector 1 quad) (-> s5-0 vector 0 quad))
|
|
(+! (-> s5-0 vector 0 x) f28-0)
|
|
(set! s0-0 (&-> s0-0 1))
|
|
(set! (-> s5-0 vector 0 y) (+ (-> this y-offset) (* (the float (-> s0-0 0)) (-> this y-scale))))
|
|
(if (and (point-in-bbox? (the-as bounding-box (-> s5-0 vector 2)) (the-as vector (-> s5-0 vector)))
|
|
(point-in-bbox? (the-as bounding-box (-> s5-0 vector 2)) (-> s5-0 vector 1))
|
|
)
|
|
(add-debug-line
|
|
#t
|
|
(bucket-id debug2)
|
|
(the-as vector (-> s5-0 vector))
|
|
(-> s5-0 vector 1)
|
|
*color-red*
|
|
#f
|
|
(the-as rgba -1)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
(+! (-> s5-0 vector 0 z) f30-0)
|
|
(&+! s2-0 s4-0)
|
|
)
|
|
)
|
|
(let ((s2-1 (&-> (-> this data) 0)))
|
|
(set! (-> s5-0 vector 0 x) (-> this x-offset))
|
|
(countdown (s1-1 s4-0)
|
|
(let ((s0-1 (the-as pointer s2-1)))
|
|
(set! (-> s5-0 vector 0 z) (-> this z-offset))
|
|
(set! (-> s5-0 vector 0 y)
|
|
(+ (-> this y-offset) (* (the float (-> (the-as (pointer int8) s0-1) 0)) (-> this y-scale)))
|
|
)
|
|
(set! sv-96 (+ s3-0 -1))
|
|
(while (nonzero? sv-96)
|
|
(set! sv-96 (+ sv-96 -1))
|
|
(set! (-> s5-0 vector 1 quad) (-> s5-0 vector 0 quad))
|
|
(+! (-> s5-0 vector 0 z) f30-0)
|
|
(&+! s0-1 s4-0)
|
|
(set! (-> s5-0 vector 0 y)
|
|
(+ (-> this y-offset) (* (the float (-> (the-as (pointer int8) s0-1))) (-> this y-scale)))
|
|
)
|
|
(if (and (point-in-bbox? (the-as bounding-box (-> s5-0 vector 2)) (the-as vector (-> s5-0 vector)))
|
|
(point-in-bbox? (the-as bounding-box (-> s5-0 vector 2)) (-> s5-0 vector 1))
|
|
)
|
|
(add-debug-line
|
|
#t
|
|
(bucket-id debug2)
|
|
(the-as vector (-> s5-0 vector))
|
|
(-> s5-0 vector 1)
|
|
*color-blue*
|
|
#f
|
|
(the-as rgba -1)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
(+! (-> s5-0 vector 0 x) f28-0)
|
|
(set! s2-1 (&-> s2-1 1))
|
|
)
|
|
)
|
|
)
|
|
)
|
|
0
|
|
(none)
|
|
)
|
|
)
|
|
|
|
(defmethod debug-draw ((this xz-height-map) (arg0 vector))
|
|
(rlet ((vf0 :class vf)
|
|
(vf4 :class vf)
|
|
(vf5 :class vf)
|
|
(vf6 :class vf)
|
|
)
|
|
(init-vf0-vector)
|
|
(let ((v1-0 (new 'stack-no-clear 'vector4w-2)))
|
|
(let ((a1-1 (-> v1-0 vector)))
|
|
(let ((a0-1 arg0))
|
|
(let ((a2-1 -573440.0))
|
|
(.mov vf6 a2-1)
|
|
)
|
|
(.lvf vf4 (&-> a0-1 quad))
|
|
)
|
|
(.add.x.vf vf5 vf0 vf0 :mask #b1000)
|
|
(.add.x.vf vf5 vf4 vf6 :mask #b111)
|
|
(.svf (&-> a1-1 0 quad) vf5)
|
|
)
|
|
(let ((a1-2 (-> v1-0 vector 1)))
|
|
(let ((a0-2 arg0))
|
|
(let ((a2-3 573440.0))
|
|
(.mov vf6 a2-3)
|
|
)
|
|
(.lvf vf4 (&-> a0-2 quad))
|
|
)
|
|
(.add.x.vf vf5 vf0 vf0 :mask #b1000)
|
|
(.add.x.vf vf5 vf4 vf6 :mask #b111)
|
|
(.svf (&-> a1-2 quad) vf5)
|
|
)
|
|
(debug-draw-mesh this (the-as vector (-> v1-0 vector)))
|
|
)
|
|
(debug-draw-at-point this arg0)
|
|
0
|
|
(none)
|
|
)
|
|
)
|