jak-project/goal_src/jak3/engine/debug/memory-usage.gc
Hat Kid 93afb02cf4
decomp3: spawn target, add merc and particle buckets and some temporary hacks (#3445)
This includes all the collision stuff needed to spawn `target`,
decompiles the sparticle code and adds some of the PC hacks needed for
merc to run (it doesn't work quite right and looks bad, likely due to a
combination of code copied from Jak 2 and the time of day hacks).

There are a bunch of temporary hacks (see commits) in place to prevent
the game from crashing quite as much, but it is still extremely prone to
doing so due to lots of missing functions/potentially bad decomp.

---------

Co-authored-by: water <awaterford111445@gmail.com>
2024-04-05 00:07:39 -04:00

575 lines
22 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
;; name: memory-usage.gc
;; name in dgo: memory-usage
;; dgos: GAME
;; DECOMP BEGINS
;; this file is debug only
(declare-file (debug))
(defmethod mem-usage ((this object) (usage memory-usage-block) (flags int))
this
)
(defmethod calculate-total ((this memory-usage-block))
(let ((v0-0 0))
(dotimes (v1-0 (-> this length))
(+! v0-0 (-> this data v1-0 total))
)
v0-0
)
)
(defmethod reset! ((this memory-usage-block))
(set! (-> this length) 0)
(dotimes (v1-0 113)
(set! (-> this data v1-0 used) 0)
(set! (-> this data v1-0 total) 0)
(set! (-> this data v1-0 count) 0)
)
this
)
(defun mem-size ((arg0 basic) (arg1 symbol) (arg2 int))
(let ((gp-0 (new 'stack 'memory-usage-block)))
(mem-usage arg0 gp-0 arg2)
(if arg1
(inspect gp-0)
)
(calculate-total gp-0)
)
)
(defmethod compute-memory-usage! ((this level) (arg0 symbol))
(if (zero? (-> this mem-usage-block))
(set! (-> this mem-usage-block) (new 'debug 'memory-usage-block))
)
(set! arg0 (or (zero? (-> this mem-usage-block length)) arg0))
(when arg0
(mem-usage this (reset! (-> this mem-usage-block)) 0)
(set! (-> this mem-usage) (calculate-total (-> this mem-usage-block)))
0
)
(-> this mem-usage-block)
)
(defmethod mem-usage ((this process-tree) (usage memory-usage-block) (flags int))
(let ((s3-0 91))
(let* ((s2-0 *dead-pool-list*)
(a0-1 (car s2-0))
)
(while (not (null? s2-0))
(set! (-> usage data s3-0 name) (symbol->string-debug (the-as symbol a0-1)))
(+! s3-0 1)
(set! s2-0 (cdr s2-0))
(set! a0-1 (car s2-0))
)
)
(set! (-> usage length) (max (-> usage length) s3-0))
)
(set! (-> usage data 97 name) "*debug-dead-pool*")
(set! *temp-mem-usage* usage)
(when (logtest? flags 32)
(let* ((s5-1 91)
(s4-1 *dead-pool-list*)
(v1-10 (car s4-1))
)
(while (not (null? s4-1))
(let ((a0-4 (-> (the-as symbol v1-10) value)))
(set! *global-search-count* s5-1)
(iterate-process-tree
(the-as process-tree a0-4)
(lambda ((arg0 basic))
(let ((gp-0 *temp-mem-usage*)
(s5-0 *global-search-count*)
)
(+! (-> gp-0 data s5-0 used) 1)
(+! (-> gp-0 data s5-0 total) (logand -16 (+ (asize-of arg0) 15)))
)
#t
)
*null-kernel-context*
)
)
(+! s5-1 1)
(set! s4-1 (cdr s4-1))
(set! v1-10 (car s4-1))
)
)
)
(iterate-process-tree
this
(lambda ((arg0 process-drawable))
(let ((gp-0 *temp-mem-usage*))
(let ((s4-0 (cond
((= (-> arg0 pool) *8k-dead-pool*)
92
)
((= (-> arg0 pool) *16k-dead-pool*)
93
)
((= (-> arg0 pool) *nk-dead-pool*)
94
)
((= (-> arg0 pool) *target-dead-pool*)
95
)
((= (-> arg0 pool) *camera-dead-pool*)
96
)
((= (-> arg0 pool) *debug-dead-pool*)
97
)
(else
91
)
)
)
)
(+! (-> gp-0 data s4-0 count) 1)
(+! (-> gp-0 data s4-0 total) (logand -16 (+ (asize-of arg0) 15)))
)
(set! (-> gp-0 length) (max 99 (-> gp-0 length)))
(set! (-> gp-0 data 98 name) "process-active")
(+! (-> gp-0 data 98 count) 1)
(let ((v1-23 (asize-of arg0)))
(+! (-> gp-0 data 98 used) v1-23)
(+! (-> gp-0 data 98 total) (logand -16 (+ v1-23 15)))
)
(set! (-> gp-0 length) (max 100 (-> gp-0 length)))
(set! (-> gp-0 data 99 name) "heap-total")
(+! (-> gp-0 data 99 count) 1)
(let ((v1-34 (+ (- -4 (the-as int arg0)) (the-as int (-> arg0 heap-cur)))))
(+! (-> gp-0 data 99 used) v1-34)
(+! (-> gp-0 data 99 total) (logand -16 (+ v1-34 15)))
)
(set! (-> gp-0 length) (max 101 (-> gp-0 length)))
(set! (-> gp-0 data 100 name) "heap-process")
(+! (-> gp-0 data 100 count) 1)
(let ((v1-45 (- (-> arg0 type size) (-> arg0 type heap-base))))
(+! (-> gp-0 data 100 used) v1-45)
(+! (-> gp-0 data 100 total) (logand -16 (+ v1-45 15)))
)
(set! (-> gp-0 length) (max 102 (-> gp-0 length)))
(set! (-> gp-0 data 101 name) "heap-header")
(+! (-> gp-0 data 101 count) 1)
(let ((v1-55 (-> arg0 type heap-base)))
(+! (-> gp-0 data 101 used) v1-55)
(+! (-> gp-0 data 101 total) (logand -16 (+ v1-55 15)))
)
(set! (-> gp-0 length) (max 103 (-> gp-0 length)))
(set! (-> gp-0 data 102 name) "heap-thread")
(+! (-> gp-0 data 102 count) 1)
(let ((v1-65 (asize-of (-> arg0 main-thread))))
(+! (-> gp-0 data 102 used) v1-65)
(+! (-> gp-0 data 102 total) (logand -16 (+ v1-65 15)))
)
(when (type? arg0 process-drawable)
(when (nonzero? (-> arg0 root))
(set! (-> gp-0 length) (max 104 (-> gp-0 length)))
(set! (-> gp-0 data 103 name) "heap-root")
(+! (-> gp-0 data 103 count) 1)
(let ((v1-78 (asize-of (-> arg0 root))))
(+! (-> gp-0 data 103 used) v1-78)
(+! (-> gp-0 data 103 total) (logand -16 (+ v1-78 15)))
)
(when (type? (-> arg0 root) collide-shape)
(set! (-> gp-0 length) (max 110 (-> gp-0 length)))
(set! (-> gp-0 data 109 name) "heap-collide-prim")
(+! (-> gp-0 data 109 count) 1)
(let ((v1-90 (asize-of (-> (the-as collide-shape-moving (-> arg0 root)) root-prim))))
(+! (-> gp-0 data 109 used) v1-90)
(+! (-> gp-0 data 109 total) (logand -16 (+ v1-90 15)))
)
)
)
(when (nonzero? (-> arg0 node-list))
(set! (-> gp-0 length) (max 107 (-> gp-0 length)))
(set! (-> gp-0 data 106 name) "heap-cspace")
(+! (-> gp-0 data 106 count) 1)
(let ((v1-102 (asize-of (-> arg0 node-list))))
(+! (-> gp-0 data 106 used) v1-102)
(+! (-> gp-0 data 106 total) (logand -16 (+ v1-102 15)))
)
)
(when (nonzero? (-> arg0 draw))
(set! (-> gp-0 length) (max 105 (-> gp-0 length)))
(set! (-> gp-0 data 104 name) "heap-draw-control")
(+! (-> gp-0 data 104 count) 1)
(let ((v1-114 (asize-of (-> arg0 draw))))
(+! (-> gp-0 data 104 used) v1-114)
(+! (-> gp-0 data 104 total) (logand -16 (+ v1-114 15)))
)
(when (nonzero? (-> arg0 draw skeleton))
(set! (-> gp-0 length) (max 108 (-> gp-0 length)))
(set! (-> gp-0 data 107 name) "heap-bone")
(+! (-> gp-0 data 107 count) 1)
(let ((v1-128 (asize-of (-> arg0 draw skeleton))))
(+! (-> gp-0 data 107 used) v1-128)
(+! (-> gp-0 data 107 total) (logand -16 (+ v1-128 15)))
)
)
)
(when (nonzero? (-> arg0 skel))
(set! (-> gp-0 length) (max 106 (-> gp-0 length)))
(set! (-> gp-0 data 105 name) "heap-joint-control")
(+! (-> gp-0 data 105 count) 1)
(let ((v1-140 (asize-of (-> arg0 skel))))
(+! (-> gp-0 data 105 used) v1-140)
(+! (-> gp-0 data 105 total) (logand -16 (+ v1-140 15)))
)
)
(when (nonzero? (-> arg0 part))
(set! (-> gp-0 length) (max 109 (-> gp-0 length)))
(set! (-> gp-0 data 108 name) "heap-part")
(+! (-> gp-0 data 108 count) 1)
(let ((v1-152 (asize-of (-> arg0 part))))
(+! (-> gp-0 data 108 used) v1-152)
(+! (-> gp-0 data 108 total) (logand -16 (+ v1-152 15)))
)
)
(when (nonzero? (-> arg0 nav))
(set! (-> gp-0 length) (max 111 (-> gp-0 length)))
(set! (-> gp-0 data 110 name) "heap-misc")
(+! (-> gp-0 data 110 count) 1)
(let ((v1-164 (asize-of (-> arg0 nav))))
(+! (-> gp-0 data 110 used) v1-164)
(+! (-> gp-0 data 110 total) (logand -16 (+ v1-164 15)))
)
)
(when (nonzero? (-> arg0 path))
(set! (-> gp-0 length) (max 111 (-> gp-0 length)))
(set! (-> gp-0 data 110 name) "heap-misc")
(+! (-> gp-0 data 110 count) 1)
(let ((v1-176 (asize-of (-> arg0 path))))
(+! (-> gp-0 data 110 used) v1-176)
(+! (-> gp-0 data 110 total) (logand -16 (+ v1-176 15)))
)
)
(when (nonzero? (-> arg0 vol))
(set! (-> gp-0 length) (max 111 (-> gp-0 length)))
(set! (-> gp-0 data 110 name) "heap-misc")
(+! (-> gp-0 data 110 count) 1)
(let ((v1-188 (asize-of (-> arg0 vol))))
(+! (-> gp-0 data 110 used) v1-188)
(+! (-> gp-0 data 110 total) (logand -16 (+ v1-188 15)))
)
)
)
)
#t
)
*null-kernel-context*
)
this
)
(define *max-dma* 0)
(defmethod print-mem-usage ((this memory-usage-block) (arg0 level) (arg1 object))
(local-vars (sv-16 object) (sv-32 string) (sv-48 symbol))
(let ((s3-0 (&- (-> arg0 heap current) (the-as uint (-> arg0 heap base)))))
(let ((v1-2 (+ (-> this data 62 total) (-> this data 63 total))))
(< #x10000 v1-2)
)
(let* ((v1-4 (-> arg0 info memory-mode))
(v1-5
(cond
((= v1-4 (level-memory-mode large))
#xbd0000
)
((= v1-4 (level-memory-mode medium))
#x8fb800
)
((or (= v1-4 (level-memory-mode small-center)) (= v1-4 (level-memory-mode city-center)))
#x627000
)
((or (= v1-4 (level-memory-mode borrow))
(= v1-4 (level-memory-mode borrow0))
(= v1-4 (level-memory-mode borrow1))
(= v1-4 (level-memory-mode borrow2))
(= v1-4 (level-memory-mode borrow3))
(= v1-4 (level-memory-mode borrow4))
(= v1-4 (level-memory-mode borrow-city-small))
)
(+ (- #xc000 (the-as int (-> arg0 heap base))) (the-as int (-> arg0 heap top-base)))
)
((or (= v1-4 (level-memory-mode tiny-center))
(= v1-4 (level-memory-mode tiny-edge))
(= v1-4 (level-memory-mode city-tiny-edge))
(= v1-4 (level-memory-mode tiny))
)
#x3f0000
)
((= v1-4 (level-memory-mode micro))
#x1f8000
)
((= v1-4 (level-memory-mode tiny-center-micro))
#x2f4000
)
((= v1-4 (level-memory-mode tiny-center-small))
#x4ec000
)
(else
#x5e8000
)
)
)
(a0-25 (-> arg0 info memory-mode))
(v1-8
(- (the-as int v1-5)
(the-as
uint
(if (or (= a0-25 (level-memory-mode tiny-center)) (or (= a0-25 (level-memory-mode tiny-edge))
(= a0-25 (level-memory-mode city-tiny-edge))
(= a0-25 (level-memory-mode tiny))
)
)
#x24000
#xc000
)
)
)
)
(a0-28 0)
)
(when (-> arg0 info borrow)
(dotimes (a1-21 5)
(+! a0-28 (-> arg0 info borrow borrow-size a1-21))
)
)
(let ((s1-0 (- v1-8 (shl a0-28 10)))
(s2-0 (* (dma-buffer-length (-> *display* frames (-> *display* last-screen) global-buf)) 16))
)
(set! *max-dma* (max s2-0 *max-dma*))
(if (< (- s1-0 (the-as int (shl (-> arg0 info buffer-size) 10))) s3-0)
(format arg1 "~3L")
)
(let ((s0-0 format))
(set! sv-16 arg1)
(set! sv-32 "~0K~10,'-S--~5,'-DK-of-~5,'-DK--~5,'-DK-of-~5,'-DK--")
(set! sv-48 (-> arg0 name))
(let* ((s3-1 (sar s3-0 10))
(s4-1 (- (sar s1-0 10) (the-as int (-> arg0 info buffer-size))))
(s1-1 (sar (memory-used *nk-dead-pool*) 10))
(t2-0 (sar (memory-total *nk-dead-pool*) 10))
(t0-0 s4-1)
(t1-0 s1-1)
)
(s0-0 sv-16 sv-32 sv-48 s3-1 t0-0 t1-0 t2-0)
(format arg1 "~5,'-DK/~5,'-DK--~%" (shr s2-0 10) (sar *max-dma* 10))
(when *stats-memory-short*
(let ((s3-2 (if (cpad-hold? 1 l3)
#t
arg1
)
)
(s4-2 format)
(s2-1 "heap-~5,'-DK/~5,'-DK----~D---~D/~D~%")
(s1-2 (sar (memory-used *nk-dead-pool*) 10))
(s0-1 (sar (memory-total *nk-dead-pool*) 10))
)
(set! t0-0 (the-as int (compact-time *nk-dead-pool*)))
(set! t1-0 (the-as int (-> *nk-dead-pool* compact-count)))
(set! t2-0 (the-as int (-> *nk-dead-pool* compact-count-targ)))
(s4-2 s3-2 s2-1 s1-2 s0-1 (the-as uint t0-0) (the-as uint t1-0) (the-as uint t2-0))
)
)
(when (not *stats-memory-short*)
(set! (-> *dma-mem-usage* data 88 total)
(* (dma-buffer-length (-> *display* frames (-> *display* last-screen) debug-buf)) 16)
)
(let ((t9-11 format)
(a0-47 arg1)
(a1-28 " bsp ~192H~5DK ~280Hdebug~456H~5DK~%")
(a2-12 (sar (+ (-> this data 59 total) (-> this data 60 total) (-> this data 61 total)) 10))
(a3-5 (sar (-> *dma-mem-usage* data 88 total) 10))
)
(t9-11 a0-47 a1-28 a2-12 a3-5 (the-as none t0-0) (the-as none t1-0) (the-as none t2-0))
(format
arg1
" bsp-leaf-vis ~192H~5DK~%"
(sar (+ (-> this data 62 total) (-> this data 63 total)) 10)
(the-as none a3-5)
)
(format arg1 " level-code ~192H~5DK~%" (sar (-> this data 66 total) 10) (the-as none a3-5))
)
(format
arg1
" tfrag ~192H~5DK ~280Htfragment~456H~5DK~%"
(sar
(+ (-> this data 1 total)
(-> this data 2 total)
(-> this data 3 total)
(-> this data 4 total)
(-> this data 5 total)
(-> this data 6 total)
(-> this data 7 total)
(-> this data 8 total)
)
10
)
(sar (-> *dma-mem-usage* data 1 total) 10)
)
(format
arg1
" tie-proto ~192H~5DK ~280Hsky~456H~5DK~%"
(sar
(+ (-> this data 9 total)
(-> this data 10 total)
(-> this data 11 total)
(-> this data 12 total)
(-> this data 13 total)
(-> this data 14 total)
(-> this data 16 total)
(-> this data 17 total)
)
10
)
(sar (-> *dma-mem-usage* data 89 total) 10)
)
(format
arg1
" tie-instance ~192H~5DK ~280Htie-fragment~456H~5DK~%"
(sar (+ (-> this data 18 total) (-> this data 20 total) (-> this data 21 total) (-> this data 22 total)) 10)
(sar (-> *dma-mem-usage* data 9 total) 10)
)
(format
arg1
" shrub-proto ~192H~5DK ~280Htie-scissor~456H~5DK~%"
(sar
(+ (-> this data 25 total)
(-> this data 26 total)
(-> this data 27 total)
(-> this data 28 total)
(-> this data 29 total)
(-> this data 30 total)
(-> this data 31 total)
(-> this data 32 total)
(-> this data 33 total)
)
10
)
(sar (-> *dma-mem-usage* data 15 total) 10)
)
(format
arg1
" shrub-instance ~192H~5DK ~280Hshrubbery~456H~5DK~%"
(sar (-> this data 34 total) 10)
(sar (-> *dma-mem-usage* data 27 total) 10)
)
(format
arg1
" hfragment ~192H~5DK ~280Hhfragment~456H~5DK~%"
(sar (-> this data 43 total) 10)
(sar (-> *dma-mem-usage* data 43 total) 10)
(the-as none t0-0)
(the-as none t1-0)
(the-as none t2-0)
)
(format
arg1
" collision ~192H~5DK ~280Htie-generic~456H~5DK~%"
(sar
(+ (-> this data 51 total)
(-> this data 52 total)
(-> this data 53 total)
(-> this data 54 total)
(-> this data 55 total)
(-> this data 56 total)
(-> this data 57 total)
(-> this data 58 total)
)
10
)
(sar (-> *dma-mem-usage* data 17 total) 10)
)
(format
arg1
" pris-geo ~192H~5DK ~280Hpris-fragment~456H~5DK~%"
(sar
(+ (-> this data 35 total)
(-> this data 36 total)
(-> this data 37 total)
(-> this data 38 total)
(-> this data 39 total)
(-> this data 40 total)
(-> this data 41 total)
(-> this data 42 total)
(-> this data 74 total)
(-> this data 75 total)
(-> this data 76 total)
(-> this data 77 total)
(-> this data 79 total)
(-> this data 82 total)
(-> this data 81 total)
(-> this data 112 total)
)
10
)
(sar (-> *dma-mem-usage* data 35 total) 10)
)
(format
arg1
" pris-anim ~192H~5DK ~280Hpris-generic~456H~5DK~%"
(sar
(+ (-> this data 68 total)
(-> this data 69 total)
(-> this data 70 total)
(-> this data 71 total)
(-> this data 72 total)
(-> this data 78 total)
(-> this data 80 total)
(-> this data 73 total)
)
10
)
(sar (-> *dma-mem-usage* data 90 total) 10)
)
(format
arg1
" textures ~192H~5DK ~280Htextures~456H~5DK~%"
(sar (-> this data 83 total) 10)
(sar (-> *dma-mem-usage* data 83 total) 10)
)
(format arg1 " entity ~192H~5DK~%" (sar
(+ (-> this data 67 total)
(-> this data 44 total)
(-> this data 45 total)
(-> this data 46 total)
(-> this data 50 total)
(-> this data 49 total)
(-> this data 47 total)
(-> this data 48 total)
)
10
)
)
(format
arg1
" misc ~192H~5DK ~280Hsprite~456H~5DK~%"
(sar
(+ (-> this data 0 total)
(-> this data 64 total)
(-> this data 65 total)
(-> this data 84 total)
(-> this data 85 total)
)
10
)
(sar (-> *dma-mem-usage* data 86 total) 10)
)
)
)
)
)
)
)
(format arg1 "~1K~0L")
this
)