jak-project/goal_src/jak2/engine/common_objs/water-flow.gc
2022-11-11 16:23:26 -05:00

412 lines
16 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
;; name: water-flow.gc
;; name in dgo: water-flow
;; dgos: ENGINE, GAME
;; DECOMP BEGINS
(defun ray-plane-equation-intersect ((arg0 vector) (arg1 vector) (arg2 vector) (arg3 vector))
(let* ((f0-1 (vector4-dot arg3 arg1))
(f1-1 (vector-dot arg3 arg2))
(f30-0 (/ (- f0-1) f1-1))
)
(vector-v*float+! arg0 arg1 arg2 f30-0)
f30-0
)
)
(deftype flow-section (structure)
((start vector :inline :offset-assert 0)
(trailing plane :inline :offset-assert 16)
(pull-dir vector :inline :offset-assert 32)
(radial-dir vector :inline :offset-assert 48)
)
:method-count-assert 9
:size-assert #x40
:flag-assert #x900000040
)
(deftype flow-section-array (inline-array-class)
((data flow-section :inline :dynamic :offset-assert 16)
)
:method-count-assert 9
:size-assert #x10
:flag-assert #x900000010
)
(set! (-> flow-section-array heap-base) (the-as uint 64))
(deftype flow-control (basic)
((path path-control :offset-assert 4)
(speed float :offset-assert 8)
(belt-radius float :offset-assert 12)
(sections flow-section-array :offset-assert 16)
(leading plane :inline :offset-assert 32)
(collide-bounds sphere :inline :offset-assert 48)
)
:method-count-assert 13
:size-assert #x40
:flag-assert #xd00000040
(:methods
(new (symbol type process-drawable res-lump) _type_ 0)
(draw-path (_type_) none 9)
(setup (_type_) none 10)
(push-process (_type_ process-focusable) none 11)
(find-and-push-things (_type_) none 12)
)
)
(defmethod relocate flow-control ((obj flow-control) (arg0 int))
(if (nonzero? (-> obj sections))
(&+! (-> obj sections) arg0)
)
(if (nonzero? (-> obj path))
(&+! (-> obj path) arg0)
)
((the-as (function flow-control int flow-control) (find-parent-method flow-control 7)) obj arg0)
)
(defmethod draw-path flow-control ((obj flow-control))
(let ((a0-1 (-> obj path)))
(if (nonzero? a0-1)
(debug-draw a0-1)
)
)
0
(none)
)
(defmethod push-process flow-control ((obj flow-control) (arg0 process-focusable))
(with-pp
(rlet ((acc :class vf)
(vf0 :class vf)
(vf4 :class vf)
(vf5 :class vf)
(vf6 :class vf)
(vf7 :class vf)
)
(init-vf0-vector)
(let ((s5-0 (new 'stack-no-clear 'vector)))
(set! (-> s5-0 quad) (-> (get-trans arg0 0) quad))
(set! (-> s5-0 w) 1.0)
(when (>= (vector4-dot s5-0 (the-as vector (-> obj leading))) 0.0)
(let* ((v1-7 (-> obj sections))
(a0-3 (-> v1-7 length))
(a3-0 (the-as object (-> obj leading)))
)
(dotimes (s3-1 a0-3)
(let ((s2-0 (-> v1-7 data s3-1)))
(when (< (vector4-dot s5-0 (the-as vector (-> s2-0 trailing))) 0.0)
(let ((v1-8 (new 'stack-no-clear 'vector)))
(vector-! v1-8 s5-0 (-> s2-0 start))
(when (>= (-> obj belt-radius) (fabs (vector-dot v1-8 (-> s2-0 radial-dir))))
(let* ((f0-7 (vector-dot v1-8 (-> s2-0 pull-dir)))
(f0-9 (- (-> v1-8 y) (* (-> s2-0 pull-dir y) f0-7)))
)
(when (and (>= f0-9 -41984.0) (>= 41779.2 f0-9))
(let* ((a0-11 (new 'stack-no-clear 'vector))
(s1-0 (new 'stack-no-clear 'vector))
(f30-0 (ray-plane-equation-intersect a0-11 s5-0 (-> s2-0 pull-dir) (the-as vector a3-0)))
(f0-10 (ray-plane-equation-intersect s1-0 s5-0 (-> s2-0 pull-dir) (-> s2-0 trailing)))
)
(let ((a0-13 (new 'stack-no-clear 'vector)))
(let ((v1-13 (-> s2-0 start)))
(let ((a1-12 (-> s2-0 pull-dir)))
(let ((a2-6 12288.0))
(.mov vf7 a2-6)
)
(.lvf vf5 (&-> a1-12 quad))
)
(.lvf vf4 (&-> v1-13 quad))
)
(.add.x.vf vf6 vf0 vf0 :mask #b1000)
(.mul.x.vf acc vf5 vf7 :mask #b111)
(.add.mul.w.vf vf6 vf4 vf0 acc :mask #b111)
(.svf (&-> a0-13 quad) vf6)
)
0
(let ((f0-12 (/ f30-0 (- f30-0 f0-10)))
(s2-1 (new 'stack-no-clear 'vector))
)
(displacement-between-two-points-normalized! (-> obj path) s2-1 (+ (the float s3-1) f0-12))
(let ((v1-17 (new 'stack-no-clear 'vector)))
(vector-float*! v1-17 s2-1 (* (-> obj speed) (-> pp clock seconds-per-frame)))
(let ((a1-15 (new 'stack-no-clear 'vector)))
(let ((a0-17 v1-17))
(let ((a2-9 2048.0))
(.mov vf7 a2-9)
)
(.lvf vf5 (&-> a0-17 quad))
)
(.lvf vf4 (&-> s5-0 quad))
(.add.x.vf vf6 vf0 vf0 :mask #b1000)
(.mul.x.vf acc vf5 vf7 :mask #b111)
(.add.mul.w.vf vf6 vf4 vf0 acc :mask #b111)
(.svf (&-> a1-15 quad) vf6)
)
0
(send-event arg0 'push-trans v1-17 3000)
)
)
)
)
)
)
)
(return #f)
)
)
(set! a3-0 (+ (the-as uint (-> v1-7 data 0 trailing)) (* s3-1 64)))
)
)
)
)
0
(none)
)
)
)
(defmethod find-and-push-things flow-control ((obj flow-control))
(local-vars (a0-10 float) (a2-5 float) (a2-12 float))
(rlet ((acc :class vf)
(vf0 :class vf)
(vf1 :class vf)
(vf2 :class vf)
(vf3 :class vf)
(vf4 :class vf)
)
(init-vf0-vector)
(set! *actor-list-length* 0)
(if #t
(set! *actor-list-length* (fill-actor-list-for-sphere *actor-hash* (-> obj collide-bounds) *actor-list* 256))
)
(when #t
(let ((a0-2 (-> *collide-player-list* alive-list next0)))
*collide-player-list*
(let ((v1-11 (-> a0-2 next0)))
(while (!= a0-2 (-> *collide-player-list* alive-list-end))
(let* ((a0-3 (-> (the-as connection a0-2) param1))
(a1-1 (-> (the-as collide-shape a0-3) root-prim))
)
(when (logtest? (-> a1-1 prim-core collide-as) (collide-spec jak bot enemy hit-by-others-list player-list))
(let ((a1-2 (-> a1-1 prim-core)))
(let ((a2-4 a1-2)
(a3-1 (-> obj collide-bounds))
)
(.lvf vf2 (&-> a2-4 world-sphere quad))
(.lvf vf3 (&-> a3-1 quad))
)
(.sub.vf vf1 vf3 vf2)
(.mul.vf vf1 vf1 vf1)
(.add.y.vf vf1 vf1 vf1 :mask #b1)
(.add.z.vf vf1 vf1 vf1 :mask #b1)
(.mov a2-5 vf1)
(let ((f0-0 a2-5)
(f1-1 (+ (-> a1-2 world-sphere w) (-> obj collide-bounds r)))
)
(when (< f0-0 (* f1-1 f1-1))
(when (< *actor-list-length* 256)
(set! (-> *actor-list* *actor-list-length*) (the-as collide-shape a0-3))
(set! *actor-list-length* (+ *actor-list-length* 1))
)
)
)
)
)
)
(set! a0-2 v1-11)
*collide-player-list*
(set! v1-11 (-> v1-11 next0))
)
)
)
)
(b! (not #f) cfg-20 :delay (empty-form))
(let ((a0-5 (-> *collide-hit-by-player-list* alive-list next0)))
*collide-hit-by-player-list*
(let ((v1-18 (-> a0-5 next0)))
(b! #t cfg-18 :delay (nop!))
(label cfg-13)
(let ((a0-6 (-> (the-as connection a0-5) param1)))
(let ((a1-13 (-> (the-as collide-shape a0-6) root-prim)))
(b!
(not (logtest? (-> a1-13 prim-core collide-as) (collide-spec jak bot enemy hit-by-others-list player-list)))
cfg-17
:delay (empty-form)
)
(let ((a1-14 (-> a1-13 prim-core)))
(let ((a2-11 a1-14)
(a3-2 (-> obj collide-bounds))
)
(.lvf vf2 (&-> a2-11 world-sphere quad))
(.lvf vf3 (&-> a3-2 quad))
)
(.sub.vf vf1 vf3 vf2)
(.mul.vf vf1 vf1 vf1)
(.add.y.vf vf1 vf1 vf1 :mask #b1)
(.add.z.vf vf1 vf1 vf1 :mask #b1)
(.mov a2-12 vf1)
(let ((f0-1 a2-12)
(f1-5 (+ (-> a1-14 world-sphere w) (-> obj collide-bounds r)))
)
(b! (>= f0-1 (* f1-5 f1-5)) cfg-17 :delay #f)
)
)
)
(b! (>= *actor-list-length* 256) cfg-17 :delay #f)
(set! (-> *actor-list* *actor-list-length*) (the-as collide-shape a0-6))
)
(set! *actor-list-length* (+ *actor-list-length* 1))
(label cfg-17)
(set! a0-5 v1-18)
*collide-hit-by-player-list*
(set! v1-18 (-> v1-18 next0))
)
(label cfg-18)
(b! (!= a0-5 (-> *collide-hit-by-player-list* alive-list-end)) cfg-13 :delay (nop!))
)
(label cfg-20)
(let ((s5-0 0))
(b! #t cfg-29 :delay (nop!))
(label cfg-21)
(let* ((v1-23 (-> *actor-list* s5-0))
(a0-9 (-> v1-23 root-prim))
)
(when (logtest? (-> a0-9 prim-core collide-as) (collide-spec jak bot enemy hit-by-others-list player-list))
(.lvf vf1 (&-> obj collide-bounds quad))
(.lvf vf2 (&-> a0-9 prim-core world-sphere quad))
(.sub.vf vf3 vf1 vf2)
(.add.w.vf vf4 vf1 vf2 :mask #b1000)
(.mul.vf vf3 vf3 vf3 :mask #b111)
(.mul.w.vf vf4 vf4 vf4 :mask #b1000)
(.mul.x.vf acc vf0 vf3 :mask #b1000)
(.add.mul.y.vf acc vf0 vf3 acc :mask #b1000)
(.add.mul.z.vf vf3 vf0 vf3 acc :mask #b1000)
(.sub.w.vf vf3 vf3 vf4 :mask #b1000)
(let ((f0-2 0.0))
(.add.w.vf vf3 vf0 vf3 :mask #b1)
(.mov a0-10 vf3)
(let ((s4-0 (-> v1-23 process)))
(b! (< f0-2 a0-10) cfg-27)
(let ((a1-29 (if (type? s4-0 process-focusable)
s4-0
)
)
)
(if a1-29
(push-process obj (the-as process-focusable a1-29))
)
)
)
)
(label cfg-27)
0
)
)
(+! s5-0 1)
(label cfg-29)
(b! (< s5-0 *actor-list-length*) cfg-21)
)
0
(none)
)
)
(defmethod setup flow-control ((obj flow-control))
(local-vars (sv-32 flow-section) (sv-48 flow-section))
(let* ((s5-0 (-> obj path))
(s4-0 (-> s5-0 curve num-cverts))
(s3-0 (new 'stack-no-clear 'vector))
)
(let ((s2-0 (new 'process 'flow-section-array (+ s4-0 -1))))
(set! (-> obj sections) s2-0)
(set! (-> obj collide-bounds quad) (the-as uint128 0))
(get-point-in-path! s5-0 s3-0 0.0 'interp)
(vector+! (the-as vector (-> obj collide-bounds)) (the-as vector (-> obj collide-bounds)) s3-0)
(let ((s1-0 (+ s4-0 -1)))
(set! sv-32 (the-as flow-section #f))
(dotimes (s0-0 s1-0)
(set! sv-48 (-> s2-0 data s0-0))
(set! (-> sv-48 start quad) (-> s3-0 quad))
(get-point-in-path! s5-0 s3-0 (the float (+ s0-0 1)) 'interp)
(vector+! (the-as vector (-> obj collide-bounds)) (the-as vector (-> obj collide-bounds)) s3-0)
(vector-! (-> sv-48 pull-dir) s3-0 (-> sv-48 start))
(vector-normalize! (-> sv-48 pull-dir) 1.0)
(set! (-> sv-48 trailing quad) (-> sv-48 pull-dir quad))
(set! (-> sv-48 trailing y) 0.0)
(vector-normalize! (-> sv-48 trailing) 1.0)
(set-vector! (-> sv-48 radial-dir) (- (-> sv-48 trailing z)) 0.0 (-> sv-48 trailing x) 1.0)
(set! (-> sv-48 trailing w) (- (vector-dot s3-0 (the-as vector (-> sv-48 trailing)))))
(when sv-32
(vector+!
(the-as vector (-> sv-32 trailing))
(the-as vector (-> sv-32 trailing))
(the-as vector (-> sv-48 trailing))
)
(vector-normalize! (-> sv-32 trailing) 1.0)
(set! (-> sv-32 trailing w) (- (vector-dot (-> sv-48 start) (the-as vector (-> sv-32 trailing)))))
)
(set! sv-32 sv-48)
sv-32
)
)
)
(let ((s2-1 (-> obj sections data)))
(set! (-> obj leading quad) (-> s2-1 0 pull-dir quad))
(set! (-> obj leading y) 0.0)
(vector-normalize! (-> obj leading) 1.0)
(set! (-> obj leading w) (- (vector-dot (the-as vector (-> s2-1 0)) (the-as vector (-> obj leading)))))
)
(let ((f0-19 (/ 1.0 (the float s4-0)))
(f30-0 0.0)
)
(vector-float*! (the-as vector (-> obj collide-bounds)) (the-as vector (-> obj collide-bounds)) f0-19)
(dotimes (s2-2 s4-0)
(get-point-in-path! s5-0 s3-0 (the float s2-2) 'interp)
(let ((f0-22 (vector-vector-distance-squared s3-0 (-> obj collide-bounds))))
(if (< f30-0 f0-22)
(set! f30-0 f0-22)
)
)
)
(set! (-> obj collide-bounds r) (+ (sqrtf f30-0) (-> obj belt-radius)))
)
)
0
(none)
)
(defmethod new flow-control ((allocation symbol) (type-to-make type) (arg0 process-drawable) (arg1 res-lump))
(if (not arg1)
(set! arg1 (-> arg0 entity))
)
(let ((s5-0 (object-new allocation type-to-make (the-as int (-> type-to-make size)))))
(when (nonzero? s5-0)
(let ((v1-6 (new 'process 'curve-control arg0 'flow -1000000000.0)))
(cond
((nonzero? v1-6)
(set! (-> s5-0 path) v1-6)
(logior! (-> v1-6 flags) (path-control-flag display draw-line draw-point draw-text))
(if (< (-> v1-6 curve num-cverts) 2)
(go process-drawable-art-error "bad flow path")
)
(set! (-> s5-0 speed) (res-lump-float arg1 'speed :default 12288.0))
(set! (-> s5-0 belt-radius) (res-lump-float arg1 'extra-radius :default 16384.0))
(setup s5-0)
)
(else
(go process-drawable-art-error "no flow path")
)
)
)
)
s5-0
)
)