mirror of
https://github.com/open-goal/jak-project
synced 2026-06-14 14:28:25 -04:00
c3b6e7eb7e
* some cleanup and docs on collide-touch and the tie extractor * temp * more updates * update ref tests * type fix * rest of collide shape * another set of updates
177 lines
6.5 KiB
Common Lisp
177 lines
6.5 KiB
Common Lisp
;;-*-Lisp-*-
|
|
(in-package goal)
|
|
|
|
;; name: collide-touch-h.gc
|
|
;; name in dgo: collide-touch-h
|
|
;; dgos: GAME, ENGINE
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;; Collide Touch
|
|
;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; The collide-touch system is used to track collisions between collide shapes during collision resolution.
|
|
;; As the collision is resolved, shapes are added and removed from the touching list.
|
|
;; Once collision is done solving, you can send events or inspect what you touched!
|
|
|
|
;; A record of a primitive which is touching another, possibly including the triangle that is involved.
|
|
(deftype touching-prim (structure)
|
|
((cprim collide-shape-prim :offset-assert 0)
|
|
(has-tri? symbol :offset-assert 4)
|
|
(tri collide-tri-result :inline :offset-assert 16)
|
|
)
|
|
:method-count-assert 9
|
|
:size-assert #x64
|
|
:flag-assert #x900000064
|
|
)
|
|
|
|
;; A record of two primitives which are touching.
|
|
(deftype touching-prims-entry (structure)
|
|
((next touching-prims-entry :offset-assert 0)
|
|
(prev touching-prims-entry :offset-assert 4)
|
|
(allocated? symbol :offset-assert 8)
|
|
(u float :offset-assert 12)
|
|
(prim1 touching-prim :inline :offset-assert 16)
|
|
(prim2 touching-prim :inline :offset-assert 128)
|
|
)
|
|
:method-count-assert 13
|
|
:size-assert #xe4
|
|
:flag-assert #xd000000e4
|
|
(:methods
|
|
(get-touched-prim (_type_ trsqv touching-shapes-entry) collide-shape-prim 9)
|
|
(dummy-10 () none 10)
|
|
(get-middle-of-bsphere-overlap (_type_ vector) vector 11)
|
|
(get-touched-tri (_type_ collide-shape touching-shapes-entry) collide-tri-result 12)
|
|
)
|
|
)
|
|
|
|
;; A pool of up to 64 touching primitives. There is a linked list of freed entries.
|
|
(deftype touching-prims-entry-pool (structure)
|
|
((head touching-prims-entry :offset-assert 0)
|
|
(nodes touching-prims-entry 64 :inline :offset-assert 16)
|
|
)
|
|
:method-count-assert 13
|
|
:size-assert #x3c10
|
|
:flag-assert #xd00003c10
|
|
(:methods
|
|
(new (symbol type) _type_ 0)
|
|
(alloc-node (_type_) touching-prims-entry 9)
|
|
(get-free-node-count (_type_) int 10)
|
|
(init-list! (_type_) none 11)
|
|
(free-node (_type_ touching-prims-entry) touching-prims-entry 12)
|
|
)
|
|
)
|
|
|
|
(defmethod init-list! touching-prims-entry-pool ((obj touching-prims-entry-pool))
|
|
"Initialize all entries to be not allocated and in a linked list."
|
|
(let ((prev (the-as touching-prims-entry #f)))
|
|
(let ((current (the-as touching-prims-entry (-> obj nodes))))
|
|
(set! (-> obj head) current)
|
|
(countdown (a0-1 64)
|
|
(set! (-> current prev) prev)
|
|
(let ((next (&+ current 240)))
|
|
(set! (-> current next) (the-as touching-prims-entry next))
|
|
(set! (-> current allocated?) #f)
|
|
(set! prev current)
|
|
(set! current (the-as touching-prims-entry next))
|
|
)
|
|
)
|
|
)
|
|
(set! (-> prev next) #f)
|
|
)
|
|
(none)
|
|
)
|
|
|
|
(defmethod new touching-prims-entry-pool ((allocation symbol) (type-to-make type))
|
|
"Allocate and initialize a new touching-prims-entry-pool"
|
|
|
|
;; Note - the original code passed (-> type-to-make size) as an argument.
|
|
;; however, the new method of structure doesn't have this argument.
|
|
;; it uses the same value for the size so it doesn't really matter.
|
|
(let ((obj (the touching-prims-entry-pool ((method-of-type structure new)
|
|
allocation
|
|
type-to-make
|
|
;; (-> type-to-make size) see note
|
|
)
|
|
)))
|
|
(init-list! obj)
|
|
obj
|
|
)
|
|
)
|
|
|
|
;; two collide shapes which are touching.
|
|
;; This stores a list of primitive pairs which are touching.
|
|
(deftype touching-shapes-entry (structure)
|
|
((cshape1 collide-shape :offset-assert 0)
|
|
(cshape2 collide-shape :offset-assert 4)
|
|
(resolve-u int8 :offset-assert 8)
|
|
(head touching-prims-entry :offset-assert 12)
|
|
)
|
|
:allow-misaligned
|
|
:method-count-assert 18
|
|
:size-assert #x10
|
|
:flag-assert #x1200000010
|
|
(:methods
|
|
(dummy-9 (_type_) none 9)
|
|
(get-touched-shape (_type_ collide-shape) collide-shape 10)
|
|
(dummy-11 () none 11)
|
|
(prims-touching? (_type_ collide-shape-moving uint) touching-prims-entry 12) ; this one!
|
|
(prims-touching-action? (_type_ collide-shape collide-action collide-action) touching-prims-entry 13)
|
|
(dummy-14 () none 14)
|
|
(free-touching-prims-list (_type_) symbol 15)
|
|
(get-head (_type_) touching-prims-entry 16)
|
|
(get-next (_type_ touching-prims-entry) touching-prims-entry 17)
|
|
)
|
|
)
|
|
|
|
;; A list of (up to) 32 pairs of colliding shapes
|
|
(deftype touching-list (structure)
|
|
((num-touching-shapes int32 :offset-assert 0)
|
|
(resolve-u int8 :offset-assert 4)
|
|
(touching-shapes touching-shapes-entry 32 :inline :offset-assert 8)
|
|
)
|
|
:method-count-assert 15
|
|
:size-assert #x208
|
|
:flag-assert #xf00000208
|
|
(:methods
|
|
(new (symbol type) _type_ 0)
|
|
(add-touching-prims (_type_ collide-shape-prim collide-shape-prim float collide-tri-result collide-tri-result) none 9)
|
|
(dummy-10 () none 10)
|
|
(update-from-step-size (_type_ float) none 11)
|
|
(send-events-for-touching-shapes (_type_) none 12)
|
|
(get-shapes-entry (_type_ collide-shape collide-shape) touching-shapes-entry 13)
|
|
(free-all-prim-nodes (_type_) none 14)
|
|
)
|
|
)
|
|
|
|
(defmethod new touching-list ((allocation symbol) (type-to-make type))
|
|
"See note in touching-prims-entry-pool"
|
|
(let ((obj (the touching-list ((method-of-type structure new)
|
|
allocation
|
|
type-to-make
|
|
;; (-> type-to-make size) see note
|
|
)
|
|
)))
|
|
(set! (-> obj num-touching-shapes) 0)
|
|
(set! (-> obj resolve-u) 0)
|
|
obj
|
|
)
|
|
)
|
|
|
|
(defmethod get-head touching-shapes-entry ((obj touching-shapes-entry))
|
|
"Get the first pair of touching prims in a touching-shapes-entry"
|
|
(-> obj head)
|
|
)
|
|
|
|
(defmethod get-next touching-shapes-entry ((obj touching-shapes-entry) (arg0 touching-prims-entry))
|
|
"Get the next pair of touching prims."
|
|
(-> arg0 next)
|
|
)
|
|
|
|
;; Allocate the global touching lists.
|
|
;; We have a pool of prim pairs that can be used in any shape pair
|
|
(define-perm *touching-prims-entry-pool* touching-prims-entry-pool (new 'global 'touching-prims-entry-pool))
|
|
|
|
;; and a list of up to 32 shape pairs
|
|
(define-perm *touching-list* touching-list (new 'global 'touching-list))
|
|
|