Files
jak-project/goal_src/jak2/engine/math/transform.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

80 lines
2.6 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
;; name: transform.gc
;; name in dgo: transform
;; dgos: ENGINE, GAME
;; DECOMP BEGINS
(defmethod print ((this transform))
"Print a transform."
(format #t "#<transform @ #x~X~%" this)
(format #t "~T~Ttrans:~F ~F ~F ~F ~%" (-> this trans x) (-> this trans y) (-> this trans z) (-> this trans w))
(format #t "~T~Trot: ~F ~F ~F ~F ~%" (-> this rot x) (-> this rot y) (-> this rot z) (-> this rot w))
(format #t "~T~Tscale:~F ~F ~F ~F>" (-> this scale x) (-> this scale y) (-> this scale z) (-> this scale w))
this
)
(defmethod new trs ((allocation symbol) (type-to-make type))
"Allocate a new transform and set to identity."
(let ((gp-0 (object-new allocation type-to-make (the-as int (-> type-to-make size)))))
(set! (-> gp-0 trans w) 1.0)
(set! (-> gp-0 rot w) 1.0)
(vector-identity! (-> gp-0 scale))
gp-0
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;
;; transform utilities
;;;;;;;;;;;;;;;;;;;;;;;;;;
;; these functions are unused and possibly extremely old.
;; they aren't very efficient, and have the destination as the 2nd argument,
;; which differens from almost all other GOAL code.
(defun transform-matrix-calc! ((arg0 transform) (arg1 matrix))
"Convert a transform to matrix. Not efficient, and the output is the second arg."
(let ((s4-0 (new-stack-matrix0))
(s3-0 (new-stack-matrix0))
)
(matrix-identity! arg1)
(matrix-translate! arg1 (-> arg0 trans))
(matrix-rotate-y! s4-0 (-> arg0 rot y))
(matrix*! s3-0 s4-0 arg1)
(matrix-rotate-x! s4-0 (-> arg0 rot x))
(matrix*! arg1 s4-0 s3-0)
(matrix-rotate-z! s4-0 (-> arg0 rot z))
(matrix*! s3-0 s4-0 arg1)
(matrix-scale! s4-0 (-> arg0 scale))
(matrix*! arg1 s4-0 s3-0)
)
)
(defun transform-matrix-parent-calc! ((arg0 transform) (arg1 matrix) (arg2 vector))
"Convert a transform to a matrix, applying an inverse scaling."
(let ((s4-0 (new-stack-matrix0))
(s3-0 (new-stack-matrix0))
)
(matrix-identity! s3-0)
(matrix-translate! s3-0 (-> arg0 trans))
(matrix-inv-scale! s4-0 arg2)
(matrix*! arg1 s4-0 s3-0)
(matrix-rotate-y! s4-0 (-> arg0 rot y))
(matrix*! s3-0 s4-0 arg1)
(matrix-rotate-x! s4-0 (-> arg0 rot x))
(matrix*! arg1 s4-0 s3-0)
(matrix-rotate-z! s4-0 (-> arg0 rot z))
(matrix*! s3-0 s4-0 arg1)
(matrix-scale! s4-0 (-> arg0 scale))
(matrix*! arg1 s4-0 s3-0)
)
)
(defun trs-matrix-calc! ((arg0 trs) (arg1 matrix))
"Convert a trs to a matrix"
;; this relies on the fact that trs and transform both have the same memory layout.
(transform-matrix-calc! (the-as transform (-> arg0 trans)) arg1)
)