Files
jak-project/goal_src/jak1/pc/debug/pc-debug-common.gc
Tyler Wilding c162c66118 g/j1: Cleanup all main issues in the formatter and format all of goal_src/jak1 (#3535)
This PR does two main things:
1. Work through the main low-hanging fruit issues in the formatter
keeping it from feeling mature and usable
2. Iterate and prove that point by formatting all of the Jak 1 code
base. **This has removed around 100K lines in total.**
- The decompiler will now format it's results for jak 1 to keep things
from drifting back to where they were. This is controlled by a new
config flag `format_code`.

How am I confident this hasn't broken anything?:
- I compiled the entire project and stored it's `out/jak1/obj` files
separately
- I then recompiled the project after formatting and wrote a script that
md5's each file and compares it (`compare-compilation-outputs.py`
- The results (eventually) were the same:

![Screenshot 2024-05-25
132900](https://github.com/open-goal/jak-project/assets/13153231/015e6f20-8d19-49b7-9951-97fa88ddc6c2)
> This proves that the only difference before and after is non-critical
whitespace for all code/macros that is actually in use.

I'm still aware of improvements that could be made to the formatter, as
well as general optimization of it's performance. But in general these
are for rare or non-critical situations in my opinion and I'll work
through them before doing Jak 2. The vast majority looks great and is
working properly at this point. Those known issues are the following if
you are curious:

![image](https://github.com/open-goal/jak-project/assets/13153231/0edfaba1-6d36-40f5-ab23-0642209867c4)
2024-06-05 22:17:31 -04:00

83 lines
3.5 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
(require "kernel/gstring.gc")
(require "engine/math/math.gc")
#| Various debugging displays made for the pc port. This file is shared for all games. |#
;; debug-only file!
(declare-file (debug))
;; ----------------------
;; memory usage bars!
;; ----------------------
(defconstant MEM_BAR_WIDTH 104) ;; total width of the bar
(defconstant MEM_BAR_HEIGHT 8) ;; total height of the bar
(defconstant MEM_BAR_HORZ_PAD 8) ;; horizontal padding for the bar text
(defconstant MEM_BAR_NUM 7) ;; amount of bars (override later if wanted)
(defconstant MEM_BAR_BG_COL (static-rgba 64 64 64 64)) ;; color for the empty part of the bar
(defconstant MEM_BAR_RIGHT 480) ;; x coord for the right side of the bar list
(defconstant MEM_BAR_BOTTOM 224) ;; x coord for the bottom side of the bar list
(defconstant MEM_BAR_Y (- MEM_BAR_BOTTOM 4 (* MEM_BAR_HEIGHT MEM_BAR_NUM))) ;; y coord for top side of the bar list
(defmacro draw-memory-bar-generic (buf &key remain &key total &key name &key idx &key color)
"draw a memory usage bar"
`(let* ((total (the float ,total))
(remain (the float ,remain))
(bar-width (the int (/ (the float MEM_BAR_WIDTH) (-> *pc-settings* aspect-ratio-scale))))
(bar-x (- MEM_BAR_RIGHT bar-width MEM_BAR_HORZ_PAD)) ;; x coord for left side of the bar list
(used-p (if (zero? total) 0.0 (/ (- total remain) total)))
(used-x (the int (* used-p bar-width)))
(used-y (+ MEM_BAR_Y (* ,idx MEM_BAR_HEIGHT))))
(draw-sprite2d-xy ,buf bar-x used-y used-x MEM_BAR_HEIGHT ,color)
(draw-sprite2d-xy ,buf (+ bar-x used-x) used-y (- bar-width used-x) MEM_BAR_HEIGHT MEM_BAR_BG_COL)
(if (zero? total) (set! used-x (the int (* 0.5 bar-width))))
(draw-string-xy ,name ,buf (- bar-x MEM_BAR_HORZ_PAD) used-y (font-color red) (font-flags shadow kerning right))
(draw-string-xy (if (zero? total) "NO HEAP" (string-format "~,,2f%" (* used-p 100)))
,buf
(+ bar-x used-x)
used-y
(font-color default)
(font-flags shadow kerning middle))
(draw-string-xy (string-format "~,,1fM" (/ total (* 1024 1024)))
,buf
(+ bar-x bar-width MEM_BAR_HORZ_PAD)
used-y
(font-color red)
(font-flags shadow kerning middle-vert))))
(defmacro draw-memory-bar-kheap (buf heap &key (name #f) &key idx &key color)
"draw a memory usage bar for a kheap"
`(let ((heap ,heap))
(draw-memory-bar-generic ,buf
:remain
(&- (-> heap top) (-> heap current))
:total
(&- (-> heap top-base) (-> heap base))
:name
,(if name name (symbol->string heap))
:idx ,idx
:color ,color)))
(defmacro draw-memory-bar-dead-pool-heap (buf heap &key (name #f) &key idx &key color)
"draw a memory usage bar for a dead-pool-heap (actor heap)"
`(let* ((heap ,heap)
(pool-total (memory-total heap)))
(draw-memory-bar-generic ,buf
:remain
(- pool-total (memory-used heap))
:total
pool-total
:name
,(if name name (symbol->string heap))
:idx ,idx
:color ,color)))