From ad9a532ff97144c714b02ab53e650b66a7662a28 Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Sat, 25 Feb 2023 19:27:58 +0000 Subject: [PATCH] [jak2] text aspect ratio fixes (#2251) Fixes the aspect ratio of the font renderer (Jak 2 does not need the same hacks as Jak 1), the custom letterbox/pillarbox sizes and fixes the heap display. --------- Co-authored-by: water --- game/graphics/opengl_renderer/OpenGLRenderer.cpp | 2 +- goal_src/goal-lib.gc | 13 ++++++++++--- goal_src/jak1/pc/debug/pc-debug-common.gc | 11 +++++++---- goal_src/jak1/pc/pckernel-common.gc | 7 +------ goal_src/jak1/pc/pckernel-h.gc | 2 +- goal_src/jak1/pc/pckernel.gc | 10 +++++++--- goal_src/jak2/engine/game/main.gc | 10 ++++++---- goal_src/jak2/pc/debug/pc-debug-methods.gc | 4 +++- goal_src/jak2/pc/pckernel.gc | 9 +++++---- 9 files changed, 41 insertions(+), 27 deletions(-) diff --git a/game/graphics/opengl_renderer/OpenGLRenderer.cpp b/game/graphics/opengl_renderer/OpenGLRenderer.cpp index 1bbbd9a4c..a860f7e38 100644 --- a/game/graphics/opengl_renderer/OpenGLRenderer.cpp +++ b/game/graphics/opengl_renderer/OpenGLRenderer.cpp @@ -313,7 +313,7 @@ void OpenGLRenderer::init_bucket_renderers_jak2() { init_bucket_renderer("progress", BucketCategory::OTHER, BucketId::PROGRESS, 0x8000); init_bucket_renderer("screen-filter", BucketCategory::OTHER, - BucketId::SCREEN_FILTER, 0x8000); + BucketId::SCREEN_FILTER, 256); init_bucket_renderer("bucket-322", BucketCategory::OTHER, BucketId::BUCKET_322, 0x8000); init_bucket_renderer("debug2", BucketCategory::OTHER, BucketId::DEBUG2, 0x8000); diff --git a/goal_src/goal-lib.gc b/goal_src/goal-lib.gc index ba9fb698a..0bfa91063 100644 --- a/goal_src/goal-lib.gc +++ b/goal_src/goal-lib.gc @@ -284,15 +284,22 @@ ) ) +(defmacro define-once (name value) + "define once. Does not set the symbol if it already has a value. It must have been at least forward-declared first!" + `(begin + (if (or (not ,name) (zero? ,name)) + (set! ,name ,value) + ) + ) + ) + (defmacro define-perm (name type value) "Define 'permanent', meaning the original definition will not be blown away by a file reload. If the value of the symbol is unset (zero) or set to false, it will be defined. Otherwise, no effect, other than to inform the type system of the symbol type." `(begin (define-extern ,name ,type) - (if (or (not ,name) (zero? ,name)) - (set! ,name ,value) - ) + (define-once ,name ,value) ) ) diff --git a/goal_src/jak1/pc/debug/pc-debug-common.gc b/goal_src/jak1/pc/debug/pc-debug-common.gc index 14bef0f6a..b7a1fa2f4 100644 --- a/goal_src/jak1/pc/debug/pc-debug-common.gc +++ b/goal_src/jak1/pc/debug/pc-debug-common.gc @@ -16,22 +16,25 @@ (defconstant MEM_BAR_HEIGHT 8) ;; total height of the bar (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_X (- 480 MEM_BAR_WIDTH)) ;; x coord for left side of the bar list -(defconstant MEM_BAR_Y (- 224 4 (* MEM_BAR_HEIGHT MEM_BAR_NUM))) ;; y coord for top side of the bar list +(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_X (- MEM_BAR_RIGHT MEM_BAR_WIDTH)) ;; x coord for left 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)) - (used-p (/ (- total remain) total)) + (used-p (if (zero? total) 0.0 (/ (- total remain) total))) (used-x (the int (* used-p MEM_BAR_WIDTH))) (used-y (+ MEM_BAR_Y (* ,idx MEM_BAR_HEIGHT))) ) (draw-sprite2d-xy ,buf MEM_BAR_X used-y used-x MEM_BAR_HEIGHT ,color) (draw-sprite2d-xy ,buf (+ MEM_BAR_X used-x) used-y (- MEM_BAR_WIDTH used-x) MEM_BAR_HEIGHT MEM_BAR_BG_COL) (draw-string-xy ,name ,buf MEM_BAR_X used-y (font-color red) (font-flags shadow kerning right)) - (draw-string-xy (string-format "~,,2f%" (* used-p 100)) ,buf (+ MEM_BAR_X used-x) used-y (font-color red) (font-flags shadow kerning middle)) + (draw-string-xy (string-format "~,,2f%" (* used-p 100)) ,buf (+ MEM_BAR_X used-x) used-y (font-color default) (font-flags shadow kerning middle)) (draw-string-xy (string-format "~,,1fM" (/ total (* 1024 1024))) ,buf (+ MEM_BAR_X MEM_BAR_WIDTH) used-y (font-color red) (font-flags shadow kerning left)) ) ) diff --git a/goal_src/jak1/pc/pckernel-common.gc b/goal_src/jak1/pc/pckernel-common.gc index 751df8ad3..37ccb7ca8 100644 --- a/goal_src/jak1/pc/pckernel-common.gc +++ b/goal_src/jak1/pc/pckernel-common.gc @@ -279,12 +279,7 @@ (update-speedrun obj)) (when (not (-> obj use-vis?)) - (set! (-> (get-video-params) relative-x-scale) (-> obj aspect-ratio-reciprocal)) - (set! (-> (get-video-params) relative-x-scale-reciprical) (-> obj aspect-ratio-scale)) - (set! (-> *font-default-matrix* vector 0 x) (-> (get-video-params) relative-x-scale)) - ) - (when (not (-> obj use-vis?)) - (update-progress-video-hacks obj) + (update-video-hacks obj) ) (cond ((-> obj force-actors?) diff --git a/goal_src/jak1/pc/pckernel-h.gc b/goal_src/jak1/pc/pckernel-h.gc index 1c624be66..2dae9294e 100644 --- a/goal_src/jak1/pc/pckernel-h.gc +++ b/goal_src/jak1/pc/pckernel-h.gc @@ -330,7 +330,7 @@ (update-to-os (_type_) none) (update-discord-rpc (_type_) object) (update-speedrun (_type_) object) - (update-progress-video-hacks (_type_) object) + (update-video-hacks (_type_) object) (reset (_type_) none) (reset-audio (_type_) none) (reset-input (_type_) none) diff --git a/goal_src/jak1/pc/pckernel.gc b/goal_src/jak1/pc/pckernel.gc index 11b49548d..e09105870 100644 --- a/goal_src/jak1/pc/pckernel.gc +++ b/goal_src/jak1/pc/pckernel.gc @@ -299,8 +299,12 @@ (speedrun-mode-update)) 0) -(defmethod update-progress-video-hacks pc-settings-jak1 ((obj pc-settings-jak1)) - "update the graphics hacks used for the progress menu. ugh." +(defmethod update-video-hacks pc-settings-jak1 ((obj pc-settings-jak1)) + "update the graphics hacks used for sprites and other things. ugh." + + (set! (-> (get-video-params) relative-x-scale) (-> obj aspect-ratio-reciprocal)) + (set! (-> (get-video-params) relative-x-scale-reciprical) (-> obj aspect-ratio-scale)) + (set! (-> *font-default-matrix* vector 0 x) (-> (get-video-params) relative-x-scale)) (set-hud-aspect-ratio 'aspect4x3 'ntsc) ;; set hud aspect ratios every frame because why not? @@ -356,7 +360,7 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(define *pc-settings* (new 'global 'pc-settings-jak1)) +(define-once *pc-settings* (new 'global 'pc-settings-jak1)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/goal_src/jak2/engine/game/main.gc b/goal_src/jak2/engine/game/main.gc index f4860f178..d014423f2 100644 --- a/goal_src/jak2/engine/game/main.gc +++ b/goal_src/jak2/engine/game/main.gc @@ -41,16 +41,18 @@ (cond ((< (-> *pc-settings* aspect-ratio) ASPECT_16X9) ;; too tall. needs vertical letterboxing. - (let ((lbx-h (the int (* 112.0 (- 1.0 (/ (-> *pc-settings* aspect-ratio) ASPECT_16X9)))))) + (let ((lbx-h (the int (* 208.0 (- 1.0 (/ (-> *pc-settings* aspect-ratio) ASPECT_16X9)))))) + ;(format 0 "using new letterbox! size: ~D~%" lbx-h) (draw-sprite2d-xy dma-buf 0 0 512 lbx-h (new 'static 'rgba :a #x80)) - (draw-sprite2d-xy dma-buf 0 (- 448 lbx-h) 512 lbx-h (new 'static 'rgba :a #x80)) + (draw-sprite2d-xy dma-buf 0 (- 416 lbx-h) 512 lbx-h (new 'static 'rgba :a #x80)) ) ) ((> (-> *pc-settings* aspect-ratio) ASPECT_16X9) ;; too wide. needs horizontal letterboxing. (let ((lbx-w (the int (* 256.0 (- 1.0 (/ ASPECT_16X9 (-> *pc-settings* aspect-ratio))))))) - (draw-sprite2d-xy dma-buf 0 0 lbx-w 448 (new 'static 'rgba :a #x80)) - (draw-sprite2d-xy dma-buf (- 512 lbx-w) 0 lbx-w 448 (new 'static 'rgba :a #x80)) + ;(format 0 "using new pillarbox! size: ~D~%" lbx-w) + (draw-sprite2d-xy dma-buf 0 0 lbx-w 416 (new 'static 'rgba :a #x80)) + (draw-sprite2d-xy dma-buf (- 512 lbx-w) 0 lbx-w 416 (new 'static 'rgba :a #x80)) ) ) ) diff --git a/goal_src/jak2/pc/debug/pc-debug-methods.gc b/goal_src/jak2/pc/debug/pc-debug-methods.gc index 2c7b7da3a..e75ea9472 100644 --- a/goal_src/jak2/pc/debug/pc-debug-methods.gc +++ b/goal_src/jak2/pc/debug/pc-debug-methods.gc @@ -15,6 +15,8 @@ #f) ) +(defconstant MEM_BAR_HEIGHT 14) ;; total height of the bar +(defconstant MEM_BAR_BOTTOM 416) ;; x coord for the bottom side of the bar list (defconstant MEM_BAR_NUM 11) ;; amount of memory usage bars (override later if wanted) (defmethod draw-memory pc-settings-jak2 ((obj pc-settings-jak2) (buf dma-buffer)) "draw the memory heap status in the bottom right corner" @@ -31,7 +33,7 @@ (draw-memory-bar-kheap buf global :idx idx :color (static-rgba 32 32 255 64)) (draw-memory-bar-kheap buf debug :idx (1+! idx) :color (static-rgba 255 32 32 64)) (dotimes (i (-> *level* length)) - (if (!= (-> *level* level i status) 'inactive) (draw-memory-bar-kheap buf (-> *level* level i heap) :name (string-format "l~D" i) :idx (1+! idx) :color (-> level-heap-colors i))) + (draw-memory-bar-kheap buf (-> *level* level i heap) :name (string-format "l~D" i) :idx (1+! idx) :color (-> level-heap-colors i)) ) (draw-memory-bar-dead-pool-heap buf *nk-dead-pool* :name "actor" :idx (1+! idx) :color (static-rgba 32 255 32 64)) (draw-memory-bar-generic buf diff --git a/goal_src/jak2/pc/pckernel.gc b/goal_src/jak2/pc/pckernel.gc index 9100c9039..91de4e0b8 100644 --- a/goal_src/jak2/pc/pckernel.gc +++ b/goal_src/jak2/pc/pckernel.gc @@ -48,7 +48,7 @@ ) (defmethod get-game-language! pc-settings-jak2 ((obj pc-settings-jak2)) - (-> *setting-control* user-default language) + (get-current-language) ) (defmethod update-discord-rpc pc-settings-jak2 ((obj pc-settings-jak2)) @@ -78,10 +78,11 @@ #f ) -(defmethod update-progress-video-hacks pc-settings-jak2 ((obj pc-settings-jak2)) +(defmethod update-video-hacks pc-settings-jak2 ((obj pc-settings-jak2)) "update the graphics hacks used for the progress menu. ugh." - #f + (set! (-> (get-video-params) relative-x-scale) (-> obj aspect-ratio-reciprocal)) + (set! (-> (get-video-params) relative-x-scale-reciprical) (-> obj aspect-ratio-scale)) ) @@ -111,7 +112,7 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(define *pc-settings* (new 'global 'pc-settings-jak2)) +(define-once *pc-settings* (new 'global 'pc-settings-jak2)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;