Skip to content

Commit

Permalink
Add dynamic Resolution menu logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Zedb0T committed Dec 10, 2024
1 parent c476b84 commit 04a3818
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
10 changes: 10 additions & 0 deletions game/kernel/common/kmachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,14 @@ void pc_get_resolution(u32 id, u32 for_windowed, u32 w_ptr, u32 h_ptr) {
}
}

u32 pc_get_current_height_resolution() {
return Gfx::g_global_settings.game_res_h;
}

u32 pc_get_current_width_resolution() {
return Gfx::g_global_settings.game_res_w;
}

u64 pc_is_supported_resolution(u64 width, u64 height) {
if (Display::GetMainDisplay()) {
return bool_to_symbol(
Expand Down Expand Up @@ -955,6 +963,8 @@ void init_common_pc_port_functions(
make_func_symbol_func("pc-set-window-size!", (void*)pc_set_window_size);
make_func_symbol_func("pc-get-num-resolutions", (void*)pc_get_num_resolutions);
make_func_symbol_func("pc-get-resolution", (void*)pc_get_resolution);
make_func_symbol_func("pc-get-resolution-h", (void*)pc_get_current_height_resolution);
make_func_symbol_func("pc-get-resolution-w", (void*)pc_get_current_width_resolution);
make_func_symbol_func("pc-is-supported-resolution?", (void*)pc_is_supported_resolution);

// -- INPUT RELATED --
Expand Down
4 changes: 4 additions & 0 deletions goal_src/jak1/kernel-defs.gc
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,10 @@

(define-extern pc-get-resolution (function int symbol (pointer int64) (pointer int64) none))

(define-extern pc-get-resolution-h (function int))

(define-extern pc-get-resolution-w (function int))

(define-extern pc-is-supported-resolution? (function int int symbol))

(define-extern pc-set-frame-rate (function int none))
Expand Down
40 changes: 31 additions & 9 deletions goal_src/jak1/pc/progress-pc.gc
Original file line number Diff line number Diff line change
Expand Up @@ -1163,15 +1163,37 @@
(1+! (-> *temp-options* length))))

(defmacro add-resolution-option (x y)
"add a resolution button to *temp-options* with specified size"
`(let ((option (-> *temp-options* (length *temp-options*))))
(set! (-> option option-type) (game-option-type resolution))
(set! (-> option option-disabled-func) #f)
(set! (-> option name) (text-id resolution-fmt))
(set! (-> option param1) (the float ,x))
(set! (-> option param2) (the float ,y))
(set! (-> option scale) #t)
(1+! (-> *temp-options* length))))
"Add a resolution button to *temp-options* with specified size.
Reserve the first index for the current resolution if it matches."
`(let ((current-width (pc-get-resolution-w))
(current-height (pc-get-resolution-h)))
;; First we check to see if we have a match, and if so insert it into index 0
(if (and (= current-width ,x) (= current-height ,y))
(let ((current-option (-> *temp-options* 0)))
(set! (-> current-option option-type) (game-option-type resolution))
(set! (-> current-option option-disabled-func) #f)
(set! (-> current-option name) (text-id resolution-fmt))
(set! (-> current-option param1) (the float ,x))
(set! (-> current-option param2) (the float ,y))
(set! (-> current-option scale) #t))
;;Here we are checking to see if we are at the start of *temp-options* and if so we skip index 0, as we are saving that for the resolution match
(if (= (length *temp-options*) 0)
(let ((option (-> *temp-options* 1)))
(set! (-> option option-type) (game-option-type resolution))
(set! (-> option option-disabled-func) #f)
(set! (-> option name) (text-id resolution-fmt))
(set! (-> option param1) (the float ,x))
(set! (-> option param2) (the float ,y))
(set! (-> option scale) #t)
(set! (-> *temp-options* length) (+ (-> *temp-options* length) 2)))
(let ((option (-> *temp-options* (length *temp-options*))))
(set! (-> option option-type) (game-option-type resolution))
(set! (-> option option-disabled-func) #f)
(set! (-> option name) (text-id resolution-fmt))
(set! (-> option param1) (the float ,x))
(set! (-> option param2) (the float ,y))
(set! (-> option scale) #t)
(1+! (-> *temp-options* length)))))))

(defun build-resolution-options ()
(set! (-> *temp-options* length) 0)
Expand Down

0 comments on commit 04a3818

Please sign in to comment.