jak-project/goal_src/engine/collide/collide-shape-h.gc
Tyler Wilding c8a31d4d1b
decomp: Pass of the final remaining gameplay related files (#921)
* blocked: `plant-boss` has `go` returning none issues

* blocked: `ice-cube` return value getting forced to none

* blocked: `ropebridge` has static data isue

* blocked: `double-lurker` handle cast issues

* decomp: finish `billy`

* decomp: finish `lurkerworm`

* blocked: `pelican` handle casts

* decomp: finish `citb-bunny`

* blocked: inherited states in `snow-bunny`

* blocked: CFG resolution in `lavatube-energy`

* decomp: finish `citadel-sages`

* progress: working through `collectables`

* blocked: finished as much as currently possible in `collectables`

- process-tree's 10 method pparently has a 3rd arg -- im doubtful
- set-to-run function
- branch delay unimplemented case
- weird method 21 eco-collectable

* pre-merge

* decomp: update source files / ref tests

* decomp: finish `floating-launcher`, `shover`, `steam-cap`, `sun-iris-door`, `whirlpool`

* decomp: address feedback

* update ref tests and gsrc
2021-11-14 11:14:43 -05:00

501 lines
18 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
;; name: collide-shape-h.gc
;; name in dgo: collide-shape-h
;; dgos: GAME, ENGINE
(declare-type touching-list structure)
;; Represents a collision between the "rider" (zoomer?) and a primitive shape.
;; collisions are "sticky", meaning these structures stick around.
(deftype collide-sticky-rider (structure)
((rider-handle handle :offset-assert 0)
(sticky-prim basic :offset-assert 8)
(prim-ry float :offset-assert 12)
(rider-local-pos vector :inline :offset-assert 16)
)
:method-count-assert 10
:size-assert #x20
:flag-assert #xa00000020
(:methods
(set-rider! (_type_ handle) symbol 9)
)
)
(defmethod set-rider! collide-sticky-rider ((obj collide-sticky-rider) (arg0 handle))
"Set the rider and clear the primitive."
(set! (-> obj rider-handle) arg0)
(set! (-> obj sticky-prim) #f)
#f
)
;; A collection of collide-sticky-riders
;; dynamic type. I think there's one collide-sticky-rider per rider?
(deftype collide-sticky-rider-group (basic)
((num-riders int32 :offset-assert 4)
(allocated-riders int32 :offset-assert 8)
(rider collide-sticky-rider 1 :inline :offset-assert 16)
)
:method-count-assert 11
:size-assert #x30
:flag-assert #xb00000030
(:methods
(new (symbol type int) _type_ 0)
(dummy-9 () none 9)
(reset! (_type_) int 10)
)
)
(defmethod reset! collide-sticky-rider-group ((obj collide-sticky-rider-group))
"Reset all active riders"
(set! (-> obj num-riders) 0)
0
)
(deftype pull-rider-info (structure)
((rider collide-sticky-rider :offset-assert 0)
(rider-cshape basic :offset-assert 4)
(rider-delta-ry float :offset-assert 8)
(rider-dest vector :inline :offset-assert 16)
)
:method-count-assert 9
:size-assert #x20
:flag-assert #x900000020
)
(declare-type collide-shape-prim basic)
(deftype collide-shape-intersect (basic)
((move-vec vector :inline :offset-assert 16)
(best-u float :offset-assert 32)
(best-tri collide-tri-result :inline :offset-assert 48)
(best-from-prim collide-shape-prim :offset-assert 132)
(best-to-prim collide-shape-prim :offset-assert 136)
)
:method-count-assert 10
:size-assert #x8c
:flag-assert #xa0000008c
(:methods
(dummy-9 () none 9)
)
)
(deftype collide-overlap-result (structure)
((best-dist float :offset-assert 0)
(best-from-prim collide-shape-prim :offset-assert 4)
(best-to-prim collide-shape-prim :offset-assert 8)
(best-from-tri collide-tri-result :inline :offset-assert 16)
)
:method-count-assert 10
:size-assert #x64
:flag-assert #xa00000064
(:methods
(reset! (_type_) none 9)
)
)
(defmethod reset! collide-overlap-result ((obj collide-overlap-result))
"Reset the result."
(set! (-> obj best-dist) 0.0)
(set! (-> obj best-from-prim) #f)
(set! (-> obj best-to-prim) #f)
(none)
)
(deftype overlaps-others-params (structure)
((options uint32 :offset-assert 0)
(tlist touching-list :offset-assert 4)
)
:method-count-assert 9
:size-assert #x8
:flag-assert #x900000008
)
;; The engine system is used to link collision checks with processes.
(define *collide-hit-by-player-list* (new 'global 'engine 'collide-hit-by-player-list 768))
(define *collide-usually-hit-by-player-list* (new 'global 'engine 'collide-usually-hit-by-player-list 256))
(define *collide-hit-by-others-list* (new 'global 'engine 'collide-hit-by-others-list 96))
(define *collide-player-list* (new 'global 'engine 'collide-player-list 32))
;; some parts of collide-shape-prim are broken out here.
(deftype collide-prim-core (structure)
((world-sphere vector :inline :offset-assert 0)
(collide-as uint64 :offset-assert 16)
(action uint32 :offset-assert 24)
(offense int8 :offset-assert 28)
(prim-type int8 :offset-assert 29)
(extra uint8 2 :offset-assert 30)
(quad uint128 2 :offset 0)
)
:method-count-assert 9
:size-assert #x20
:flag-assert #x900000020
)
;; the base class for collision shapes.
(deftype collide-shape-prim (basic)
((cshape basic :offset-assert 4)
(prim-id uint32 :offset-assert 8)
(transform-index int8 :offset-assert 12)
(prim-core collide-prim-core :inline :offset-assert 16)
(local-sphere vector :inline :offset-assert 48)
(collide-with uint64 :offset-assert 64)
;; overlays of the prim-core
(world-sphere vector :inline :offset 16)
(collide-as uint64 :offset 32)
(action uint32 :offset 40)
(offense int8 :offset 44)
(prim-type int8 :offset 45)
;; overlay of the local-sphere w
(radius meters :offset 60)
)
:method-count-assert 28
:size-assert #x48
:flag-assert #x1c00000048
(:methods
(new (symbol type basic uint int) _type_ 0)
(dummy-9 () none 9)
(dummy-10 (_type_ uint) collide-shape-prim 10)
(dummy-11 () none 11)
(add-fg-prim-using-box (_type_) none 12)
(add-fg-prim-using-line-sphere (_type_) none 13)
(add-fg-prim-using-y-probe (_type_) none 14)
(dummy-15 () none 15)
(dummy-16 () none 16)
(dummy-17 () none 17)
(dummy-18 () none 18)
(dummy-19 () none 19)
(dummy-20 () none 20)
(dummy-21 () none 21)
(dummy-22 () none 22)
(dummy-23 () none 23)
(dummy-24 () none 24)
(dummy-25 () none 25)
(dummy-26 () none 26)
(dummy-27 () none 27)
)
)
;; sphere collision
;; the pat is stored directly here.
(deftype collide-shape-prim-sphere (collide-shape-prim)
((pat pat-surface :offset-assert 72)
)
:method-count-assert 28
:size-assert #x4c
:flag-assert #x1c0000004c
(:methods
(new (symbol type basic uint) _type_ 0)
)
)
;; mesh collision
;; the pats are stored per tri in the mesh.
(deftype collide-shape-prim-mesh (collide-shape-prim)
((mesh collide-mesh :offset-assert 72)
(mesh-id int32 :offset-assert 76)
(mesh-cache-id uint64 :offset-assert 80)
(mesh-cache-tris uint32 :offset-assert 88)
)
:method-count-assert 29
:size-assert #x5c
:flag-assert #x1d0000005c
(:methods
(new (symbol type basic uint uint) _type_ 0)
(dummy-28 (_type_ int) none 28)
)
)
;; A group of collide-shape-prim's
(deftype collide-shape-prim-group (collide-shape-prim)
((num-prims int32 :offset-assert 72)
(allocated-prims int32 :offset-assert 76)
(prim collide-shape-prim 1 :offset-assert 80)
(prims collide-shape-prim :dynamic :score 20 :offset 80) ;; added
)
:method-count-assert 30
:size-assert #x54
:flag-assert #x1e00000054
(:methods
(new (symbol type basic uint int) _type_ 0)
(dummy-28 (_type_) none 28)
(dummy-29 () none 29)
)
)
(defenum collide-list-enum
(hit-by-player)
(usually-hit-by-player)
(hit-by-others)
(player)
)
;; an actual instance of a collision primitive.
;; it's based on a transform (q means quaternion, v means with derivatives)
(deftype collide-shape (trsqv)
((process process :offset-assert 140)
(max-iteration-count uint8 :offset-assert 144)
(nav-flags uint8 :offset-assert 145)
(pad-byte uint8 2 :offset-assert 146)
(pat-ignore-mask pat-surface :offset-assert 148)
(event-self basic :offset-assert 152)
(event-other basic :offset-assert 156)
(root-prim collide-shape-prim :offset-assert 160)
(riders collide-sticky-rider-group :offset-assert 164)
(backup-collide-as uint64 :offset-assert 168)
(backup-collide-with uint64 :offset-assert 176)
)
:method-count-assert 56
:size-assert #xb8
:flag-assert #x38000000b8
(:methods
(new (symbol type process collide-list-enum) _type_)
(TODO-RENAME-28 (_type_) none 28)
(dummy-29 (_type_ int) none 29)
(TODO-RENAME-30 (_type_ vector) none 30)
(dummy-31 () none 31)
(dummy-32 (_type_ float uint) none 32)
(dummy-33 (_type_ vector uint) none 33)
(dummy-34 (_type_ uint) collide-shape-prim 34)
(dummy-35 (_type_) none 35)
(dummy-36 () none 36)
(dummy-37 (_type_ vector) none 37)
(dummy-38 () none 38)
(dummy-39 () none 39)
(dummy-40 (_type_ structure) none 40) ;; ?? - I've seen overlaps-others-params | collide-edge-hold-list
(dummy-41 (_type_ attack-info float) none 41)
(dummy-42 () none 42)
(dummy-43 () none 43)
(dummy-44 (_type_) none 44)
(dummy-45 (_type_) none 45)
(dummy-46 (_type_) none 46)
(dummy-47 (_type_) none 47)
(dummy-48 (_type_) none 48)
(dummy-49 (_type_) none 49)
(dummy-50 (_type_) none 50)
(dummy-51 () none 51)
(dummy-52 () none 52)
(dummy-53 (_type_ int int int) none 53)
(dummy-54 (_type_ int int) none 54)
(dummy-55 (_type_ process uint float float float) none 55)
)
)
;; More complicated collide-shape?
(deftype collide-shape-moving (collide-shape)
((rider-time uint64 :offset-assert 184)
(rider-last-move vector :inline :offset-assert 192)
(trans-old vector 3 :inline :offset-assert 208)
(poly-pat pat-surface :offset-assert 256)
(cur-pat pat-surface :offset-assert 260)
(ground-pat pat-surface :offset-assert 264)
(status uint64 :offset-assert 272)
(old-status uint64 :offset-assert 280)
(prev-status uint64 :offset-assert 288)
(reaction-flag uint32 :offset-assert 296)
(reaction function :offset-assert 300)
(no-reaction function :offset-assert 304)
(local-normal vector :inline :offset-assert 320)
(surface-normal vector :inline :offset-assert 336)
(poly-normal vector :inline :offset-assert 352)
(ground-poly-normal vector :inline :offset-assert 368)
(ground-touch-point vector :inline :offset-assert 384)
(shadow-pos vector :inline :offset-assert 400)
(ground-impact-vel meters :offset-assert 416)
(surface-angle float :offset-assert 420)
(poly-angle float :offset-assert 424)
(touch-angle float :offset-assert 428)
(coverage float :offset-assert 432)
(dynam dynamics :offset-assert 436)
(surf surface :offset-assert 440)
)
:method-count-assert 65
:size-assert #x1bc
:flag-assert #x41000001bc
(:methods
(dummy-56 (_type_ pat-surface) none 56)
(dummy-57 (_type_ vector) none 57)
(dummy-58 (_type_ vector) none 58)
(dummy-59 (_type_ vector uint float symbol symbol symbol) none 59)
(dummy-60 (_type_ float float symbol uint) none 60)
(TODO-RENAME-61 (_type_ vector vector vector) none 61)
(dummy-62 (_type_ vector float) vector 62)
(dummy-63 () none 63)
(dummy-64 () none 64)
)
)
(defmethod new collide-shape-prim ((allocation symbol) (type-to-make type) (cshape basic) (prim-id uint) (size-bytes int))
"Allocate a new collide-shape-prim. It is expected that children of collide-shape-prim override this.
NOTE: uses the size-bytes as the TOTAL size of the structure."
(let ((obj (object-new allocation type-to-make size-bytes)))
;; not sure what this is.
(set! (-> obj cshape) cshape)
;; sphere/mesh?
(set! (-> obj prim-id) prim-id)
(set! (-> obj prim-core action) 0)
(set! (-> obj prim-core collide-as) 0)
(set! (-> obj collide-with) 0)
(set! (-> obj transform-index) -2)
(set! (-> obj prim-core offense) 0)
(set! (-> obj prim-core prim-type) -2)
obj
)
)
(defmethod new collide-shape-prim-sphere ((allocation symbol) (type-to-make type) (cshape basic) (prim-id uint))
"Allocate a new sphere primitive"
(let ((obj (the collide-shape-prim-sphere ((method-of-type collide-shape-prim new) allocation type-to-make cshape prim-id (size-of collide-shape-prim-mesh)))))
(set! (-> obj pat) (new 'static 'pat-surface :mode (pat-mode obstacle)))
(set! (-> obj prim-core prim-type) -1)
obj
)
)
(defmethod new collide-shape-prim-mesh ((allocation symbol) (type-to-make type) (cshape basic) (mesh-id uint) (prim-id uint))
"Allocate a new mesh primitive"
(let ((obj (the collide-shape-prim-mesh ((method-of-type collide-shape-prim new) allocation type-to-make cshape prim-id (size-of collide-shape-prim-mesh)))))
(set! (-> obj mesh) #f)
(set! (-> obj mesh-id) (the int mesh-id))
(set! (-> obj mesh-cache-id) 0)
(set! (-> obj prim-core prim-type) 1)
obj
)
)
(defmethod new collide-shape-prim-group ((allocation symbol) (type-to-make type) (cshape basic) (elt-count uint) (prim-id int))
"Allocate a group of primitives."
(let ((obj (the collide-shape-prim-group ((method-of-type collide-shape-prim new) allocation type-to-make cshape (the uint prim-id) (the int (+ (-> type-to-make size) (* (+ elt-count -1) 4)))))))
(set! (-> obj allocated-prims) (the int elt-count))
(set! (-> obj num-prims) 0)
(set! (-> obj prim-core prim-type) 0)
(while (nonzero? elt-count)
(+! elt-count -1)
(set! (-> obj prim elt-count) (the collide-shape-prim #f))
(nop!)
)
obj
)
)
(defmethod length collide-shape-prim-group ((obj collide-shape-prim-group))
"How many primitives are used?"
(-> obj num-prims)
)
(defmethod asize-of collide-shape-prim-group ((obj collide-shape-prim-group))
"How big is this in memory?"
(the-as int
(+ (-> obj type size) (the-as uint (* (+ (-> obj allocated-prims) -1) 4)))
)
)
(defmethod new collide-shape ((allocation symbol) (type-to-make type) (proc process) (collide-list-kind collide-list-enum))
"Allocate a new collide-shape and add to a collide-list"
(let ((obj (object-new allocation type-to-make (the int (-> type-to-make size)))))
(set! (-> obj process) proc)
(set! (-> obj max-iteration-count) 1)
(set! (-> obj nav-flags) #x1)
(set! (-> obj event-self) #f)
(set! (-> obj event-other) #f)
(set! (-> obj riders) #f)
(set! (-> obj root-prim) #f)
;; add a special ignore mask for the camera vs other things.
(case (-> proc type symbol)
(('camera)
(set!
(-> obj pat-ignore-mask)
(new 'static 'pat-surface :skip #x2 :nocamera #x1)
)
)
(else
(set!
(-> obj pat-ignore-mask)
(new 'static 'pat-surface :skip #x1 :noentity #x1)
)
)
)
;; reset transformation to the origin.
(set! (-> obj trans w) 1.0)
(quaternion-identity! (-> obj quat))
(vector-identity! (-> obj scale))
;; add us to right list.
(case collide-list-kind
(((collide-list-enum hit-by-player))
(add-connection *collide-hit-by-player-list* proc #f obj #f #f))
(((collide-list-enum usually-hit-by-player))
(add-connection *collide-usually-hit-by-player-list* proc #f obj #f #f))
(((collide-list-enum hit-by-others))
(add-connection *collide-hit-by-others-list* proc #f obj #f #f))
(((collide-list-enum player))
(add-connection *collide-player-list* proc #f obj #f #f))
(else
(format 0 "Unsupported collide-list-enum in collide-shape constructor!~%"))
)
obj
)
)
(defmethod new collide-sticky-rider-group ((allocation symbol) (type-to-make type) (riders-amount int))
"Allocate a new collide-sticky-rider-group with space for riders-amount sticky riders."
(let ((obj (object-new allocation type-to-make (the int (+ (-> type-to-make size) (the uint (* (1- riders-amount) (size-of collide-sticky-rider))))))))
(set! (-> obj allocated-riders) riders-amount)
(set! (-> obj num-riders) 0)
obj
)
)
(defmethod length collide-sticky-rider-group ((obj collide-sticky-rider-group))
(-> obj num-riders)
)
(defmethod asize-of collide-sticky-rider-group ((obj collide-sticky-rider-group))
(the-as int
(+ (-> obj type size) (the-as uint (* (1- (-> obj allocated-riders)) (size-of collide-sticky-rider))))
)
)
(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 #x1
:action #x1
:offense 4
:prim-type 2
)
: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 #x20
:action #x1
:offense 4
:prim-type 2
)
:local-sphere (new 'static 'vector :w 204800000.0)
:mesh #f
)
)