mirror of
https://github.com/open-goal/jak-project
synced 2026-07-11 07:25:37 -04:00
171 lines
6.1 KiB
Common Lisp
171 lines
6.1 KiB
Common Lisp
;;-*-Lisp-*-
|
|
(in-package goal)
|
|
|
|
;; name: collide-cache-h.gc
|
|
;; name in dgo: collide-cache-h
|
|
;; dgos: ENGINE, GAME
|
|
|
|
;; +++prim-type
|
|
(defenum prim-type
|
|
:type int8
|
|
(prim -2)
|
|
(sphere -1)
|
|
(group 0)
|
|
(mesh 1)
|
|
(fake-prim 2)
|
|
)
|
|
;; ---prim-type
|
|
|
|
(declare-type collide-cache-prim structure)
|
|
(declare-type collide-using-spheres-params structure)
|
|
(declare-type instance-tie structure)
|
|
(declare-type collide-list structure)
|
|
|
|
;; DECOMP BEGINS
|
|
|
|
(deftype collide-puss-sphere (structure)
|
|
"A query sphere from the user for the porbe-using-spheres query.
|
|
This is used internally by the collide-cache implementation."
|
|
((bsphere sphere :inline)
|
|
(bbox4w bounding-box4w :inline)
|
|
)
|
|
)
|
|
|
|
|
|
(deftype collide-puss-work (structure)
|
|
"Scratchpad memory map for probe-using-spheres query."
|
|
((closest-pt vector :inline)
|
|
(tri-normal vector :inline)
|
|
(tri-bbox4w bounding-box4w :inline)
|
|
(spheres-bbox4w bounding-box4w :inline)
|
|
(spheres collide-puss-sphere 64 :inline)
|
|
)
|
|
(:methods
|
|
(check-mesh-prim-against-spheres (_type_ collide-cache-prim collide-using-spheres-params) symbol)
|
|
(check-sphere-prim-against-spheres (_type_ collide-cache-prim collide-using-spheres-params) symbol)
|
|
)
|
|
)
|
|
|
|
|
|
(deftype collide-cache-tri (structure)
|
|
"A single triangle inside the collision cache.
|
|
Contains a reference back to the source object (like a collide-shape or water-control), and the prim itself."
|
|
((vertex vector 3 :inline)
|
|
(extra-quad uint8 16)
|
|
(pat pat-surface :overlay-at (-> extra-quad 0))
|
|
(collide-ptr basic :overlay-at (-> extra-quad 4))
|
|
(prim-index uint16 :overlay-at (-> extra-quad 8))
|
|
(user16 uint16 :overlay-at (-> extra-quad 10))
|
|
(user32 uint32 :overlay-at (-> extra-quad 12))
|
|
(clear-flags uint128 :overlay-at (-> extra-quad 0))
|
|
)
|
|
)
|
|
|
|
|
|
(deftype collide-cache-prim (structure)
|
|
"A primitive inside the collide-cache.
|
|
This can represent a sphere, a triangle mesh, or a group of other primitives within a bounding sphere."
|
|
((prim-core collide-prim-core :inline)
|
|
(extra-quad uint8 16)
|
|
(ccache collide-cache :overlay-at (-> extra-quad 0))
|
|
(prim collide-shape-prim :overlay-at (-> extra-quad 4))
|
|
(first-tri uint16 :overlay-at (-> extra-quad 8))
|
|
(num-tris uint16 :overlay-at (-> extra-quad 10))
|
|
(extra basic :overlay-at (-> extra-quad 12))
|
|
(world-sphere vector :inline :overlay-at (-> prim-core world-sphere))
|
|
(collide-as collide-spec :overlay-at (-> prim-core collide-as))
|
|
(action collide-action :overlay-at (-> prim-core action))
|
|
(prim-type prim-type :overlay-at (-> prim-core prim-type))
|
|
)
|
|
(:methods
|
|
(resolve-moving-sphere-tri (_type_ collide-query sphere vector float collide-action) float)
|
|
(resolve-moving-sphere-sphere (_type_ collide-query sphere vector float collide-action) float)
|
|
)
|
|
)
|
|
|
|
|
|
(deftype collide-cache (basic)
|
|
"The collide-cache is a structure to accelerate collision queries.
|
|
In particular, it helps with queries where you don't know what you might hit.
|
|
It can detect collision with the background geometry, foreground dynamic collision shapes (spheres and meshes), and water.
|
|
To use it, it must first be 'filled' with geometry. Then you can manually inspect the geometry, or use one of the queries.
|
|
The supported queries are 'line-sphere' (raycast) and 'spheres' (check if intersecting anything).
|
|
It is not useful for ollision queries against a specific foreground object, like 'am I on top of platform X right now?'."
|
|
((num-tris int32)
|
|
(max-tris int32)
|
|
(num-prims int32)
|
|
(max-prims int32)
|
|
(ignore-mask pat-surface)
|
|
(ignore-processes process 2)
|
|
(collide-box bounding-box :inline)
|
|
(collide-box4w bounding-box4w :inline)
|
|
(collide-with collide-spec)
|
|
(unused uint32 3)
|
|
(prims collide-cache-prim 4)
|
|
(tris collide-cache-tri)
|
|
)
|
|
(:methods
|
|
(new (symbol type int int) _type_)
|
|
(collide-cache-method-9 () none)
|
|
(collide-cache-method-10 () none)
|
|
(collide-cache-method-11 () none)
|
|
(collide-cache-method-12 () none)
|
|
(collide-cache-method-13 () none)
|
|
(collide-cache-method-14 () none)
|
|
(collide-cache-method-15 () none)
|
|
(collide-cache-method-16 () none)
|
|
(collide-cache-method-17 () none)
|
|
(collide-cache-method-18 () none)
|
|
(collide-cache-method-19 () none)
|
|
(collide-cache-method-20 () none)
|
|
(collide-cache-method-21 () none)
|
|
(collide-cache-method-22 () none)
|
|
(collide-cache-method-23 () none)
|
|
(collide-cache-method-24 () none)
|
|
(collide-cache-method-25 () none)
|
|
(collide-cache-method-26 () none)
|
|
(collide-cache-method-27 () none)
|
|
)
|
|
)
|
|
|
|
|
|
(deftype collide-list-item (structure)
|
|
"Entry on the broad-phase collision list.
|
|
Can represent instanced collision, as a TIE instance, or a single non-instanced mesh fragment."
|
|
((mesh instance-tie)
|
|
(inst basic)
|
|
)
|
|
:pack-me
|
|
)
|
|
|
|
|
|
(deftype collide-list (structure)
|
|
"List of items returned by the broad-phase collision query."
|
|
((num-items int32)
|
|
(items collide-list-item 256 :inline :offset 16)
|
|
)
|
|
)
|
|
|
|
|
|
(defmethod new collide-cache ((allocation symbol) (type-to-make type) (arg0 int) (arg1 int))
|
|
(let* ((s3-0 (logand -16 (+ (-> type-to-make size) 19)))
|
|
(gp-0 (* 48 arg0))
|
|
(v1-3 (* (+ arg1 1) 64))
|
|
(v0-0 (object-new allocation type-to-make (the-as int (+ s3-0 gp-0 v1-3))))
|
|
)
|
|
(set! (-> v0-0 max-tris) arg1)
|
|
(set! (-> v0-0 max-prims) arg0)
|
|
(set! (-> v0-0 prims 0) (the-as collide-cache-prim (logand -16 (+ (+ s3-0 15) (the-as uint v0-0)))))
|
|
(set! (-> v0-0 tris) (the-as collide-cache-tri (+ (the-as uint (-> v0-0 prims 0)) gp-0)))
|
|
v0-0
|
|
)
|
|
)
|
|
|
|
(kmemopen global "collide-cache-buffers")
|
|
|
|
(define-perm *collide-cache* collide-cache (new 'global 'collide-cache 100 460))
|
|
|
|
(define-perm *collide-list* collide-list (new 'global 'collide-list))
|
|
|
|
(kmemclose)
|