77#include < AdvancedResolution.h>
88
99namespace AdvancedResolutionSettings {
10- enum setting { UPDATE_aspectRatio_X, UPDATE_aspectRatio_Y , UPDATE_verticalPixelCount, UPDATE_integerScaleFactor };
10+ enum setting { UPDATE_aspectRatioX, UPDATE_aspectRatioY , UPDATE_verticalPixelCount, UPDATE_integerScaleFactor };
1111
1212const char * aspectRatioPresetLabels[] = { " Off" , " Custom" , " 4:3" , " 16:9" , " 5:3 (Nintendo 3DS)" , " 16:10 (8:5)" };
1313const float aspectRatioPresetsX[] = { 0 .0f , 12 .0f , 4 .0f , 16 .0f , 5 .0f , 16 .0f };
1414const float aspectRatioPresetsY[] = { 0 .0f , 9 .0f , 3 .0f , 9 .0f , 3 .0f , 10 .0f };
15- const int default_AspectRatio = 1 ;
15+ const int default_AspectRatio = 1 ; // Default combo list option
1616
1717const char * pixelCountPresetLabels[] = { " Custom" , " Native N64 (240p)" , " 2x (480p)" , " 3x (720p)" , " 4x (960p)" ,
1818 " 5x (1200p)" , " 6x (1440p)" , " Full HD (1080p)" , " 4K (2160p)" };
1919const int pixelCountPresets[] = { 480 , 240 , 480 , 720 , 960 , 1200 , 1440 , 1080 , 2160 , 480 };
20- const int default_pixelCount = 0 ;
20+ const int default_pixelCount = 0 ; // Default combo list option
21+ const uint32_t minVerticalPixelCount = 240 ; // see: LUS::AdvancedResolution()
22+ const uint32_t maxVerticalPixelCount = 4320 ;
2123
2224const unsigned short default_maxIntegerScaleFactor = 6 ;
2325
@@ -26,29 +28,30 @@ void AdvancedResolutionSettingsWindow::InitElement() {
2628
2729void AdvancedResolutionSettingsWindow::DrawElement () {
2830#ifndef __APPLE__
29- ImGui::SetNextWindowSize (ImVec2 (444 , 464 ), ImGuiCond_FirstUseEver);
31+ ImGui::SetNextWindowSize (ImVec2 (444 , 484 ), ImGuiCond_FirstUseEver);
3032 if (ImGui::Begin (" Advanced Resolution Settings" , &mIsVisible )) {
3133 bool update[sizeof (setting)];
3234 for (unsigned short i = 0 ; i < sizeof (setting); i++)
3335 update[i] = false ;
34- short max_integerScaleFactor = default_maxIntegerScaleFactor; // default value, which may or may not get overridden depending on viewport res
35- unsigned short integerScale_maximumBounds =
36- gfx_current_game_window_viewport.height / gfx_current_dimensions.height ; // can change when window is resized
36+ short max_integerScaleFactor = default_maxIntegerScaleFactor; // default value, which may or may not get
37+ // overridden depending on viewport res
38+ unsigned short integerScale_maximumBounds = gfx_current_game_window_viewport.height /
39+ gfx_current_dimensions.height ; // can change when window is resized
3740 if (integerScale_maximumBounds < 1 )
3841 integerScale_maximumBounds = 1 ; // it should never be less than 1x.
3942 // Stored Values
40- static float aspectRatio_X = CVarGetFloat (" gAdvancedResolution_aspectRatioX" , 16 .0f );
41- static float aspectRatio_Y = CVarGetFloat (" gAdvancedResolution_aspectRatioY" , 9 .0f );
42- static int verticalPixelCount = CVarGetInteger (" gAdvancedResolution_verticalPixelCount" , 480 );
43- static int integerScaleFactor = CVarGetInteger (" gAdvancedResolution_IntegerScaleFactor" , 1 );
43+ static float aspectRatioX = CVarGetFloat (" gAdvancedResolution_aspectRatioX" , 16 .0f );
44+ static float aspectRatioY = CVarGetFloat (" gAdvancedResolution_aspectRatioY" , 9 .0f );
45+ static int verticalPixelCount = CVarGetInteger (" gAdvancedResolution_verticalPixelCount" , 480 );
46+ static int integerScaleFactor = CVarGetInteger (" gAdvancedResolution_IntegerScaleFactor" , 1 );
4447 // Combo List defaults
4548 static int item_aspectRatio = default_AspectRatio;
4649 static int item_pixelCount = default_pixelCount;
4750 // Pointers
48- float * p_aspectRatio_X = &aspectRatio_X ;
49- float * p_aspectRatio_Y = &aspectRatio_Y ;
50- int * p_verticalPixelCount = &verticalPixelCount;
51- int * p_integerScaleFactor = &integerScaleFactor;
51+ float * p_aspectRatioX = &aspectRatioX ;
52+ float * p_aspectRatioY = &aspectRatioY ;
53+ int * p_verticalPixelCount = &verticalPixelCount;
54+ int * p_integerScaleFactor = &integerScaleFactor;
5255
5356 // The original resolution slider (also for convenience)
5457 if (UIWidgets::EnhancementSliderFloat (" Internal Resolution: %d %%" , " ##IMul" , " gInternalResolution" , 0 .5f , 2 .0f ,
@@ -71,24 +74,32 @@ void AdvancedResolutionSettingsWindow::DrawElement() {
7174 CVarSetInteger (" gAdvancedResolutionMode" , activateAdvancedMode);
7275 }
7376 // Resolution visualiser
74- ImGui::Text (" Viewport: %d by %d" , gfx_current_game_window_viewport.width , gfx_current_game_window_viewport.height );
77+ ImGui::Text (" Viewport: %d by %d" , gfx_current_game_window_viewport.width ,
78+ gfx_current_game_window_viewport.height );
7579 ImGui::Text (" Internal res: %d by %d" , gfx_current_dimensions.width , gfx_current_dimensions.height );
80+ if (IsDroppingFrames ()) {
81+ ImGui::TextColored ({ 0 .85f , 0 .85f , 0 .0f , 1 .0f },
82+ ICON_FA_EXCLAMATION_TRIANGLE " Significant frame rate (FPS) drop detected." );
83+ } else {
84+ ImGui::Text (" " );
85+ }
7686
7787 UIWidgets::PaddedSeparator (true , true , 3 .0f , 3 .0f );
7888
7989 // Aspect Ratio
8090 ImGui::Text (" Force aspect ratio:" );
81- if (ImGui::Combo (" Aspect Ratio Presets" , &item_aspectRatio, aspectRatioPresetLabels, IM_ARRAYSIZE (aspectRatioPresetLabels))) {
82- aspectRatio_X = aspectRatioPresetsX[item_aspectRatio];
83- aspectRatio_Y = aspectRatioPresetsY[item_aspectRatio];
84- update[UPDATE_aspectRatio_X] = true ;
85- update[UPDATE_aspectRatio_Y] = true ;
91+ if (ImGui::Combo (" Aspect Ratio Presets" , &item_aspectRatio, aspectRatioPresetLabels,
92+ IM_ARRAYSIZE (aspectRatioPresetLabels))) {
93+ aspectRatioX = aspectRatioPresetsX[item_aspectRatio];
94+ aspectRatioY = aspectRatioPresetsY[item_aspectRatio];
95+ update[UPDATE_aspectRatioX] = true ;
96+ update[UPDATE_aspectRatioY] = true ;
8697 }
87- if (ImGui::InputFloat (" X" , p_aspectRatio_X , 0 .1f , 1 .0f , " %.3f" ) ||
88- ImGui::InputFloat (" Y" , p_aspectRatio_Y , 0 .1f , 1 .0f , " %.3f" ) ) {
98+ if (ImGui::InputFloat (" X" , p_aspectRatioX , 0 .1f , 1 .0f , " %.3f" ) ||
99+ ImGui::InputFloat (" Y" , p_aspectRatioY , 0 .1f , 1 .0f , " %.3f" )) {
89100 item_aspectRatio = default_AspectRatio;
90- update[UPDATE_aspectRatio_X ] = true ;
91- update[UPDATE_aspectRatio_Y ] = true ;
101+ update[UPDATE_aspectRatioX ] = true ;
102+ update[UPDATE_aspectRatioY ] = true ;
92103 }
93104
94105 UIWidgets::Spacer (0 );
@@ -98,7 +109,8 @@ void AdvancedResolutionSettingsWindow::DrawElement() {
98109 UIWidgets::CheckboxGraphics::Cross, true );
99110 UIWidgets::Tooltip (
100111 " Override the resolution scale slider and use the settings below, irrespective of window size." );
101- if (ImGui::Combo (" Pixel Count Presets" , &item_pixelCount, pixelCountPresetLabels, IM_ARRAYSIZE (pixelCountPresetLabels))) {
112+ if (ImGui::Combo (" Pixel Count Presets" , &item_pixelCount, pixelCountPresetLabels,
113+ IM_ARRAYSIZE (pixelCountPresetLabels))) {
102114 verticalPixelCount = pixelCountPresets[item_pixelCount];
103115 update[UPDATE_verticalPixelCount] = true ;
104116 }
@@ -109,20 +121,20 @@ void AdvancedResolutionSettingsWindow::DrawElement() {
109121
110122 UIWidgets::Spacer (0 );
111123 // Pixel-perfect Mode
112- UIWidgets::PaddedEnhancementCheckbox (" Pixel-perfect Mode. " , " gAdvancedResolution_PixelPerfectMode" , true , true ,
124+ UIWidgets::PaddedEnhancementCheckbox (" Pixel-perfect Mode" , " gAdvancedResolution_PixelPerfectMode" , true , true ,
113125 !CVarGetInteger (" gAdvancedResolution_verticalResolutionToggle" , 0 ), " " ,
114126 UIWidgets::CheckboxGraphics::Cross, true );
115127 UIWidgets::Tooltip (" Don't scale image to fill window." );
116128
117129 if (!CVarGetInteger (" gAdvancedResolution_verticalResolutionToggle" , 0 )) {
118130 CVarSetInteger (" gAdvancedResolution_PixelPerfectMode" , (int )false );
119131 }
120-
132+
121133 if (default_maxIntegerScaleFactor < integerScale_maximumBounds) {
122- max_integerScaleFactor = integerScale_maximumBounds + 1 ; // the +1 allows people do things like cropped 5x scaling at 1080p
123- }
124- // else max_integerScaleFactor = default_maxIntegerScaleFactor; // this statement is not needed if not using a static variable
125-
134+ max_integerScaleFactor = integerScale_maximumBounds + 1 ;
135+ // the +1 allows people do things like cropped 5x scaling at 1080p
136+ }
137+
126138 // Integer Scaling
127139 UIWidgets::EnhancementSliderInt (" Integer scale factor: %d" , " ##ARSIntScale" ,
128140 " gAdvancedResolution_IntegerScaleFactor" , 1 , max_integerScaleFactor, " %d" , 1 ,
@@ -131,7 +143,7 @@ void AdvancedResolutionSettingsWindow::DrawElement() {
131143 CVarGetInteger (" gAdvancedResolution_IntegerScale_FitAutomatically" , 0 ));
132144 UIWidgets::Tooltip (" Integer scales the image. Only available in pixel-perfect mode." );
133145
134- UIWidgets::PaddedEnhancementCheckbox (" Automatically scale image to fit viewport. " ,
146+ UIWidgets::PaddedEnhancementCheckbox (" Automatically scale image to fit viewport" ,
135147 " gAdvancedResolution_IntegerScale_FitAutomatically" , true , true ,
136148 !CVarGetInteger (" gAdvancedResolution_PixelPerfectMode" , 0 ), " " ,
137149 UIWidgets::CheckboxGraphics::Cross, true );
@@ -140,15 +152,40 @@ void AdvancedResolutionSettingsWindow::DrawElement() {
140152 CVarSetInteger (" gAdvancedResolution_IntegerScaleFactor" , integerScale_maximumBounds);
141153 }
142154
143- // Update CVars
144- if (update[UPDATE_aspectRatio_X]) { CVarSetFloat (" gAdvancedResolution_aspectRatioX" , aspectRatio_X); }
145- if (update[UPDATE_aspectRatio_Y]) { CVarSetFloat (" gAdvancedResolution_aspectRatioY" , aspectRatio_Y); }
146- if (update[UPDATE_verticalPixelCount]) { CVarSetInteger (" gAdvancedResolution_verticalPixelCount" , (int32_t )verticalPixelCount); }
155+ // Clamp and update CVars
156+ if (update[UPDATE_aspectRatioX]) {
157+ if (aspectRatioX < 0 .0f ) {
158+ aspectRatioX = 0 .0f ;
159+ }
160+ CVarSetFloat (" gAdvancedResolution_aspectRatioX" , aspectRatioX);
161+ }
162+ if (update[UPDATE_aspectRatioY]) {
163+ if (aspectRatioY < 0 .0f ) {
164+ aspectRatioY = 0 .0f ;
165+ }
166+ CVarSetFloat (" gAdvancedResolution_aspectRatioY" , aspectRatioY);
167+ }
168+ if (update[UPDATE_verticalPixelCount]) {
169+ if (verticalPixelCount < minVerticalPixelCount) {
170+ verticalPixelCount = minVerticalPixelCount;
171+ }
172+ if (verticalPixelCount > maxVerticalPixelCount) {
173+ verticalPixelCount = maxVerticalPixelCount;
174+ }
175+ CVarSetInteger (" gAdvancedResolution_verticalPixelCount" , (int32_t )verticalPixelCount);
176+ }
147177 }
148178 ImGui::End ();
149179#endif
150180}
151181
152182void AdvancedResolutionSettingsWindow::UpdateElement () {
153183}
184+
185+ bool AdvancedResolutionSettingsWindow::IsDroppingFrames () {
186+ // a rather imprecise way of checking for frame drops.
187+ // but it's mostly there to inform the player of large drops.
188+ const float threshold = 1 .1f ;
189+ return ImGui::GetIO ().Framerate < (CVarGetInteger (" gInterpolationFPS" , 20 ) - threshold);
190+ }
154191} // namespace AdvancedResolutionSettings
0 commit comments