game: dont filter resolutions in windowed mode (#3688)

I'll test this more thoroughly tomorrow, quick change to allow picking
resolutions that would normally be filtered out, while in windowed mode.
This commit is contained in:
Tyler Wilding 2024-09-30 20:18:01 -04:00 committed by GitHub
parent 614c5a663c
commit 5b8bb8fe23
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 57 additions and 32 deletions

View file

@ -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) {
@ -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) {

View file

@ -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;

View file

@ -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};
@ -380,6 +389,8 @@ 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.
@ -387,10 +398,10 @@ void DisplayManager::update_resolutions() {
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);
}
@ -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());
}

View file

@ -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
@ -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();

View file

@ -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))

View file

@ -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))
@ -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

View file

@ -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))

View file

@ -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)

View file

@ -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))
@ -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)
@ -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)

View file

@ -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))