jak-project/goal_src/jak2/engine/collide/collide-mesh-h.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

118 lines
3 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
;; name: collide-mesh-h.gc
;; name in dgo: collide-mesh-h
;; dgos: ENGINE, GAME
(declare-type collide-mesh-cache-tri structure)
(declare-type collide-shape-prim-mesh basic)
;; DECOMP BEGINS
(deftype collide-tri-result (structure)
((vertex vector 3 :inline)
(intersect vector :inline)
(normal vector :inline)
(pat pat-surface)
(collide-ptr basic)
)
)
(deftype collide-mesh-tri (structure)
((vertex-index uint8 3)
(unused uint8)
(pat pat-surface)
)
:pack-me
)
(deftype collide-mesh (basic)
((joint-id int32)
(num-tris uint32)
(num-verts uint32)
(vertex-data (inline-array vector))
(tris collide-mesh-tri 1 :inline :offset 32)
)
(:methods
(debug-draw-tris (_type_ process-drawable int) none)
(overlap-test (_type_ collide-mesh-cache-tri vector) symbol)
(should-push-away-test (_type_ collide-mesh-cache-tri collide-tri-result vector float) float)
(sphere-on-platform-test (_type_ collide-mesh-cache-tri collide-tri-result vector float) float)
(unpack-mesh-to-cache! (_type_ (inline-array collide-mesh-cache-tri) matrix) none)
(collide-mesh-math-1 (_type_ object object) none)
(collide-mesh-math-2 (_type_ object object object) none)
)
)
(deftype collide-mesh-cache-tri (structure)
((vertex vector 3 :inline)
(normal vector :inline)
(bbox4w bounding-box4w :inline)
(pat pat-surface :overlay-at (-> normal data 3))
)
)
(deftype collide-mesh-cache-entry (structure)
((mat matrix :inline)
(tris collide-mesh-cache-tri :inline :dynamic)
)
)
(deftype collide-mesh-cache (basic)
((used-size uint32)
(max-size uint32)
(id uint32)
(data uint8 48000)
)
(:methods
(populate-for-prim-mesh (_type_ collide-shape-prim-mesh) collide-mesh-cache-entry)
(is-id? (_type_ int) symbol)
(next-id! (_type_) uint)
(allocate! (_type_ int) collide-mesh-cache-entry)
)
)
(defmethod next-id! ((this collide-mesh-cache))
"Reset all used entries in the cache and increment the id.
If the id is zero, set it to 1"
;; ld v1, 12(a0)
(let ((v1 (-> this id)))
;; sw r0, 0(a0)
(set! (-> this used-size) 0)
;; daddiu v0, v1, 1
(let ((v0 (+ v1 1)))
;; beql v0, r0, L3
;; addiu v0, r0, 1 (only taken if v0 = 0)
(if (= v0 0)
(set! v0 (the uint 1))
)
;; L3:
;; sd v0, 12(a0)
(set! (-> this id) v0)
v0
)
)
)
(defmethod is-id? ((this collide-mesh-cache) (arg0 int))
(= (-> this id) arg0)
)
(kmemopen global "collide-mesh-cache")
(define-perm *collide-mesh-cache* collide-mesh-cache (new 'global 'collide-mesh-cache))
(set! (-> *collide-mesh-cache* id) (the-as uint 1))
(set! (-> *collide-mesh-cache* used-size) (the-as uint 0))
(set! (-> *collide-mesh-cache* max-size) (the-as uint #xbb80))
(kmemclose)