mirror of
https://github.com/open-goal/jak-project
synced 2026-07-11 07:25:37 -04:00
d1ece445d4
Relates to #1353 This adds no new functionality or overhead to the compiler, yet. This is the preliminary work that has: - added code to the compiler in several spots to flag when something is used without being properly required/imported/whatever (disabled by default) - that was used to generate project wide file dependencies (some circulars were manually fixed) - then that graph underwent a transitive reduction and the result was written to all `jak1` source files. The next step will be making this actually produce and use a dependency graph. Some of the reasons why I'm working on this: - eliminates more `game.gp` boilerplate. This includes the `.gd` files to some extent (`*-ag` files and `tpage` files will still need to be handled) this is the point of the new `bundles` form. This should make it even easier to add a new file into the source tree. - a build order that is actually informed from something real and compiler warnings that tell you when you are using something that won't be available at build time. - narrows the search space for doing LSP actions -- like searching for references. Since it would be way too much work to store in the compiler every location where every symbol/function/etc is used, I have to do ad-hoc searches. By having a dependency graph i can significantly reduce that search space. - opens the doors for common shared code with a legitimate pattern. Right now jak 2 shares code from the jak 1 folder. This is basically a hack -- but by having an explicit require syntax, it would be possible to reference arbitrary file paths, such as a `common` folder. Some stats: - Jak 1 has about 2500 edges between files, including transitives - With transitives reduced at the source code level, each file seems to have a modest amount of explicit requirements. Known issues: - Tracking the location for where `defmacro`s and virtual state definitions were defined (and therefore the file) is still problematic. Because those forms are in a macro environment, the reader does not track them. I'm wondering if a workaround could be to search the reader's text_db by not just the `goos::Object` but by the text position. But for the purposes of finishing this work, I just statically analyzed and searched the code with throwaway python code.
178 lines
4.2 KiB
Common Lisp
178 lines
4.2 KiB
Common Lisp
;;-*-Lisp-*-
|
|
(in-package goal)
|
|
(bundles "ENGINE.CGO" "GAME.CGO")
|
|
|
|
(require "kernel-defs.gc")
|
|
|
|
;; name: memory-usage-h.gc
|
|
;; name in dgo: memory-usage-h
|
|
;; dgos: GAME, ENGINE
|
|
|
|
;; DECOMP BEGINS
|
|
|
|
;; this file is debug only
|
|
(declare-file (debug))
|
|
|
|
;; The memory-usage system is used to track how much memory is used by tracking statistics for categories.
|
|
;; It can be used in different ways for different objects.
|
|
;; - DMA memory usage per renderer
|
|
;; - static level data memory usage
|
|
;; - actor heap memory usage
|
|
;; All basics have a mem-usage method that will add its memory usage to
|
|
;; a memory-usage-block. It also takes some flags that are currently unknown.
|
|
|
|
;; Information for a single category.
|
|
(deftype memory-usage-info (structure)
|
|
((name string)
|
|
(count int32)
|
|
(used int32)
|
|
(total int32)
|
|
)
|
|
)
|
|
|
|
;; Memory info for all categories
|
|
(deftype memory-usage-block (basic)
|
|
((work-bsp basic)
|
|
(length int32)
|
|
(data memory-usage-info 109 :inline)
|
|
)
|
|
(:methods
|
|
(reset! (_type_) _type_)
|
|
(calculate-total (_type_) int)
|
|
(print-mem-usage (_type_ level object) none)
|
|
)
|
|
)
|
|
|
|
|
|
;; The main RAM usage memory info
|
|
(define *mem-usage* (new 'debug 'memory-usage-block))
|
|
|
|
;; The DMA memory usage info
|
|
(define *dma-mem-usage* (new 'debug 'memory-usage-block))
|
|
|
|
;; Used internally for computing memory info
|
|
(define *temp-mem-usage* (the-as memory-usage-block #f))
|
|
|
|
;; TODO: flags.
|
|
;; bit 0 : count as a prototype definition.
|
|
;; bit 1 : count as an instance of a prototype.
|
|
;; bit 2 : count tie colors 1 (geom 1)
|
|
;; bit 3 : count tie colors 2 (geom 2)
|
|
;; bit 4 : ?? (geom 3)
|
|
|
|
;; Memory usage stats are organized by the type of object.
|
|
;; This enum allows you to go from type to the index in the memory-usage-block's data array.
|
|
(defenum mem-usage-id
|
|
:bitfield #f
|
|
:type uint32
|
|
(drawable-group 0)
|
|
(tfragment 1)
|
|
(tfragment-base 2)
|
|
(tfragment-common 3)
|
|
(tfragment-level0 4)
|
|
(tfragment-level1 5)
|
|
(tfragment-color 6)
|
|
(tfragment-debug 7)
|
|
(tfragment-pal 8)
|
|
(tie-fragment 9)
|
|
(tie-gif 10)
|
|
(tie-points 11)
|
|
(tie-colors 12)
|
|
(tie-draw-points 13)
|
|
(tie-debug 14)
|
|
(tie-near 15)
|
|
(tie-pal 16)
|
|
(tie-generic 17)
|
|
(instance-tie 18)
|
|
(instance-tie-colors0 19)
|
|
(instance-tie-colors1 20)
|
|
(instance-tie-colors2 21)
|
|
(instance-tie-colors3 22)
|
|
(instance-tie-colors* 23)
|
|
(prototype-bucket-shrub 24)
|
|
(generic-shrub 25)
|
|
(generic-shrub-data 26)
|
|
(shrubbery 27)
|
|
(shrubbery-object 28)
|
|
(shrubbery-vertex 29)
|
|
(shrubbery-color 30)
|
|
(shrubbery-stq 31)
|
|
(shrubbery-pal 32)
|
|
(billboard 33)
|
|
(instance-shrubbery 34)
|
|
(pris-fragment 35)
|
|
;; ??
|
|
(entity 43)
|
|
(camera 44)
|
|
(nav-mesh 45)
|
|
;; ??
|
|
(res 48)
|
|
(ambient 49)
|
|
(collide-fragment-0 50)
|
|
(collision-poly-0 51)
|
|
(collision-vertex-0 52)
|
|
(collide-fragment-1 53)
|
|
(collision-poly-1 54)
|
|
(collision-vertex-1 55)
|
|
(bsp-main 56)
|
|
(bsp-misc 57)
|
|
(bsp-node 58)
|
|
(bsp-leaf-vis-self 59)
|
|
(bsp-leaf-vis-adj 60)
|
|
(draw-node 61)
|
|
(pat 62)
|
|
(level-code 63)
|
|
(entity-links 64) ;; or ambient links, its messed up
|
|
(joint 65)
|
|
(joint-anim-compressed 66)
|
|
(joint-anim-compressed-control 67)
|
|
(joint-anim-fixed 68)
|
|
(joint-anim-frame 69)
|
|
(art-group 70)
|
|
(art-mesh-anim 71)
|
|
(art-mesh-geo 72)
|
|
(art-joint-geo 73)
|
|
(art-joint-anim 74)
|
|
(merc-ctrl 75)
|
|
(joint-anim-drawable 76)
|
|
(blend-shape 77)
|
|
(collide-mesh 78)
|
|
(texture 79)
|
|
(string 80)
|
|
(array 81)
|
|
(sprite 82)
|
|
(depth-cue 83)
|
|
(debug-dma 84) ;; maybe
|
|
(sky-dma 85) ;; maybe
|
|
(pris-generic)
|
|
(4k-dead-pool 87)
|
|
(8k-dead-pool 88)
|
|
(16k-dead-pool 89)
|
|
(nk-dead-pool 90)
|
|
(target-dead-pool 91)
|
|
(camera-dead-pool 92)
|
|
(debug-dead-pool 93)
|
|
(process-active 94)
|
|
(heap-total 95)
|
|
(heap-process 96)
|
|
(heap-header 97)
|
|
(heap-thread 98)
|
|
(heap-root 99)
|
|
(heap-draw-control 100)
|
|
(heap-joint-control 101)
|
|
(heap-cspace 102)
|
|
(heap-bone 103)
|
|
(heap-part 104)
|
|
(heap-collide-prim 105)
|
|
(heap-misc 106)
|
|
(shadow-geo 107)
|
|
(eye-anim 108)
|
|
)
|
|
|
|
;; get a memory usage id as an integer.
|
|
(defmacro mem-usage-id-int (kind)
|
|
`(the int (mem-usage-id ,kind))
|
|
)
|
|
|
|
(defun-extern mem-size basic symbol int int)
|