Files
jak-project/goal_src/jak2/engine/collide/collide-shape-h.gc
T
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

656 lines
22 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
;; name: collide-shape-h.gc
;; name in dgo: collide-shape-h
;; dgos: ENGINE, GAME
(declare-type collide-shape trsqv)
(declare-type collide-shape-moving collide-shape)
(declare-type control-info collide-shape-moving)
(declare-type touching-list structure)
(declare-type collide-query structure)
(declare-type water-info structure)
(declare-type collide-shape-prim-group basic)
(declare-type collide-cache-prim structure)
(declare-type collide-shape-prim basic)
(declare-type collide-cache basic)
(declare-type rigid-body structure)
(defenum collide-spec
:bitfield #t
:type uint32
(backgnd 0) ;; 1
(jak 1) ;; 2
(bot 2) ;; 4
(crate 3) ;; 8
(civilian 4) ;; 16
(enemy 5) ;; 32
(obstacle 6) ;; 64
(vehicle-sphere 7) ;; 128
(hit-by-player-list 8) ;; 256
(hit-by-others-list 9) ;; 512
(player-list 10) ;; 1024
(water 11) ;; 2048
(collectable 12) ;; 4096
(blocking-plane 13) ;; 8192
(projectile 14) ;; 16384
(jak-vulnerable 15) ;; 32768
(camera-blocker 16) ;; hi 1
(notice-blue-eco-powerup 17) ;; hi 2
(tobot 18) ;; hi 4
(pusher 19) ;; hi 8
(vehicle-mesh 20) ;; hi 16
(bot-targetable 21) ;; hi 32
(jak-vehicle 22) ;; hi 64
(special-obstacle 23) ;; hi 128
(mech-punch 24) ;; hi 256
(obstacle-for-jak 25) ;; hi 512
(vehicle-mesh-probeable 26) ;; hi 1024
(unknown-27 27)
(unknown-28 28)
(unknown-29 29)
(unknown-30 30)
(unknown-31 31)
(unknown-32 32)
(unknown-33 33)
(unknown-34 34)
(unknown-35 35)
(unknown-36 36)
(unknown-37 37)
(unknown-38 38)
(unknown-39 39)
(unknown-40 40)
(unknown-41 41)
(unknown-42 42)
(unknown-43 43)
(unknown-44 44)
(unknown-45 45)
(unknown-46 46)
(unknown-47 47)
(unknown-48 48)
(unknown-49 49)
(unknown-50 50)
(unknown-51 51)
(unknown-52 52)
(unknown-53 53)
(unknown-54 54)
(unknown-55 55)
(unknown-56 56)
(unknown-57 57)
(unknown-58 58)
(unknown-59 59)
(unknown-60 60)
(unknown-61 61)
(unknown-62 62)
(unknown-63 63)
)
(defenum collide-action
:bitfield #t
:type uint32
(solid 0) ;; 1
(semi-solid 1) ;; 2
(rideable 2) ;; 4
(can-ride 3) ;; 8
(dont-push-away 4) ;; 16
(pull-rider-can-collide 5) ;; 32
(deadly 6) ;; 64
(persistent-attack 7) ;; 128
(no-smack 8) ;; 256
(no-standon 9) ;; 512
(block-turn-around 10) ;; 1024
(check-edge 11) ;; 2048
(check-stuck 12) ;; 4096
(stuck-wall-escape 13) ;; 8192
(no-normal-reset 14) ;; 163884
(edge-grabbed 15) ;; 32768
(nav-sphere 16) ;; hi 1
)
(defenum overlaps-others-options
:type uint32
:bitfield #t
(oo0)
(oo1)
(oo2)
(oo3)
(oo4)
)
(defenum prim-type
:type int8
(prim -2)
(sphere -1)
(group 0)
(mesh 1)
(fake-prim 2)
)
(defenum cshape-moving-flags
:bitfield #t
:type uint64
(on-surface 0)
(on-ground 1)
(t-surface 2)
(t-wall 3)
(t-ceil 4)
(t-act 5)
(csmf06)
(csmf07)
(csmf08)
(csmf09)
(on-water 10)
(csmf11)
(csmf12)
(csmf13)
(csmf14)
(csmf15)
(csmf16)
(csmf17)
(csmf18)
(csmf19)
(csmf20)
(csmf21)
(csmf22)
(csmf23)
(csmf24)
(csmf25)
(csmf26)
(csmf27)
(csmf28)
(csmf29)
)
(defenum cshape-reaction-flags
:bitfield #t
:type uint32
(csrf00)
(csrf01)
(csrf02)
(csrf03)
(csrf04)
(csrf05)
(csrf06)
(csrf07)
(csrf08)
(csrf09)
(csrf10)
(csrf11)
(csrf12)
(csrf13)
(csrf14)
(csrf15)
(csrf16)
(csrf17)
(csrf18)
(csrf19)
(csrf20)
(csrf21)
(csrf22)
(csrf23)
(csrf24)
(csrf25)
(csrf26)
(csrf27)
(csrf28)
(csrf29)
(csrf30)
(csrf31)
)
(defenum collide-list-enum
(hit-by-player)
(usually-hit-by-player)
(hit-by-others)
(player)
)
(defenum collide-status
:bitfield #t
:type uint64
(on-surface 0)
(on-ground 1)
(touch-surface 2)
(touch-wall 3)
(touch-ceiling 4)
(touch-actor 5)
(on-special-surface 6)
(touch-edge 7)
(no-touch 8)
(blocked 9)
(on-water 10)
(impact-surface 11)
(touch-background 12)
(stuck 13)
(touch-ceiling-sticky 14)
(glance 15)
(probe-hit 16)
)
;; +++nav-flags
(defenum nav-flags
:type uint8
:bitfield #t
(has-root-sphere 0)
(has-extra-sphere 1)
(has-child-spheres 2)
)
;; ---nav-flags
(define-extern cshape-reaction-update-state (function control-info collide-query vector none))
(define-extern cshape-reaction-default (function control-info collide-query vector vector collide-status))
(define-extern cshape-reaction-just-move (function control-info collide-query vector collide-status))
;; DECOMP BEGINS
(deftype collide-rider (structure)
((rider-handle handle)
(sticky-prim collide-shape-prim)
(prim-ry float)
(rider-local-pos vector :inline)
)
)
(deftype collide-rider-pool (basic)
((alloc-count int32)
(riders collide-rider 20 :inline)
)
(:methods
(add-rider (_type_ handle) collide-rider)
(prepare (_type_) none)
)
)
(defmethod prepare ((this collide-rider-pool))
"Gets this pool ready to be used to allow allocations. This should be called once at the start of every frame."
(set! (-> this alloc-count) 0)
0
(none)
)
(deftype pull-rider-info (structure)
((rider collide-rider)
(rider-cshape collide-shape-moving)
(rider-delta-ry float)
(rider-dest vector :inline)
)
)
(kmemopen global "collide-lists")
(define *collide-hit-by-player-list* (new 'global 'engine 'collide-hit-by-player-list (* 640 PROCESS_HEAP_MULT) connection))
(define *collide-hit-by-others-list* (new 'global 'engine 'collide-hit-by-others-list (* 768 PROCESS_HEAP_MULT) connection))
(define *collide-player-list* (new 'global 'engine 'collide-player-list 32 connection))
(kmemclose)
(deftype overlaps-others-params (structure)
((options overlaps-others-options)
(collide-with-filter collide-spec)
(tlist touching-list)
(filtered-root-collide-with collide-spec)
(filtered-child-collide-with collide-spec)
(filtered-other-collide-as collide-spec)
)
)
(deftype move-above-ground-params (structure)
((gnd-collide-with collide-spec)
(popup float)
(dont-move-if-overlaps? symbol)
(hover-if-no-ground? symbol)
(overlaps-params overlaps-others-params :inline)
(new-pos vector :inline)
(old-gspot-pos vector :inline)
(old-gspot-normal vector :inline)
(pat pat-surface)
(on-ground? symbol)
(do-move? symbol)
)
)
(deftype collide-prim-core (structure)
((world-sphere vector :inline)
(collide-as collide-spec :offset 16)
(collide-with collide-spec)
(action collide-action)
(prim-type prim-type)
(unused1 uint8 3)
(quad uint128 2 :overlay-at (-> world-sphere data 0))
)
)
(deftype collide-shape-prim (basic)
((cshape collide-shape)
(prim-id uint32)
(transform-index int8)
(unused2 int8 3)
(prim-core collide-prim-core :inline)
(local-sphere vector :inline)
(world-sphere vector :inline :overlay-at (-> prim-core world-sphere))
(collide-as collide-spec :overlay-at (-> prim-core collide-as))
(collide-with collide-spec :overlay-at (-> prim-core collide-with))
(action collide-action :overlay-at (-> prim-core action))
(prim-type int8 :overlay-at (-> prim-core prim-type))
(radius float :overlay-at (-> local-sphere data 3))
(specific uint8 16)
)
(:methods
(new (symbol type collide-shape uint int) _type_)
(debug-draw (_type_) none)
(add-fg-prim-using-box (_type_ collide-cache) none)
(add-fg-prim-using-line-sphere (_type_ collide-cache object) none)
(overlaps-others-test (_type_ overlaps-others-params collide-shape-prim) symbol)
(overlaps-others-group (_type_ overlaps-others-params collide-shape-prim-group) symbol)
(collide-shape-prim-method-14 () none)
(collide-with-collide-cache-prim-mesh (_type_ collide-query collide-cache-prim) none)
(collide-with-collide-cache-prim-sphere (_type_ collide-query collide-cache-prim) none)
(on-platform-test (_type_ collide-shape-prim collide-query float) none)
(should-push-away-test (_type_ collide-shape-prim collide-query) none)
(should-push-away-a-group-test (_type_ collide-shape-prim-group collide-query) none)
)
)
(deftype collide-shape-prim-sphere (collide-shape-prim)
((pat pat-surface :overlay-at (-> specific 0))
(nav-radius float :overlay-at (-> specific 4))
)
(:methods
(new (symbol type collide-shape uint) _type_)
)
)
(deftype collide-shape-prim-mesh (collide-shape-prim)
((mesh collide-mesh :overlay-at (-> specific 0))
(mesh-id int32 :overlay-at (-> specific 4))
(mesh-cache-id uint32 :overlay-at (-> specific 8))
(mesh-cache-entry collide-mesh-cache-entry :overlay-at (-> specific 12))
)
(:methods
(new (symbol type collide-shape uint uint) _type_)
)
)
(deftype collide-shape-prim-group (collide-shape-prim)
((num-children uint8 :overlay-at (-> specific 0))
(num-alloc-children uint8 :overlay-at (-> specific 1))
(child (inline-array collide-shape-prim) :overlay-at (-> specific 4))
)
(:methods
(new (symbol type collide-shape uint int) _type_)
)
)
(deftype collide-shape (trsqv)
((actor-hash-index int16 :offset 12)
(process process-drawable)
(max-iteration-count uint8)
(nav-flags nav-flags)
(total-prims uint8)
(num-riders uint8)
(pat-ignore-mask pat-surface)
(event-self symbol)
(event-other symbol)
(root-prim collide-shape-prim)
(riders (inline-array collide-rider))
(penetrate-using penetrate)
(penetrated-by penetrate)
(backup-collide-as collide-spec)
(backup-collide-with collide-spec)
(event-priority uint8)
(rider-max-momentum float)
)
(:methods
(new (symbol type process-drawable collide-list-enum) _type_)
(move-by-vector! (_type_ vector) none)
(move-to-point! (_type_ vector) none)
(debug-draw (_type_) none)
(fill-cache-for-shape (_type_ float collide-query) none)
(fill-cache-integrate-and-collide (_type_ vector collide-query meters) none)
(find-prim-by-id (_type_ uint) collide-shape-prim)
(find-prim-by-id-logtest (_type_ uint) collide-shape-prim)
(detect-riders! (_type_) symbol)
(build-bounding-box-for-shape (_type_ bounding-box float collide-spec) symbol)
(integrate-and-collide! (_type_ vector) none)
(find-collision-meshes (_type_) none)
(on-platform (_type_ collide-shape collide-query) symbol)
(find-overlapping-shapes (_type_ overlaps-others-params) symbol)
(shove-to-closest-point-on-path (_type_ attack-info float) vector)
(should-push-away (_type_ collide-shape collide-query) symbol)
(pull-rider! (_type_ pull-rider-info) none)
(pull-riders! (_type_) symbol)
(do-push-aways (_type_) collide-spec)
(update-transforms (_type_) none)
(set-collide-with! (_type_ collide-spec) none)
(set-collide-as! (_type_ collide-spec) none)
(modify-collide-as! (_type_ int collide-spec collide-spec) none)
(send-shoves (_type_ process touching-shapes-entry float float float) symbol)
(above-ground? (_type_ collide-query vector collide-spec float float float) symbol)
(water-info-init! (_type_ water-info collide-action) water-info)
(iterate-prims (_type_ (function collide-shape-prim none)) none)
(pusher-init (_type_) none)
)
)
(deftype collide-shape-moving (collide-shape)
((rider-time time-frame)
(rider-last-move vector :inline)
(trans-old vector :inline)
(trans-old-old vector :inline :offset 240)
(trans-old-old-old vector :inline :offset 256)
(poly-pat pat-surface :offset 272)
(cur-pat pat-surface)
(ground-pat pat-surface)
(status collide-status)
(old-status collide-status)
(prev-status collide-status)
(reaction-flag cshape-reaction-flags)
(reaction (function control-info collide-query vector vector collide-status))
(no-reaction (function collide-shape-moving collide-query vector vector object))
(local-normal vector :inline)
(surface-normal vector :inline)
(poly-normal vector :inline)
(ground-poly-normal vector :inline)
(gspot-pos vector :inline)
(gspot-normal vector :inline)
(grount-touch-point vector :inline)
(ground-impact-vel meters)
(surface-angle float)
(poly-angle float)
(touch-angle float)
(coverage float)
(dynam dynamics)
(surf surface)
)
(:methods
(new (symbol type process-drawable collide-list-enum) _type_)
(find-ground (_type_ collide-query collide-spec float float float) symbol)
(react-to-pat! (_type_ pat-surface) cshape-reaction-flags)
(integrate-no-collide! (_type_ vector) none)
(integrate-for-enemy-no-mtg (_type_ vector overlaps-others-params) symbol)
(move-above-ground (_type_ vector move-above-ground-params) none)
(move-to-ground (_type_ float float symbol collide-spec) none)
(move-to-ground-point (_type_ vector vector vector) none)
(compute-acc-due-to-gravity (_type_ vector float) vector)
(collide-shape-moving-method-63 (_type_ rigid-body float) none)
(try-snap-to-surface (_type_ vector float float float) symbol)
(fill-and-try-snap-to-surface (_type_ vector float float float collide-query) symbol)
(step-collison! (_type_ vector vector float int) float)
(collide-with-all-collide-cache-prims (_type_ matrix collide-query) none)
)
)
(defmethod new collide-shape-prim ((allocation symbol) (type-to-make type) (arg0 collide-shape) (arg1 uint) (arg2 int))
(let ((v0-0 (object-new allocation type-to-make arg2)))
(set! (-> v0-0 cshape) arg0)
(set! (-> v0-0 prim-id) arg1)
(set! (-> v0-0 prim-core action) (collide-action))
(set! (-> v0-0 prim-core collide-as) (collide-spec))
(set! (-> v0-0 prim-core collide-with) (collide-spec))
(set! (-> v0-0 transform-index) -2)
(set! (-> v0-0 prim-core prim-type) (prim-type prim))
v0-0
)
)
;; WARN: Return type mismatch collide-shape-prim vs collide-shape-prim-sphere.
(defmethod new collide-shape-prim-sphere ((allocation symbol) (type-to-make type) (arg0 collide-shape) (arg1 uint))
(let ((v0-0 ((method-of-type collide-shape-prim new) allocation type-to-make arg0 arg1 80)))
(set! (-> (the-as collide-shape-prim-sphere v0-0) pat)
(new 'static 'pat-surface :mode (pat-mode obstacle) :material (pat-material stone))
)
(set! (-> (the-as collide-shape-prim-sphere v0-0) prim-core prim-type) (prim-type sphere))
(the-as collide-shape-prim-sphere v0-0)
)
)
;; WARN: Return type mismatch collide-shape-prim vs collide-shape-prim-mesh.
(defmethod new collide-shape-prim-mesh ((allocation symbol) (type-to-make type) (arg0 collide-shape) (arg1 uint) (arg2 uint))
(let ((v0-0 ((method-of-type collide-shape-prim new) allocation type-to-make arg0 arg2 80)))
(set! (-> (the-as collide-shape-prim-mesh v0-0) mesh) #f)
(set! (-> (the-as collide-shape-prim-mesh v0-0) mesh-id) (the-as int arg1))
(set! (-> (the-as collide-shape-prim-mesh v0-0) mesh-cache-id) (the-as uint 0))
(set! (-> (the-as collide-shape-prim-mesh v0-0) prim-core prim-type) (prim-type mesh))
(the-as collide-shape-prim-mesh v0-0)
)
)
;; WARN: Return type mismatch collide-shape-prim vs collide-shape-prim-group.
(defmethod new collide-shape-prim-group ((allocation symbol) (type-to-make type) (arg0 collide-shape) (arg1 uint) (arg2 int))
(let ((v0-0 ((method-of-type collide-shape-prim new) allocation type-to-make arg0 (the-as uint arg2) 80)))
(set! (-> (the-as collide-shape-prim-group v0-0) num-children) arg1)
(set! (-> (the-as collide-shape-prim-group v0-0) num-alloc-children) arg1)
(set! (-> (the-as collide-shape-prim-group v0-0) prim-core prim-type) (prim-type group))
(set! (-> (the-as collide-shape-prim-group v0-0) child)
(the-as (inline-array collide-shape-prim) (&+ (the-as collide-shape-prim-group v0-0) 80))
)
(the-as collide-shape-prim-group v0-0)
)
)
;; WARN: Return type mismatch uint vs int.
(defmethod length ((this collide-shape-prim-group))
(the-as int (-> this num-children))
)
(defmethod new collide-shape ((allocation symbol) (type-to-make type) (arg0 process-drawable) (arg1 collide-list-enum))
(let ((s5-0 (object-new allocation type-to-make (the-as int (-> type-to-make size)))))
(set! (-> s5-0 actor-hash-index) -1)
(set! (-> s5-0 process) arg0)
(set! (-> s5-0 max-iteration-count) (the-as uint 1))
(set! (-> s5-0 nav-flags) (nav-flags has-root-sphere))
(set! (-> s5-0 event-self) #f)
(set! (-> s5-0 event-other) #f)
(set! (-> s5-0 riders) (the-as (inline-array collide-rider) #f))
(set! (-> s5-0 root-prim) #f)
(set! (-> s5-0 penetrate-using) (penetrate))
(set! (-> s5-0 penetrated-by) (penetrate))
(set! (-> s5-0 event-priority) (the-as uint 0))
(set! (-> s5-0 rider-max-momentum) 409600.0)
(case (-> arg0 type symbol)
(('camera)
(set! (-> s5-0 pat-ignore-mask) (new 'static 'pat-surface :nocamera #x1 :probe #x1 :noendlessfall #x1))
)
(('target)
(set! (-> s5-0 pat-ignore-mask) (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1))
)
(else
(set! (-> s5-0 pat-ignore-mask)
(new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1)
)
)
)
(set! (-> s5-0 trans w) 1.0)
(quaternion-identity! (-> s5-0 quat))
(vector-identity! (-> s5-0 scale))
(cond
((= arg1 (collide-list-enum hit-by-player))
(add-connection *collide-hit-by-player-list* arg0 #f s5-0 #f #f)
)
((= arg1 (collide-list-enum usually-hit-by-player))
(add-connection *collide-hit-by-others-list* arg0 #f s5-0 #f #f)
)
((= arg1 (collide-list-enum hit-by-others))
(add-connection *collide-player-list* arg0 #f s5-0 #f #f)
)
(else
(format 0 "Unsupported collide-list-enum in collide-shape constructor!~%")
)
)
s5-0
)
)
;; WARN: Return type mismatch collide-shape vs collide-shape-moving.
(defmethod new collide-shape-moving ((allocation symbol) (type-to-make type) (arg0 process-drawable) (arg1 collide-list-enum))
(let ((v0-0 ((method-of-type collide-shape new) allocation type-to-make arg0 arg1)))
(set! (-> (the-as collide-shape-moving v0-0) gspot-pos y) -40959590.0)
(set! (-> (the-as collide-shape-moving v0-0) gspot-normal quad) (-> *y-vector* quad))
(set! (-> (the-as collide-shape-moving v0-0) surf) *standard-ground-surface*)
(the-as collide-shape-moving v0-0)
)
)
(define *collide-shape-prim-backgnd* (new 'static 'collide-shape-prim-mesh
:cshape #f
:prim-core (new 'static 'collide-prim-core
:world-sphere (new 'static 'vector :w 204800000.0)
:collide-as (collide-spec backgnd)
:action (collide-action solid)
:prim-type (prim-type fake-prim)
)
:local-sphere (new 'static 'vector :w 204800000.0)
:mesh #f
)
)
(define *collide-shape-prim-water* (new 'static 'collide-shape-prim-mesh
:cshape #f
:prim-core (new 'static 'collide-prim-core
:world-sphere (new 'static 'vector :w 204800000.0)
:collide-as (collide-spec water)
:action (collide-action solid)
:prim-type (prim-type fake-prim)
)
:local-sphere (new 'static 'vector :w 204800000.0)
:mesh #f
)
)
(define-perm *collide-rider-pool* collide-rider-pool (new 'global 'collide-rider-pool))
;; og:preserve-this added macro
(defmacro normalized-heading-to-quaternion! (quat heading)
"Modified for PC. This does a clever trick, but it doesn't work if the heading is exactly
[0, 0, -1] because this tries to normalize a quaternion that's all 0's.
I think that, on ps2, something prevents the heading from being exactly 0, 0, -1,
but this doesn't happen on PC. A similar thing happened with Jak 1's punch glitch,
where some trig functions were slightly off from returning exactly 0.0 and 1.0 on ps2
rounding only."
`(begin
(if (and (= (-> ,heading x) 0.0)
(= (+ 1.0 (-> ,heading z)) 0.0)
)
(quaternion-set! ,quat 0.0 1.0 0.0 0.0)
(quaternion-set! ,quat 0.0 (-> ,heading x) 0.0 (+ 1.0 (-> ,heading z)))
)
(quaternion-normalize! ,quat)
)
)