jak-project/goal_src/jak2/engine/geometry/cylinder.gc
ManDude cd68cb671e
deftype and defmethod syntax major changes (#3094)
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>
2023-10-30 03:20:02 +00:00

285 lines
9.3 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
;; name: cylinder.gc
;; name in dgo: cylinder
;; dgos: ENGINE, GAME
;; DECOMP BEGINS
(defmethod ray-capsule-intersect ((this cylinder) (ray1 vector) (ray2 vector))
(let ((t2-0 (new 'stack-no-clear 'vector))
(s4-0 (new 'stack-no-clear 'vector))
)
0.0
0.0
(let ((f30-0
(ray-cylinder-intersect ray1 ray2 (-> this origin) (-> this axis) (-> this radius) (-> this length) t2-0)
)
)
(let ((f0-5 (ray-sphere-intersect ray1 ray2 (-> this origin) (-> this radius))))
(if (and (>= f0-5 0.0) (or (< f30-0 0.0) (< f0-5 f30-0)))
(set! f30-0 f0-5)
)
)
(vector+float*! s4-0 (-> this origin) (-> this axis) (-> this length))
(let ((f0-8 (ray-sphere-intersect ray1 ray2 s4-0 (-> this radius))))
(if (and (>= f0-8 0.0) (or (< f30-0 0.0) (< f0-8 f30-0)))
(set! f30-0 f0-8)
)
)
f30-0
)
)
)
(deftype cylinder-verts (structure)
((vert vector 24 :inline)
)
)
(defmethod debug-draw ((this cylinder) (arg0 vector4w))
(local-vars
(sv-896 matrix)
(sv-912 vector)
(sv-928 vector)
(sv-944 vector)
(sv-960 vector)
(sv-976 vector)
(sv-992 vector)
(sv-1008 vector)
(sv-1024 vector)
(sv-1040 vector)
(sv-1056 vector)
(sv-1072 vector)
(sv-1088 vector)
)
(rlet ((acc :class vf)
(vf0 :class vf)
(vf1 :class vf)
(vf2 :class vf)
(vf3 :class vf)
(vf4 :class vf)
(vf5 :class vf)
(vf6 :class vf)
)
(init-vf0-vector)
(let ((s1-0 (new 'stack-no-clear 'vector))
(s0-0 (new 'stack-no-clear 'vector))
)
(if (< 0.999 (fabs (-> this axis y)))
(vector-cross! s1-0 (-> this axis) (new 'static 'vector :z 1.0))
(vector-cross! s1-0 (-> this axis) (new 'static 'vector :y 1.0))
)
(vector-normalize! s1-0 (-> this radius))
(vector-float*! s0-0 (-> this axis) (* 0.125 (-> this length)))
(let ((s5-0 (new 'stack-no-clear 'cylinder-verts))
(s4-0 (new 'stack-no-clear 'cylinder-verts))
(s3-0 (new 'stack-no-clear 'matrix))
)
(matrix-axis-angle! s3-0 (-> this axis) 4096.0)
(set! sv-896 (new 'stack-no-clear 'matrix))
(vector-matrix*! (the-as vector sv-896) (-> this origin) s3-0)
(let ((v1-6 (-> s3-0 trans)))
(.lvf vf4 (&-> (-> this origin) quad))
(.lvf vf5 (&-> sv-896 quad 0))
(.mov.vf vf6 vf0 :mask #b1000)
(.sub.vf vf6 vf4 vf5 :mask #b111)
(.svf (&-> v1-6 quad) vf6)
)
(dotimes (v1-7 8)
(vector+! (-> s5-0 vert (+ v1-7 8)) (-> this origin) s1-0)
(vector+float*! (-> s5-0 vert (+ v1-7 8)) (-> s5-0 vert (+ v1-7 8)) s0-0 (the float v1-7))
)
(dotimes (s0-1 8)
(set! sv-944 (-> s5-0 vert s0-1))
(set! sv-912 (-> this origin))
(set! sv-928 s1-0)
(let ((f0-8 (cos (* 2048.0 (the float (- 7 s0-1))))))
(.lvf vf2 (&-> sv-928 quad))
(.lvf vf1 (&-> sv-912 quad))
(let ((v1-19 f0-8))
(.mov vf3 v1-19)
)
)
(.add.x.vf vf4 vf0 vf0 :mask #b1000)
(.mul.x.vf acc vf2 vf3)
(.add.mul.w.vf vf4 vf1 vf0 acc :mask #b111)
(.svf (&-> sv-944 quad) vf4)
(set! sv-992 (-> s5-0 vert s0-1))
(set! sv-960 (-> s5-0 vert s0-1))
(set! sv-976 (-> this axis))
(let ((f0-13 (* (- (-> this radius)) (sin (* 2048.0 (the float (- 7 s0-1)))))))
(.lvf vf2 (&-> sv-976 quad))
(.lvf vf1 (&-> sv-960 quad))
(let ((v1-33 f0-13))
(.mov vf3 v1-33)
)
)
(.add.x.vf vf4 vf0 vf0 :mask #b1000)
(.mul.x.vf acc vf2 vf3)
(.add.mul.w.vf vf4 vf1 vf0 acc :mask #b111)
(.svf (&-> sv-992 quad) vf4)
(set! sv-1040 (-> s5-0 vert (+ s0-1 16)))
(set! sv-1008 (-> this origin))
(set! sv-1024 s1-0)
(let ((f0-16 (cos (* 2048.0 (the float s0-1)))))
(.lvf vf2 (&-> sv-1024 quad))
(.lvf vf1 (&-> sv-1008 quad))
(let ((v1-43 f0-16))
(.mov vf3 v1-43)
)
)
(.add.x.vf vf4 vf0 vf0 :mask #b1000)
(.mul.x.vf acc vf2 vf3)
(.add.mul.w.vf vf4 vf1 vf0 acc :mask #b111)
(.svf (&-> sv-1040 quad) vf4)
(set! sv-1088 (-> s5-0 vert (+ s0-1 16)))
(set! sv-1056 (-> s5-0 vert (+ s0-1 16)))
(set! sv-1072 (-> this axis))
(let ((f0-21 (+ (-> this length) (* (-> this radius) (sin (* 2048.0 (the float s0-1)))))))
(.lvf vf2 (&-> sv-1072 quad))
(.lvf vf1 (&-> sv-1056 quad))
(let ((v1-57 f0-21))
(.mov vf3 v1-57)
)
)
(.add.x.vf vf4 vf0 vf0 :mask #b1000)
(.mul.x.vf acc vf2 vf3)
(.add.mul.w.vf vf4 vf1 vf0 acc :mask #b111)
(.svf (&-> sv-1088 quad) vf4)
)
(dotimes (s2-1 16)
(dotimes (s1-1 24)
(vector-matrix*! (-> s4-0 vert s1-1) (-> s5-0 vert s1-1) s3-0)
(camera-line (-> s5-0 vert s1-1) (-> s4-0 vert s1-1) arg0)
(if (nonzero? s1-1)
(camera-line (-> s5-0 vert s1-1) (-> s5-0 vert (+ s1-1 -1)) arg0)
)
)
(let ((v1-77 s5-0))
(set! s5-0 s4-0)
(set! s4-0 v1-77)
)
)
)
)
0
(none)
)
)
(defun ray-arbitrary-circle-intersect ((arg0 vector) (arg1 vector) (arg2 vector) (arg3 vector) (arg4 float))
(let* ((v1-1 (vector-! (new 'stack-no-clear 'vector) arg2 arg0))
(f0-2 (/ (vector-dot v1-1 arg3) (vector-dot arg1 arg3)))
)
(cond
((or (< 1.0 f0-2) (< f0-2 0.0))
-100000000.0
)
((let ((a0-8 (new 'stack-no-clear 'vector)))
(vector-float*! a0-8 arg1 f0-2)
(vector-! a0-8 a0-8 v1-1)
(< (vector-dot a0-8 a0-8) (* arg4 arg4))
)
f0-2
)
(else
-100000000.0
)
)
)
)
(defmethod ray-flat-cyl-intersect ((this cylinder-flat) (arg0 vector) (arg1 vector))
(let ((gp-0 (new 'stack-no-clear 'vector))
(s5-0 (new 'stack-no-clear 'vector))
)
0.0
0.0
(let ((f30-0
(ray-cylinder-intersect arg0 arg1 (-> this origin) (-> this axis) (-> this radius) (-> this length) gp-0)
)
)
(let ((f0-5 (ray-arbitrary-circle-intersect arg0 arg1 (-> this origin) (-> this axis) (-> this radius))))
(when (and (>= f0-5 0.0) (or (< f30-0 0.0) (< f0-5 f30-0)))
(set! f30-0 f0-5)
(set! (-> gp-0 quad) (-> this origin quad))
)
)
(vector+float*! s5-0 (-> this origin) (-> this axis) (-> this length))
(let ((f0-8 (ray-arbitrary-circle-intersect arg0 arg1 s5-0 (-> this axis) (-> this radius))))
(when (and (>= f0-8 0.0) (or (< f30-0 0.0) (< f0-8 f30-0)))
(set! f30-0 f0-8)
(set! (-> gp-0 quad) (-> s5-0 quad))
)
)
f30-0
)
)
)
(deftype cylinder-flat-verts (structure)
((vert vector 10 :inline)
)
)
(defmethod debug-draw ((this cylinder-flat) (arg0 vector4w))
(local-vars (sv-448 vector))
(rlet ((vf0 :class vf)
(vf4 :class vf)
(vf5 :class vf)
(vf6 :class vf)
)
(init-vf0-vector)
(let ((s1-0 (new 'stack-no-clear 'vector))
(s0-0 (new 'stack-no-clear 'vector))
)
(if (< 0.999 (fabs (-> this axis y)))
(vector-cross! s1-0 (-> this axis) (new 'static 'vector :z 1.0))
(vector-cross! s1-0 (-> this axis) (new 'static 'vector :y 1.0))
)
(vector-normalize! s1-0 (-> this radius))
(vector-float*! s0-0 (-> this axis) (* 0.14285715 (-> this length)))
(let ((s5-0 (new 'stack-no-clear 'cylinder-flat-verts))
(s4-0 (new 'stack-no-clear 'cylinder-flat-verts))
(s3-0 (new 'stack-no-clear 'matrix))
)
(matrix-axis-angle! s3-0 (-> this axis) 4096.0)
(set! sv-448 (new 'stack-no-clear 'vector))
(vector-matrix*! sv-448 (-> this origin) s3-0)
(let ((v1-6 (-> s3-0 trans)))
(.lvf vf4 (&-> (-> this origin) quad))
(.lvf vf5 (&-> sv-448 quad))
(.mov.vf vf6 vf0 :mask #b1000)
(.sub.vf vf6 vf4 vf5 :mask #b111)
(.svf (&-> v1-6 quad) vf6)
)
(dotimes (v1-7 8)
(vector+! (-> s5-0 vert (+ v1-7 1)) (-> this origin) s1-0)
(vector+float*! (-> s5-0 vert (+ v1-7 1)) (-> s5-0 vert (+ v1-7 1)) s0-0 (the float v1-7))
)
(set! (-> s5-0 vert 0 quad) (-> this origin quad))
(vector+float*! (-> s5-0 vert 9) (-> this origin) (-> this axis) (-> this length))
(dotimes (s2-1 16)
(dotimes (s1-1 10)
(vector-matrix*! (-> s4-0 vert s1-1) (-> s5-0 vert s1-1) s3-0)
(camera-line (-> s5-0 vert s1-1) (-> s4-0 vert s1-1) arg0)
(if (nonzero? s1-1)
(camera-line (-> s5-0 vert s1-1) (-> s5-0 vert (+ s1-1 -1)) arg0)
)
)
(let ((v1-29 s5-0))
(set! s5-0 s4-0)
(set! s4-0 v1-29)
)
)
)
)
0
(none)
)
)