From 46db6a36dace2a38cf6c72c3422bc37c9044e15a Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Mon, 15 Jan 2024 18:53:49 +0000 Subject: [PATCH] [pckernel] use `pc-get-resolution` to fetch initial fullscreen resolution (#3307) This is the more correct way of doing what that code is trying to do. Fixes #3296 Also fixed some type inconsistencies with related code, probably wasn't causing issues though. May also fix the "black screen on startup" issues people keep having, but that would simply be a nice bonus and isn't the aim of this PR. --- game/kernel/common/kmachine.cpp | 12 ++++----- goal_src/jak1/kernel-defs.gc | 4 +-- goal_src/jak1/pc/pckernel-h.gc | 31 +++++++++++++++------- goal_src/jak1/pc/progress-pc.gc | 2 +- goal_src/jak2/kernel-defs.gc | 4 +-- goal_src/jak2/pc/progress/progress-h-pc.gc | 4 +-- 6 files changed, 35 insertions(+), 22 deletions(-) diff --git a/game/kernel/common/kmachine.cpp b/game/kernel/common/kmachine.cpp index 4875e8bf71..e2fa629d3d 100644 --- a/game/kernel/common/kmachine.cpp +++ b/game/kernel/common/kmachine.cpp @@ -512,13 +512,13 @@ void pc_get_active_display_size(u32 w_ptr, u32 h_ptr) { return; } if (w_ptr) { - auto w_out = Ptr(w_ptr).c(); + auto w_out = Ptr(w_ptr).c(); if (w_out) { *w_out = Display::GetMainDisplay()->get_display_manager()->get_screen_width(); } } if (h_ptr) { - auto h_out = Ptr(h_ptr).c(); + auto h_out = Ptr(h_ptr).c(); if (h_out) { *h_out = Display::GetMainDisplay()->get_display_manager()->get_screen_height(); } @@ -537,13 +537,13 @@ void pc_get_window_size(u32 w_ptr, u32 h_ptr) { return; } if (w_ptr) { - auto w = Ptr(w_ptr).c(); + auto w = Ptr(w_ptr).c(); if (w) { *w = Display::GetMainDisplay()->get_display_manager()->get_window_width(); } } if (h_ptr) { - auto h = Ptr(h_ptr).c(); + auto h = Ptr(h_ptr).c(); if (h) { *h = Display::GetMainDisplay()->get_display_manager()->get_window_height(); } @@ -590,11 +590,11 @@ s64 pc_get_num_resolutions() { void pc_get_resolution(u32 id, u32 w_ptr, u32 h_ptr) { if (Display::GetMainDisplay()) { auto res = Display::GetMainDisplay()->get_display_manager()->get_resolution(id); - auto w = Ptr(w_ptr).c(); + auto w = Ptr(w_ptr).c(); if (w) { *w = res.width; } - auto h = Ptr(h_ptr).c(); + auto h = Ptr(h_ptr).c(); if (h) { *h = res.height; } diff --git a/goal_src/jak1/kernel-defs.gc b/goal_src/jak1/kernel-defs.gc index 7d5350b57d..e8ae838d62 100644 --- a/goal_src/jak1/kernel-defs.gc +++ b/goal_src/jak1/kernel-defs.gc @@ -358,12 +358,12 @@ ;; Display Related Functions (define-extern pc-get-display-mode (function symbol)) -(define-extern pc-get-active-display-size (function (pointer int32) (pointer int32) none)) +(define-extern pc-get-active-display-size (function (pointer int64) (pointer int64) none)) (define-extern pc-get-active-display-refresh-rate (function int)) (define-extern pc-get-display-count (function int)) (define-extern pc-get-display-name (function int string symbol)) (define-extern pc-get-os (function symbol)) -(define-extern pc-get-window-size (function (pointer int32) (pointer int32) none)) +(define-extern pc-get-window-size (function (pointer int64) (pointer int64) none)) (define-extern pc-get-window-scale (function (pointer float) (pointer float) none)) (define-extern pc-set-window-size (function int int none)) (define-extern pc-set-fullscreen-display (function int none)) diff --git a/goal_src/jak1/pc/pckernel-h.gc b/goal_src/jak1/pc/pckernel-h.gc index a1b8f67ebd..169d5716f9 100644 --- a/goal_src/jak1/pc/pckernel-h.gc +++ b/goal_src/jak1/pc/pckernel-h.gc @@ -110,17 +110,17 @@ ;; "generic" graphics settings (target-fps int16) ;; the target framerate of the game ;; game resolution? - (width int32) - (height int32) + (width int64) + (height int64) ;; window size. resolution = window size in windowed mode. - (window-width int32) - (window-height int32) + (window-width int64) + (window-height int64) ;; reported window framebuffer size from OS - (framebuffer-width int32) - (framebuffer-height int32) + (framebuffer-width int64) + (framebuffer-height int64) ;; the region to draw in that framebuffer. rest is cleared to black. - (framebuffer-scissor-width int32) - (framebuffer-scissor-height int32) + (framebuffer-scissor-width int64) + (framebuffer-scissor-height int64) (dpi-x float) ;; DPI width scale (dpi-y float) ;; DPI height scale (aspect-ratio-auto? symbol) ;; if on, aspect ratio is calculated automatically based on game display size. @@ -344,7 +344,20 @@ (set! (-> obj letterbox?) #t) ;; get screen size and set to borderless at screen res (if retail) - (pc-get-active-display-size (&-> obj width) (&-> obj height)) + (cond + ((> (pc-get-num-resolutions) 0) + ;; pick first available resolution by default + (pc-get-resolution 0 (&-> obj width) (&-> obj height)) + ) + (else + ;; somehow didn't get a single resolution. this is pretty bad. + (pc-get-active-display-size (&-> obj width) (&-> obj height)) + (max! (-> obj width) PC_MIN_WIDTH) + (max! (-> obj height) PC_MIN_HEIGHT) + (format 0 "!!!! failed to get any screen resolutions !!!!") + ) + ) + (format 0 "fullscreen resolution defaulted to ~D x ~D~%" (-> obj width) (-> obj height)) (if (not *debug-segment*) (set-display-mode! obj 'borderless call-handlers) (set-display-mode! obj 'windowed call-handlers)) diff --git a/goal_src/jak1/pc/progress-pc.gc b/goal_src/jak1/pc/progress-pc.gc index ee4d0ddad2..ed47d8ff7c 100644 --- a/goal_src/jak1/pc/progress-pc.gc +++ b/goal_src/jak1/pc/progress-pc.gc @@ -578,7 +578,7 @@ (num-resolutions (pc-get-num-resolutions)) (num-resolutions-added 0)) (when (> num-resolutions 0) - (pc-get-window-size (the-as (pointer int32) (& window-width)) (the-as (pointer int32) (& window-height))) + (pc-get-window-size (& window-width) (& window-height)) (set! window-aspect-ratio (/ (the float window-width) (the float window-height))) (dotimes (i num-resolutions) (let ((res-width 0) diff --git a/goal_src/jak2/kernel-defs.gc b/goal_src/jak2/kernel-defs.gc index b03db70a85..5e947a8213 100644 --- a/goal_src/jak2/kernel-defs.gc +++ b/goal_src/jak2/kernel-defs.gc @@ -195,12 +195,12 @@ ;; Display Related Functions (define-extern pc-get-display-mode (function symbol)) -(define-extern pc-get-active-display-size (function (pointer int32) (pointer int32) none)) +(define-extern pc-get-active-display-size (function (pointer int64) (pointer int64) none)) (define-extern pc-get-active-display-refresh-rate (function int)) (define-extern pc-get-display-count (function int)) (define-extern pc-get-display-name (function int string symbol)) (define-extern pc-get-os (function symbol)) -(define-extern pc-get-window-size (function (pointer int32) (pointer int32) none)) +(define-extern pc-get-window-size (function (pointer int64) (pointer int64) none)) (define-extern pc-get-window-scale (function (pointer float) (pointer float) none)) (define-extern pc-set-window-size (function int int none)) (define-extern pc-set-fullscreen-display (function int none)) diff --git a/goal_src/jak2/pc/progress/progress-h-pc.gc b/goal_src/jak2/pc/progress/progress-h-pc.gc index a00bc0af3a..0652c959c2 100644 --- a/goal_src/jak2/pc/progress/progress-h-pc.gc +++ b/goal_src/jak2/pc/progress/progress-h-pc.gc @@ -35,8 +35,8 @@ ;; OS state kept for drawing later, avoids desync and duplicate fetching (num-resolutions int) (win-aspect float) - (win-w int32) - (win-h int32) + (win-w int64) + (win-h int64) ) )