Skip to content

Commit

Permalink
game: dont filter resolutions in windowed mode (#3688)
Browse files Browse the repository at this point in the history
I'll test this more thoroughly tomorrow, quick change to allow picking
resolutions that would normally be filtered out, while in windowed mode.
  • Loading branch information
xTVaser authored Oct 1, 2024
1 parent 614c5a6 commit 5b8bb8f
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 32 deletions.
8 changes: 4 additions & 4 deletions game/graphics/opengl_renderer/loader/LoaderStages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ class TieLoadStage : public LoaderStage {
if (m_next_tree >= data.lev_data->level->tie_trees[m_next_geo].size()) {
m_next_tree = 0;
m_next_geo++;
while (data.lev_data->level->tie_trees[m_next_geo].empty() &&
m_next_geo < tfrag3::TIE_GEOS) {
while (m_next_geo < tfrag3::TIE_GEOS &&
data.lev_data->level->tie_trees[m_next_geo].empty()) {
m_next_geo++;
}
if (m_next_geo >= tfrag3::TIE_GEOS) {
Expand Down Expand Up @@ -452,8 +452,8 @@ class TieLoadStage : public LoaderStage {
if (m_next_tree >= data.lev_data->level->tie_trees[m_next_geo].size()) {
m_next_tree = 0;
m_next_geo++;
while (data.lev_data->level->tie_trees[m_next_geo].empty() &&
m_next_geo < tfrag3::TIE_GEOS) {
while (m_next_geo < tfrag3::TIE_GEOS &&
data.lev_data->level->tie_trees[m_next_geo].empty()) {
m_next_geo++;
}
if (m_next_geo >= tfrag3::TIE_GEOS) {
Expand Down
10 changes: 6 additions & 4 deletions game/kernel/common/kmachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,16 +586,18 @@ void pc_set_window_size(u64 width, u64 height) {
}
}

s64 pc_get_num_resolutions() {
s64 pc_get_num_resolutions(u32 for_windowed) {
if (Display::GetMainDisplay()) {
return Display::GetMainDisplay()->get_display_manager()->get_num_resolutions();
return Display::GetMainDisplay()->get_display_manager()->get_num_resolutions(
symbol_to_bool(for_windowed));
}
return 0;
}

void pc_get_resolution(u32 id, u32 w_ptr, u32 h_ptr) {
void pc_get_resolution(u32 id, u32 for_windowed, u32 w_ptr, u32 h_ptr) {
if (Display::GetMainDisplay()) {
auto res = Display::GetMainDisplay()->get_display_manager()->get_resolution(id);
auto res = Display::GetMainDisplay()->get_display_manager()->get_resolution(
id, symbol_to_bool(for_windowed));
auto w = Ptr<s64>(w_ptr).c();
if (w) {
*w = res.width;
Expand Down
40 changes: 31 additions & 9 deletions game/system/hid/display_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,17 @@ int DisplayManager::get_screen_height() {
return 480;
}

Resolution DisplayManager::get_resolution(int id) {
if (id < (int)m_available_resolutions.size()) {
int DisplayManager::get_num_resolutions(bool for_window_size) {
if (for_window_size) {
return m_available_window_sizes.size();
}
return m_available_resolutions.size();
}

Resolution DisplayManager::get_resolution(int id, bool for_window_size) {
if (for_window_size && id < (int)m_available_window_sizes.size()) {
return m_available_window_sizes.at(id);
} else if (id < (int)m_available_resolutions.size()) {
return m_available_resolutions.at(id);
}
return {0, 0, 0.0};
Expand Down Expand Up @@ -380,17 +389,19 @@ void DisplayManager::update_resolutions() {
fmt::format("unable to get display mode for display {}, index {}", active_display_id, i));
continue;
}
Resolution new_res = {curr_mode.w, curr_mode.h,
static_cast<float>(curr_mode.w) / static_cast<float>(curr_mode.h)};
// Skip resolutions that aren't using the current refresh rate, they won't work.
// For example if your monitor is currently set to `60hz` and the monitor _could_ support
// resolution X but only at `30hz`...then there's no reason for us to consider it as an option.
if (curr_mode.refresh_rate != active_refresh_rate) {
lg::debug(
"[DISPLAY]: Skipping {}x{} as it requires {}hz but the monitor is currently set to {}hz",
curr_mode.w, curr_mode.h, curr_mode.refresh_rate, active_refresh_rate);
// Allow it for windowed mode though
m_available_window_sizes.push_back(new_res);
continue;
}
Resolution new_res = {curr_mode.w, curr_mode.h,
static_cast<float>(curr_mode.w) / static_cast<float>(curr_mode.h)};
lg::info("[DISPLAY]: {}x{} is supported", new_res.width, new_res.height);
m_available_resolutions.push_back(new_res);
}
Expand All @@ -400,11 +411,22 @@ void DisplayManager::update_resolutions() {
[](const Resolution& a, const Resolution& b) -> bool {
return a.width * a.height > b.width * b.height;
});
std::sort(m_available_resolutions.begin(), m_available_resolutions.end(),
[](const Resolution& a, const Resolution& b) -> bool {
return a.width * a.height > b.width * b.height;
});

// Remove duplicate resolutions
auto last = std::unique(m_available_resolutions.begin(), m_available_resolutions.end(),
[](const Resolution& a, const Resolution& b) -> bool {
return (a.width == b.width && a.height == b.height);
});
m_available_resolutions.erase(last, m_available_resolutions.end());
m_available_resolutions.erase(
std::unique(m_available_resolutions.begin(), m_available_resolutions.end(),
[](const Resolution& a, const Resolution& b) -> bool {
return (a.width == b.width && a.height == b.height);
}),
m_available_resolutions.end());
m_available_window_sizes.erase(
std::unique(m_available_window_sizes.begin(), m_available_window_sizes.end(),
[](const Resolution& a, const Resolution& b) -> bool {
return (a.width == b.width && a.height == b.height);
}),
m_available_window_sizes.end());
}
5 changes: 3 additions & 2 deletions game/system/hid/display_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ class DisplayManager {
game_settings::DisplaySettings::DisplayMode get_display_mode() {
return m_display_settings.display_mode;
}
int get_num_resolutions() { return m_available_resolutions.size(); }
Resolution get_resolution(int id);
int get_num_resolutions(bool for_window_size);
Resolution get_resolution(int id, bool for_window_size);
bool is_supported_resolution(int width, int height);

// Mutators
Expand Down Expand Up @@ -123,6 +123,7 @@ class DisplayManager {
// ie. allowing someone to set 150fps on a monitor set to 60hz is not correct
std::unordered_map<int, DisplayMode> m_current_display_modes;
std::vector<Resolution> m_available_resolutions;
std::vector<Resolution> m_available_window_sizes;

void initialize_window_position_from_settings();
void update_curr_display_info();
Expand Down
4 changes: 2 additions & 2 deletions goal_src/jak1/kernel-defs.gc
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,9 @@

(define-extern pc-set-display-mode! (function symbol none))

(define-extern pc-get-num-resolutions (function int))
(define-extern pc-get-num-resolutions (function symbol int))

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

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

Expand Down
4 changes: 2 additions & 2 deletions goal_src/jak1/pc/progress-pc.gc
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@
(let ((window-width 0)
(window-height 0)
(window-aspect-ratio 0.0)
(num-resolutions (pc-get-num-resolutions))
(num-resolutions (pc-get-num-resolutions (= (pc-get-display-mode) 'windowed)))
(num-resolutions-added 0))
(when (> num-resolutions 0)
(pc-get-window-size (& window-width) (& window-height))
Expand All @@ -1188,7 +1188,7 @@
(let ((res-width 0)
(res-height 0)
(res-aspect-ratio 0.0))
(pc-get-resolution i (& res-width) (& res-height))
(pc-get-resolution i (= (pc-get-display-mode) 'windowed) (& res-width) (& res-height))
(set! res-aspect-ratio (/ (the float res-width) (the float res-height)))
;; Ignore those that aren't relevant to the current window's aspect ratio
;; we only do this when we aren't in windowed mode, because in windowed mode
Expand Down
4 changes: 2 additions & 2 deletions goal_src/jak2/kernel-defs.gc
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@
(define-extern pc-get-display-id (function int))
(define-extern pc-set-display-id! (function int none))
(define-extern pc-set-display-mode! (function symbol none))
(define-extern pc-get-num-resolutions (function int))
(define-extern pc-get-resolution (function int (pointer int64) (pointer int64) none))
(define-extern pc-get-num-resolutions (function symbol int))
(define-extern pc-get-resolution (function int symbol (pointer int64) (pointer int64) none))
(define-extern pc-is-supported-resolution? (function int int symbol))

(define-extern pc-set-frame-rate (function int none))
Expand Down
2 changes: 1 addition & 1 deletion goal_src/jak2/pc/progress/progress-draw-pc.gc
Original file line number Diff line number Diff line change
Expand Up @@ -3198,7 +3198,7 @@

;; count "valid" resolutions
(let ((this-w 0) (this-h 0) (this-aspect 0.0))
(pc-get-resolution i (& this-w) (& this-h))
(pc-get-resolution i (= (pc-get-display-mode) 'windowed) (& this-w) (& this-h))
(set! this-aspect (/ (the float this-w) (the float this-h)))

(when (or (= (pc-get-display-mode) 'windowed)
Expand Down
8 changes: 4 additions & 4 deletions goal_src/jak2/pc/progress/progress-pc.gc
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,8 @@
(res-h 0)
(res-aspect 0.0)
(res-valid 0))
(dotimes (i (pc-get-num-resolutions))
(pc-get-resolution i (& res-w) (& res-h))
(dotimes (i (pc-get-num-resolutions (= (pc-get-display-mode) 'windowed)))
(pc-get-resolution i (= (pc-get-display-mode) 'windowed) (& res-w) (& res-h))
(set! res-aspect (/ (the float res-w) (the float res-h)))
(when (or (= (pc-get-display-mode) 'windowed)
(< (fabs (- want-aspect res-aspect)) 0.05))
Expand Down Expand Up @@ -716,7 +716,7 @@
(select-h -1)
)

(set! (-> this num-resolutions) (pc-get-num-resolutions))
(set! (-> this num-resolutions) (pc-get-num-resolutions (= (pc-get-display-mode) 'windowed)))
(cond
;; valid state
((> (-> this num-resolutions) 0)
Expand Down Expand Up @@ -770,7 +770,7 @@

;; count "valid" resolutions
(let ((this-w 0) (this-h 0) (this-aspect 0.0))
(pc-get-resolution i (& this-w) (& this-h))
(pc-get-resolution i (= (pc-get-display-mode) 'windowed) (& this-w) (& this-h))
(set! this-aspect (/ (the float this-w) (the float this-h)))

(when (or (= (pc-get-display-mode) 'windowed)
Expand Down
4 changes: 2 additions & 2 deletions goal_src/jak3/kernel-defs.gc
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@
(define-extern pc-get-display-id (function int))
(define-extern pc-set-display-id! (function int none))
(define-extern pc-set-display-mode! (function symbol none))
(define-extern pc-get-num-resolutions (function int))
(define-extern pc-get-resolution (function int (pointer int64) (pointer int64) none))
(define-extern pc-get-num-resolutions (function symbol int))
(define-extern pc-get-resolution (function int symbol (pointer int64) (pointer int64) none))
(define-extern pc-is-supported-resolution? (function int int symbol))

(define-extern pc-set-frame-rate (function int none))
Expand Down

0 comments on commit 5b8bb8f

Please sign in to comment.