Files
jak-project/goal_src/jak2/engine/gfx/texture/texture-anim-funcs.gc
T
Hat Kid 49e798f88c jak2: macro detection for launch-particles and seconds-per-frame, add og:preserve-this comments for manual patches (#2974)
This PR adds detection of the `launch-particles` and `seconds-per-frame`
macros to the decompiler, removing a lot of bloat and hiding many
process register uses.

I also added `og:preserve-this` comments to as many manual patches and
comments as I could, which will soon be used in conjunction with CI to
hopefully catch any regressions in future big decomp update PRs.

I have some concerns about the `launch-particles` macro (more details in
`sparticle-launcher.gc`) , but thus far, I have not seen anything break
yet.

---------

Co-authored-by: water <awaterford111445@gmail.com>
2023-09-10 11:48:56 -04:00

283 lines
11 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
;; name: texture-anim-funcs.gc
;; name in dgo: texture-anim-funcs
;; dgos: ENGINE, GAME
;; DECOMP BEGINS
(defun noise-texture-anim-layer-func ((dma-buf dma-buffer) (fbp-to-draw uint) (width int) (height int) (layer texture-anim-layer) (time float))
(when (and (>= time (-> layer start-time)) (< time (-> layer end-time)))
(texture-anim-layer-interp layer time)
(when (!= (-> layer interpolated-color w) 0.0)
(upload-vram-data dma-buf (the-as int (-> layer tex dest 0)) (the-as pointer (-> layer tex pad 0)) 32 32)
(dma-buffer-add-gs-set dma-buf (texflush 0))
(texture-anim-layer-add-shader dma-buf layer 1)
(let ((s1-0 (/ (+ width 63) 64)))
(dma-buffer-add-gs-set dma-buf (frame-1 (new 'static 'gs-frame :fbmsk #xffffff :fbw s1-0 :fbp fbp-to-draw)))
(texture-anim-layer-draw dma-buf width height layer)
(let* ((v1-13 dma-buf)
(a0-17 (the-as object (-> v1-13 base)))
)
(set! (-> (the-as dma-packet a0-17) dma) (new 'static 'dma-tag :qwc #x2 :id (dma-tag-id cnt)))
(set! (-> (the-as dma-packet a0-17) vif0) (new 'static 'vif-tag))
(set! (-> (the-as dma-packet a0-17) vif1) (new 'static 'vif-tag :imm #x2 :cmd (vif-cmd direct) :msk #x1))
(set! (-> v1-13 base) (&+ (the-as pointer a0-17) 16))
)
(let* ((v1-14 dma-buf)
(a0-19 (the-as object (-> v1-14 base)))
)
(set! (-> (the-as gs-gif-tag a0-19) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x1))
(set! (-> (the-as gs-gif-tag a0-19) regs) GIF_REGS_ALL_AD)
(set! (-> v1-14 base) (&+ (the-as pointer a0-19) 16))
)
(let ((v1-15 (-> dma-buf base)))
(set! (-> (the-as (pointer gs-frame) v1-15) 0) (new 'static 'gs-frame :fbw s1-0 :fbp fbp-to-draw))
(set! (-> (the-as (pointer gs-reg64) v1-15) 1) (gs-reg64 frame-1))
(set! (-> dma-buf base) (&+ v1-15 16))
)
)
)
)
0
)
(defun cloud-texture-anim-layer-func ((dma-buf dma-buffer) (fbp-to-draw uint) (width int) (height int) (layer texture-anim-layer) (time float))
(when (and (>= time (-> layer start-time)) (< time (-> layer end-time)))
(texture-anim-layer-interp layer time)
(when (!= (-> layer interpolated-color w) 0.0)
(let* ((v1-4 (-> layer tex))
(t0-1 (/ (-> v1-4 w) 2))
(a3-1 (/ (-> v1-4 h) 2))
)
;; og:preserve-this modified
;(upload-vram-data dma-buf (the-as int (-> v1-4 dest 0)) (the-as pointer (-> v1-4 pad 0)) a3-1 t0-1)
(pc-texture-anim-flag upload-generic-vram dma-buf :qwc 1)
(let ((upload-record (the texture-anim-pc-upload (-> dma-buf base))))
(set! (-> upload-record data) (the-as pointer (-> v1-4 pad 0))) ;; the clut16x16 object
(set! (-> upload-record width) t0-1)
(set! (-> upload-record height) a3-1)
(set! (-> upload-record dest) (-> v1-4 dest 0))
(set! (-> upload-record format) (gs-psm ct32))
(set! (-> upload-record force-to-gpu) 0)
)
(&+! (-> dma-buf base) 16)
)
;; og:preserve-this don't need
;(dma-buffer-add-gs-set dma-buf (texflush 0))
(texture-anim-layer-add-shader dma-buf layer 1)
(texture-anim-layer-draw dma-buf width height layer)
)
)
0
)
(defun cloud-texture-anim-func ((arg0 dma-buffer) (arg1 texture-anim))
(when (>= (+ (-> arg1 frame-time) (* (-> arg1 frame-delta) (seconds-per-frame))) (-> arg1 frame-mod))
(let ((s5-0 (-> arg1 data 0 tex))
(s4-0 (-> arg1 data 1 tex))
(s3-0 (-> arg1 data 0 tex w))
)
(when (not (paused?))
(set! (-> arg1 data 0 tex) s4-0)
(set! (-> arg1 data 1 tex) s5-0)
(make-noise-texture (the-as pointer (-> s5-0 pad 0)) s3-0 s3-0 s3-0)
)
)
)
0
)
(defun fog-texture-anim-init ((arg0 texture-anim))
(let ((gp-0 (new 'loading-level 'fog8x256))
(s4-0 (new 'loading-level 'clut16x16))
)
(when (and gp-0 s4-0)
(let ((v1-5 (new 'loading-level 'texture)))
(let ((a0-4 (the int (-> arg0 extra x)))
(a1-3 (the int (-> arg0 extra y)))
)
(set! (-> arg0 tex) v1-5)
(set! (-> v1-5 pad 0) (the-as uint gp-0))
(set! (-> v1-5 pad 1) (the-as uint s4-0))
(set! (-> v1-5 w) 256)
(set! (-> v1-5 h) 1)
(set! (-> v1-5 num-mips) (the-as uint 1))
(set! (-> v1-5 psm) (gs-psm mt8))
(set! (-> v1-5 clutpsm) (the-as uint 0))
(set! (-> v1-5 dest 0) (the-as uint (* a0-4 32)))
(set! (-> v1-5 clutdest) (the-as uint (* a1-3 32)))
)
(set! (-> v1-5 width 0) (the-as uint 4))
(set! (-> v1-5 masks data 0 mask quad) (the-as uint128 0))
(set! (-> v1-5 masks data 1 mask quad) (the-as uint128 0))
(set! (-> v1-5 masks data 2 mask quad) (the-as uint128 0))
)
0
(dotimes (v1-7 256)
(nop!)
(nop!)
(nop!)
(nop!)
(set! (-> gp-0 image v1-7) (the-as uint v1-7))
)
)
)
0
)
(define *fog-texture-work* (new 'static 'fog-texture-work :const (new 'static 'vector :x 0.00390625)))
;; WARN: Return type mismatch symbol vs int.
(defun real-fog-texture-anim-func ((arg0 dma-buffer) (arg1 texture-anim))
(local-vars (sv-48 int))
(let ((s4-0 (new 'stack-no-clear 'vector))
(s3-0 (new 'stack-no-clear 'vector))
(s1-0 *fog-texture-work*)
(s2-0 (the-as (pointer uint32) (-> arg1 tex pad 1)))
)
(let ((v1-1 (-> s1-0 color)))
(dotimes (a0-1 256)
(set! (-> s2-0 a0-1) v1-1)
)
)
(set! sv-48 0)
(let ((s0-0 0))
(let ((f0-0 40955904.0)
(f1-0 -40955904.0)
)
(dotimes (v1-7 4)
(let ((f2-0 (-> *fog-texture-work* corner v1-7 y)))
(when (< f2-0 f0-0)
(set! f0-0 f2-0)
(set! sv-48 v1-7)
sv-48
)
(when (< f1-0 f2-0)
(set! f1-0 f2-0)
(set! s0-0 v1-7)
)
)
)
)
(set! (-> s4-0 quad) (-> *fog-texture-work* corner sv-48 quad))
(vector-! s3-0 (-> *fog-texture-work* corner s0-0) (-> *fog-texture-work* corner sv-48))
(vector-float/! s3-0 s3-0 256.0)
(set! (-> *fog-texture-work* min-corner quad) (-> *fog-texture-work* corner sv-48 quad))
(set! (-> *fog-texture-work* max-corner quad) (-> *fog-texture-work* corner s0-0 quad))
)
0.0
0.0
(let ((f0-4 (fmax 4096.0 (-> *math-camera* trans y)))
(f1-2 (-> arg1 extra z))
(f2-1 (-> s1-0 alpha-near))
(f3-0 (-> s1-0 alpha-far))
(f4-0 (-> s1-0 alpha-delta))
(f5-0 (-> s1-0 fog-near))
(f6-0 (-> s1-0 fog-far))
(f7-0 (-> s1-0 fog-delta))
)
(dotimes (v1-19 256)
(let* ((f8-0 (-> s4-0 y))
(f8-1 (cond
((= f8-0 0.0)
f3-0
)
((< f8-0 0.0)
(let ((f9-4 (fmin f6-0 (/ (* f0-4 (vector-length s4-0)) (- f8-0)))))
(+ f2-1 (* f4-0 (/ (fmax 0.0 (- f9-4 f5-0)) f7-0)))
)
)
(else
(let ((f9-8 (fmin f6-0 (/ (* f1-2 (vector-length s4-0)) f8-0))))
(+ f2-1 (* f4-0 (/ (fmax 0.0 (- f9-8 f5-0)) f7-0)))
)
)
)
)
)
(set! (-> s2-0 (-> *clut-translate* v1-19))
(logior (logand (-> s2-0 (-> *clut-translate* v1-19)) (the-as uint #xffffffff00ffffff))
(shr (shl (the int (* 128.0 f8-1)) 56) 32)
)
)
)
(vector+! s4-0 s4-0 s3-0)
)
)
)
(let ((s5-1 (-> arg1 tex)))
;; og:preserve-this
;; they use bitbltbuf directly to upload in the format of the data, rather than
;; the usual PSM32 trick
; (dma-buffer-add-gs-set arg0
; (bitbltbuf
; (new 'static 'gs-bitbltbuf :dpsm (the-as int (-> s5-1 psm)) :dbp (-> s5-1 dest 0) :dbw (-> s5-1 width 0))
; )
; (trxpos (new 'static 'gs-trxpos))
; (trxreg (new 'static 'gs-trxreg :rrw (-> s5-1 w) :rrh (-> s5-1 h)))
; (trxdir (new 'static 'gs-trxdir))
; )
; (dma-buffer-add-ref-texture arg0 (the-as pointer (-> s5-1 pad 0)) (-> s5-1 w) (-> s5-1 h) (-> s5-1 psm))
(pc-texture-anim-flag upload-generic-vram arg0 :qwc 1)
(let ((upload-record (the texture-anim-pc-upload (-> arg0 base))))
(set! (-> upload-record data) (the-as pointer (-> s5-1 pad 0))) ;; the texture data
(set! (-> upload-record width) (-> s5-1 w)) ;; see fog-texture-anim-init, there's not cropping.
(set! (-> upload-record height) (-> s5-1 h))
(set! (-> upload-record dest) (-> s5-1 dest 0))
(set! (-> upload-record format) (-> s5-1 psm))
(set! (-> upload-record force-to-gpu) 1)
)
(&+! (-> arg0 base) 16)
;; and the clut
;(upload-vram-data arg0 (the-as int (-> s5-1 clutdest)) (the-as pointer (-> s5-1 pad 1)) 16 16)
(pc-texture-anim-flag upload-clut-16-16 arg0 :qwc 1)
(let ((upload-record (the texture-anim-pc-upload (-> arg0 base))))
(set! (-> upload-record data) (the-as pointer (-> s5-1 pad 1))) ;; the clut16x16 object
(set! (-> upload-record width) 16)
(set! (-> upload-record height) 16)
(set! (-> upload-record dest) (-> s5-1 clutdest))
(set! (-> upload-record format) (gs-psm ct32))
)
(&+! (-> arg0 base) 16)
(set! (-> *texture-pool* ids (shr (-> s5-1 clutdest) 6)) (the-as uint 0))
;; og:preserve-this just a texflush.
; (let* ((v1-29 arg0)
; (a0-51 (the-as object (-> v1-29 base)))
; )
; (set! (-> (the-as dma-packet a0-51) dma) (new 'static 'dma-tag :qwc #x2 :id (dma-tag-id cnt)))
; (set! (-> (the-as dma-packet a0-51) vif0) (new 'static 'vif-tag))
; (set! (-> (the-as dma-packet a0-51) vif1) (new 'static 'vif-tag :imm #x2 :cmd (vif-cmd direct) :msk #x1))
; (set! (-> v1-29 base) (&+ (the-as pointer a0-51) 16))
; )
; (let* ((v1-30 arg0)
; (a0-53 (the-as object (-> v1-30 base)))
; )
; (set! (-> (the-as gs-gif-tag a0-53) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x1))
; (set! (-> (the-as gs-gif-tag a0-53) regs) GIF_REGS_ALL_AD)
; (set! (-> v1-30 base) (&+ (the-as pointer a0-53) 16))
; )
; (let ((v1-31 (-> arg0 base)))
; (set! (-> (the-as (pointer int64) v1-31)) 0)
; (set! (-> (the-as (pointer gs-reg64) v1-31) 1) (gs-reg64 texflush))
; (set! (-> arg0 base) (&+ v1-31 16))
; )
(let ((v1-34 (shr (-> s5-1 dest 0) 6)))
(dotimes (a0-56 3)
(set! (-> *texture-pool* ids (+ v1-34 a0-56)) (the-as uint 0))
)
)
)
(the-as int #f)
)
(defun fog-texture-anim-func ((arg0 dma-buffer) (arg1 texture-anim))
(real-fog-texture-anim-func arg0 arg1)
)