Files
jak-project/goal_src/jak1/engine/debug/part-tester.gc
T
2026-07-28 12:00:35 -07:00

107 lines
4.6 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
(bundles "ENGINE.CGO" "GAME.CGO")
(require "engine/gfx/sprite/sparticle/sparticle-launcher.gc")
(require "engine/debug/debug.gc")
(#when PC_PORT
(define *part-tester-id* 105))
;; Particle test harness. `start-part` spawns one part-tester, which spawns the
;; particle group named below once per frame's worth of state change and draws a
;; cross where it is spawning from. The group under test is chosen by editing the
;; source (or, on PC, by setting *part-tester-id* from the debug menu), and the
;; spawn position follows either the anim-tester, the player, or a named entity.
;; DECOMP BEGINS
;; this file is debug only
(declare-file (debug))
(defpartgroup group-part-tester
:id 105
:bounds (static-bspherem 0 0 0 1)
:parts ((sp-item 56) (sp-item 57)))
(deftype part-tester (process)
((root trsqv)
(part sparticle-launch-control) ;; launcher for the group under test
(old-group sparticle-launch-group)) ;; group the launcher was built for
:heap-base #x100)
(define-extern *part-tester* part-tester)
;; Set from the listener to follow an entity by name; #f follows nothing.
(define *part-tester-name* (the-as string #f))
(defmethod deactivate ((this part-tester))
"Kill the particles this tester launched before the process goes away."
(if (nonzero? (-> this part)) (kill-and-free-particles (-> this part)))
((method-of-type process deactivate) this)
(none))
;; Spawn the group under test every frame, rebuilding the launch control whenever
;; the group changes.
(defstate part-tester-idle (part-tester)
:code
(behavior ()
(loop
;; follow the named entity if there is one: its process if it has one with a
;; collide-shape, otherwise the position the entity was placed at
(let ((ent (entity-by-name *part-tester-name*)))
(when ent
(let ((proc (-> ent extra process)))
(if (and proc (type-type? (-> proc type) process-drawable) (nonzero? (-> (the-as process-drawable proc) root)))
(vector-copy! (-> self root trans) (-> (the-as process-drawable proc) root trans))
(vector-copy! (-> self root trans) (-> ent extra trans))))))
(add-debug-x #t
(bucket-id debug-no-zbuf)
(-> self root trans)
(the-as rgba (new 'static 'rgba :r #xff :g #xff :b #xff :a #x80)))
;; og:preserve-this
;; change this line to change the particle group to test
;; notes:
;; - particles that use aux list won't work (warp parts)
;; - some particles may have callbacks that won't work yet
(let ((group (-> *part-group-id-table* 105)))
(#when PC_PORT
(if (nonzero? (-> *part-group-id-table* *part-tester-id*)) (set! group (-> *part-group-id-table* *part-tester-id*))))
(let ((pos (-> self root trans)))
(when (!= group (-> self old-group))
;; rewind the process heap over the old launch control instead of
;; leaking one per group change
(when (nonzero? (-> self part))
(kill-and-free-particles (-> self part))
(set! (-> self heap-cur) (&-> (-> self part) type)))
(set! (-> self part) (create-launch-control group self)))
;; a screen-space group is positioned in screen coordinates, so it gets
;; the origin rather than the tester's position
(if (nonzero? (-> self part))
(spawn (-> self part)
(cond
((logtest? (-> group flags) (sp-group-flag screen-space)) *zero-vector*)
(else (empty) pos)))))
(set! (-> self old-group) group))
(suspend))))
(defbehavior part-tester-init-by-other process-drawable ((pos vector))
"Give the new tester a trsqv at pos and start it running. Declared on
process-drawable because part-tester's root sits where a process-drawable's
does, even though part-tester is a plain process."
(set! (-> self root) (new 'process 'trsqv))
(vector-copy! (-> self root trans) pos)
(set! *part-tester* (the-as part-tester (process->ppointer self)))
(go part-tester-idle)
(none))
(define-perm *debug-part-dead-pool* dead-pool (new 'debug 'dead-pool 1 #x10000 '*debug-part-dead-pool*))
(defun start-part ()
"Restart the particle tester at the anim-tester's position, or the player's if
the anim-tester is not running. Only one is ever alive."
(kill-by-type part-tester *active-pool*)
(process-spawn part-tester
(if *anim-tester* (-> *anim-tester* 0 root trans) (target-pos 0))
:from
*debug-part-dead-pool*)
(none))