jak-project/goal_src/jak3/levels/factory/conveyor.gc
Hat Kid e2e5289788
decomp3: font widescreen and shadow hacks, generic renderer, misc files (#3483)
- `pecker-ingame`
- `des-bbush-tasks`
- `des-burning-bush`
- `des-bush-part`
- `des-bush`
- `mh-centipede`
- `mh-centipede-part`
- `mh-wasp`
- `mh-wasp-part`
- `needle-fish`
- `des-bush-time-chase`
- `timer-path`
- `mission-squad-control-h`
- `mh-bat`
- `hover-nav-factoryd`
- `hover-nav-factoryc`
- `conveyor`
- `fac-part`
- `factory-part`
- `factoryc-mood`
- `factoryc-obs`
- `factoryc-obs2`
- `lfaccar-init`
- `factory-boss-part`
- `factory-boss-scenes`
- `factory-boss-setup`
- `factory-boss-states`
- `factory-mood`
- `factoryc-manager`
- `lfacrm1-mood`
- `lfacrm2-mood`
- `missile-bot`
- `sew-laser-turret`
- `ai-task-h`
- `ash-h`
- `ash-shot`
- `ash-states`
- `ash-task`
- `ash`
- `bot-h`
- `bot-states`
- `bot`
- `ash-oasis-course`
- `oasis-defense`
- `comb-field`
- `comb-mood`
- `comb-obs`
- `comb-part`
- `comb-scenes`
- `comb-sentry`
- `comb-travel`
- `comba-init`
- `combx-scenes`
- `h-sled`
- `destroy-dark-eco`
- `fac-gunturret`
- `fac-robotank-turret`
- `fac-robotank`
- `fac-tower`
- `factory-h`
- `factory-hud`
- `factory-manager`
- `factorya-init`
- `ffight-projectile`
- `ftank-projectile`
- `fturret-projectile`
- `h-warf`
- `warf-projectile`
2024-04-28 08:59:46 -04:00

385 lines
13 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
;; name: conveyor.gc
;; name in dgo: conveyor
;; dgos: FACC
;; DECOMP BEGINS
(deftype conveyor-section (structure)
((start vector :inline)
(trailing plane :inline)
(pull-dir vector :inline)
(radial-dir vector :inline)
)
)
(deftype conveyor-section-array (inline-array-class)
((data conveyor-section :inline :dynamic)
)
)
(set! (-> conveyor-section-array heap-base) (the-as uint 64))
(deftype conveyor (process-drawable)
((speed float)
(belt-radius float)
(pull-y-threshold float)
(speed-mult-array (pointer float))
(speed-mult-array-len int8)
(sections conveyor-section-array)
(leading plane :inline)
(collide-bounds sphere :inline)
)
(:state-methods
idle
)
(:methods
(conveyor-method-21 (_type_) float)
(get-skel (_type_) art-group)
(alloc-trsqv! (_type_) none)
(init-fields! (_type_) none)
(alloc-sound! (_type_) none)
(init-skel! (_type_) none)
(push-focus (_type_ process-focusable) symbol)
(find-pushables (_type_) symbol)
)
)
(defmethod relocate ((this conveyor) (offset int))
(&+! (-> this sections) offset)
(call-parent-method this offset)
)
;; WARN: Return type mismatch symbol vs art-group.
(defmethod get-skel ((this conveyor))
(the-as art-group #f)
)
(defmethod alloc-trsqv! ((this conveyor))
(set! (-> this root) (new 'process 'trsqv))
0
(none)
)
(defmethod init-fields! ((this conveyor))
(local-vars (sv-16 res-tag))
(set! (-> this speed) 24576.0)
(set! (-> this belt-radius) 11878.4)
(set! (-> this pull-y-threshold) 10240.0)
(set! (-> this speed-mult-array) (the-as (pointer float) #f))
(set! (-> this speed-mult-array-len) 0)
(let ((a0-1 (-> this entity)))
(set! sv-16 (new 'static 'res-tag))
(let ((v1-4 (res-lump-data a0-1 'scale-factor (pointer float) :tag-ptr (& sv-16))))
(when v1-4
(set! (-> this speed-mult-array) v1-4)
(set! (-> this speed-mult-array-len) (the-as int (-> sv-16 elt-count)))
)
)
)
0
(none)
)
;; WARN: Return type mismatch object vs none.
(defmethod alloc-sound! ((this conveyor))
(let ((v1-1 (res-lump-value (-> this entity) 'options uint128 :time -1000000000.0)))
(cond
((not (logtest? #x10000 v1-1))
(set! (-> this sound)
(new 'process 'ambient-sound (static-sound-spec "conveyor" :group 0 :fo-max 80) (-> this root trans) 0.0)
)
)
(else
(set! (-> this sound) (the-as ambient-sound 0))
0
)
)
)
(none)
)
(defmethod push-focus ((this conveyor) (arg0 process-focusable))
(let ((s4-0 (new 'stack-no-clear 'vector)))
(set! (-> s4-0 quad) (-> (get-trans arg0 0) quad))
(set! (-> s4-0 w) 1.0)
(when (>= (vector4-dot s4-0 (the-as vector (-> this leading))) 0.0)
(let* ((a1-2 (-> this sections))
(a2-0 (-> a1-2 length))
)
(dotimes (a0-3 a2-0)
(let ((v1-8 (-> a1-2 data a0-3)))
(when (< (vector4-dot s4-0 (the-as vector (-> v1-8 trailing))) 0.0)
(let ((a1-3 (new 'stack-no-clear 'vector)))
(vector-! a1-3 s4-0 (-> v1-8 start))
(when (>= (-> this belt-radius) (fabs (vector-dot a1-3 (-> v1-8 radial-dir))))
(let* ((f0-7 (vector-dot a1-3 (-> v1-8 pull-dir)))
(f1-6 (- (-> a1-3 y) (* (-> v1-8 pull-dir y) f0-7)))
)
(when (>= (-> this pull-y-threshold) (fabs f1-6))
(let ((a2-8 (new 'stack-no-clear 'vector)))
(let ((f0-10 (-> this speed)))
(if (< a0-3 (-> this speed-mult-array-len))
(set! f0-10 (* f0-10 (-> this speed-mult-array a0-3)))
)
(vector-float*! a2-8 (-> v1-8 pull-dir) (* f0-10 (seconds-per-frame)))
)
(send-event arg0 'push-trans a2-8 (seconds 10))
)
)
)
)
)
(return #f)
)
)
)
)
#f
)
)
)
(defmethod find-pushables ((this conveyor))
(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-box *actor-hash* (-> this 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 vehicle-sphere hit-by-others-list player-list)
)
(let ((a1-2 (-> a1-1 prim-core)))
(let ((a2-4 a1-2)
(a3-1 (-> this 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) (-> this 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))
)
)
)
)
(when #f
(let ((a0-5 (-> *collide-hit-by-player-list* alive-list next0)))
*collide-hit-by-player-list*
(let ((v1-18 (-> a0-5 next0)))
(while (!= a0-5 (-> *collide-hit-by-player-list* alive-list-end))
(let* ((a0-6 (-> (the-as connection a0-5) param1))
(a1-13 (-> (the-as collide-shape a0-6) root-prim))
)
(when (logtest? (-> a1-13 prim-core collide-as)
(collide-spec jak bot enemy vehicle-sphere hit-by-others-list player-list)
)
(let ((a1-14 (-> a1-13 prim-core)))
(let ((a2-11 a1-14)
(a3-2 (-> this 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) (-> this collide-bounds r)))
)
(when (< f0-1 (* f1-5 f1-5))
(when (< *actor-list-length* 256)
(set! (-> *actor-list* *actor-list-length*) (the-as collide-shape a0-6))
(set! *actor-list-length* (+ *actor-list-length* 1))
)
)
)
)
)
)
(set! a0-5 v1-18)
*collide-hit-by-player-list*
(set! v1-18 (-> v1-18 next0))
)
)
)
)
(dotimes (s5-0 *actor-list-length*)
(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 vehicle-sphere hit-by-others-list player-list)
)
(.lvf vf1 (&-> this 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-focus this (the-as process-focusable a1-29))
)
)
)
)
(label cfg-27)
0
)
)
)
#f
)
)
(defmethod conveyor-method-21 ((this conveyor))
(local-vars (sv-32 conveyor-section) (sv-48 conveyor-section))
(let* ((s5-0 (-> this path))
(s4-0 (-> s5-0 curve num-cverts))
(s3-0 (new 'stack-no-clear 'vector))
)
(let ((s2-0 (new 'process 'conveyor-section-array (+ s4-0 -1))))
(set! (-> this sections) s2-0)
(set! (-> this collide-bounds quad) (the-as uint128 0))
(get-point-in-path! s5-0 s3-0 0.0 'exact)
(vector+! (the-as vector (-> this collide-bounds)) (the-as vector (-> this collide-bounds)) s3-0)
(let ((s1-0 (+ s4-0 -1)))
(set! sv-32 (the-as conveyor-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)) 'exact)
(vector+! (the-as vector (-> this collide-bounds)) (the-as vector (-> this 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 (-> this sections data)))
(set! (-> this leading quad) (-> s2-1 0 pull-dir quad))
(set! (-> this leading y) 0.0)
(vector-normalize! (-> this leading) 1.0)
(set! (-> this leading w) (- (vector-dot (the-as vector (-> s2-1 0)) (the-as vector (-> this leading)))))
)
(let ((f0-19 (/ 1.0 (the float s4-0)))
(f30-0 0.0)
)
(vector-float*! (the-as vector (-> this collide-bounds)) (the-as vector (-> this collide-bounds)) f0-19)
(dotimes (s2-2 s4-0)
(get-point-in-path! s5-0 s3-0 (the float s2-2) 'exact)
(let ((f0-22 (vector-vector-distance-squared s3-0 (-> this collide-bounds))))
(if (< f30-0 f0-22)
(set! f30-0 f0-22)
)
)
)
(set! (-> this collide-bounds r) (+ (sqrtf f30-0) (-> this belt-radius)))
)
)
)
(defstate idle (conveyor)
:virtual #t
:code sleep-code
:post (behavior ()
(find-pushables self)
(if (nonzero? (-> self sound))
(update! (-> self sound))
)
)
)
;; WARN: Return type mismatch draw-control vs none.
(defmethod init-skel! ((this conveyor))
(if (get-skel this)
(initialize-skeleton this (the-as skeleton-group (get-skel this)) (the-as pair 0))
)
(none)
)
(defmethod init-from-entity! ((this conveyor) (arg0 entity-actor))
(alloc-trsqv! this)
(process-drawable-from-entity! this arg0)
(init-skel! this)
(set! (-> this path) (new 'process 'path-control this 'path 0.0 (the-as entity #f) #f))
(logior! (-> this path flags) (path-control-flag display draw-line draw-point draw-text))
(if (< (-> this path curve num-cverts) 2)
(go process-drawable-art-error "bad path")
)
(init-fields! this)
(alloc-sound! this)
(conveyor-method-21 this)
(go (method-of-object this idle))
)