mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'jtriantafylos/background_fps' into 'master'
Fixes #1350 - Allow players to cap the game FPS when unfocused Closes #1350 See merge request veloren/veloren!2890
This commit is contained in:
commit
94439a4240
@ -61,6 +61,7 @@
|
|||||||
"hud.settings.sprites_view_distance": "Sprites View Distance",
|
"hud.settings.sprites_view_distance": "Sprites View Distance",
|
||||||
"hud.settings.figures_view_distance": "Entities View Distance",
|
"hud.settings.figures_view_distance": "Entities View Distance",
|
||||||
"hud.settings.maximum_fps": "Maximum FPS",
|
"hud.settings.maximum_fps": "Maximum FPS",
|
||||||
|
"hud.settings.background_fps": "Background FPS",
|
||||||
"hud.settings.present_mode": "Present Mode",
|
"hud.settings.present_mode": "Present Mode",
|
||||||
"hud.settings.present_mode.fifo": "Fifo",
|
"hud.settings.present_mode.fifo": "Fifo",
|
||||||
"hud.settings.present_mode.mailbox": "Mailbox",
|
"hud.settings.present_mode.mailbox": "Mailbox",
|
||||||
|
@ -51,6 +51,9 @@ widget_ids! {
|
|||||||
max_fps_slider,
|
max_fps_slider,
|
||||||
max_fps_text,
|
max_fps_text,
|
||||||
max_fps_value,
|
max_fps_value,
|
||||||
|
max_background_fps_slider,
|
||||||
|
max_background_fps_text,
|
||||||
|
max_background_fps_value,
|
||||||
present_mode_text,
|
present_mode_text,
|
||||||
present_mode_list,
|
present_mode_list,
|
||||||
fov_slider,
|
fov_slider,
|
||||||
@ -144,17 +147,44 @@ pub struct State {
|
|||||||
// Resolution, Bit Depth and Refresh Rate
|
// Resolution, Bit Depth and Refresh Rate
|
||||||
video_modes: Vec<VideoMode>,
|
video_modes: Vec<VideoMode>,
|
||||||
}
|
}
|
||||||
const FPS_CHOICES: [Fps; 12] = [
|
const FPS_CHOICES: [Fps; 17] = [
|
||||||
Fps::Max(15),
|
Fps::Max(15),
|
||||||
Fps::Max(30),
|
Fps::Max(30),
|
||||||
Fps::Max(40),
|
Fps::Max(40),
|
||||||
Fps::Max(50),
|
Fps::Max(50),
|
||||||
Fps::Max(60),
|
Fps::Max(60),
|
||||||
|
Fps::Max(75),
|
||||||
Fps::Max(90),
|
Fps::Max(90),
|
||||||
|
Fps::Max(100),
|
||||||
Fps::Max(120),
|
Fps::Max(120),
|
||||||
Fps::Max(144),
|
Fps::Max(144),
|
||||||
|
Fps::Max(165),
|
||||||
|
Fps::Max(200),
|
||||||
Fps::Max(240),
|
Fps::Max(240),
|
||||||
Fps::Max(300),
|
Fps::Max(280),
|
||||||
|
Fps::Max(360),
|
||||||
|
Fps::Max(500),
|
||||||
|
Fps::Unlimited,
|
||||||
|
];
|
||||||
|
const BG_FPS_CHOICES: [Fps; 20] = [
|
||||||
|
Fps::Max(5),
|
||||||
|
Fps::Max(10),
|
||||||
|
Fps::Max(15),
|
||||||
|
Fps::Max(20),
|
||||||
|
Fps::Max(30),
|
||||||
|
Fps::Max(40),
|
||||||
|
Fps::Max(50),
|
||||||
|
Fps::Max(60),
|
||||||
|
Fps::Max(75),
|
||||||
|
Fps::Max(90),
|
||||||
|
Fps::Max(100),
|
||||||
|
Fps::Max(120),
|
||||||
|
Fps::Max(144),
|
||||||
|
Fps::Max(165),
|
||||||
|
Fps::Max(200),
|
||||||
|
Fps::Max(240),
|
||||||
|
Fps::Max(280),
|
||||||
|
Fps::Max(360),
|
||||||
Fps::Max(500),
|
Fps::Max(500),
|
||||||
Fps::Unlimited,
|
Fps::Unlimited,
|
||||||
];
|
];
|
||||||
@ -306,13 +336,58 @@ impl<'a> Widget for Video<'a> {
|
|||||||
.color(TEXT_COLOR)
|
.color(TEXT_COLOR)
|
||||||
.set(state.ids.max_fps_value, ui);
|
.set(state.ids.max_fps_value, ui);
|
||||||
|
|
||||||
|
// Max Background FPS
|
||||||
|
Text::new(self.localized_strings.get("hud.settings.background_fps"))
|
||||||
|
.down_from(state.ids.vd_slider, 10.0)
|
||||||
|
.right_from(state.ids.max_fps_value, 30.0)
|
||||||
|
.font_size(self.fonts.cyri.scale(14))
|
||||||
|
.font_id(self.fonts.cyri.conrod_id)
|
||||||
|
.color(TEXT_COLOR)
|
||||||
|
.set(state.ids.max_background_fps_text, ui);
|
||||||
|
|
||||||
|
if let Some(which) = ImageSlider::discrete(
|
||||||
|
BG_FPS_CHOICES
|
||||||
|
.iter()
|
||||||
|
.position(|&x| x == self.global_state.settings.graphics.max_background_fps)
|
||||||
|
.unwrap_or(5),
|
||||||
|
0,
|
||||||
|
BG_FPS_CHOICES.len() - 1,
|
||||||
|
self.imgs.slider_indicator,
|
||||||
|
self.imgs.slider,
|
||||||
|
)
|
||||||
|
.w_h(104.0, 22.0)
|
||||||
|
.down_from(state.ids.max_background_fps_text, 8.0)
|
||||||
|
.track_breadth(12.0)
|
||||||
|
.slider_length(10.0)
|
||||||
|
.pad_track((5.0, 5.0))
|
||||||
|
.set(state.ids.max_background_fps_slider, ui)
|
||||||
|
{
|
||||||
|
events.push(GraphicsChange::ChangeMaxBackgroundFPS(
|
||||||
|
BG_FPS_CHOICES[which],
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
Text::new(
|
||||||
|
&self
|
||||||
|
.global_state
|
||||||
|
.settings
|
||||||
|
.graphics
|
||||||
|
.max_background_fps
|
||||||
|
.to_string(),
|
||||||
|
)
|
||||||
|
.right_from(state.ids.max_background_fps_slider, 8.0)
|
||||||
|
.font_size(self.fonts.cyri.scale(14))
|
||||||
|
.font_id(self.fonts.cyri.conrod_id)
|
||||||
|
.color(TEXT_COLOR)
|
||||||
|
.set(state.ids.max_background_fps_value, ui);
|
||||||
|
|
||||||
// Get render mode
|
// Get render mode
|
||||||
let render_mode = &self.global_state.settings.graphics.render_mode;
|
let render_mode = &self.global_state.settings.graphics.render_mode;
|
||||||
|
|
||||||
// Present Mode
|
// Present Mode
|
||||||
Text::new(self.localized_strings.get("hud.settings.present_mode"))
|
Text::new(self.localized_strings.get("hud.settings.present_mode"))
|
||||||
.down_from(state.ids.vd_slider, 10.0)
|
.down_from(state.ids.vd_slider, 10.0)
|
||||||
.right_from(state.ids.max_fps_value, 30.0)
|
.right_from(state.ids.max_background_fps_value, 30.0)
|
||||||
.font_size(self.fonts.cyri.scale(14))
|
.font_size(self.fonts.cyri.scale(14))
|
||||||
.font_id(self.fonts.cyri.conrod_id)
|
.font_id(self.fonts.cyri.conrod_id)
|
||||||
.color(TEXT_COLOR)
|
.color(TEXT_COLOR)
|
||||||
|
@ -230,8 +230,11 @@ fn handle_main_events_cleared(
|
|||||||
// running at hundreds/thousands of FPS resulting in high GPU usage for
|
// running at hundreds/thousands of FPS resulting in high GPU usage for
|
||||||
// effectively doing nothing.
|
// effectively doing nothing.
|
||||||
let max_fps = get_fps(global_state.settings.graphics.max_fps);
|
let max_fps = get_fps(global_state.settings.graphics.max_fps);
|
||||||
|
let max_background_fps = get_fps(global_state.settings.graphics.max_background_fps);
|
||||||
const TITLE_SCREEN_FPS_CAP: u32 = 60;
|
const TITLE_SCREEN_FPS_CAP: u32 = 60;
|
||||||
let target_fps = if capped_fps {
|
let target_fps = if !global_state.window.focused {
|
||||||
|
u32::min(max_background_fps, max_fps)
|
||||||
|
} else if capped_fps {
|
||||||
u32::min(TITLE_SCREEN_FPS_CAP, max_fps)
|
u32::min(TITLE_SCREEN_FPS_CAP, max_fps)
|
||||||
} else {
|
} else {
|
||||||
max_fps
|
max_fps
|
||||||
|
@ -72,6 +72,7 @@ pub enum Graphics {
|
|||||||
AdjustFigureLoDRenderDistance(u32),
|
AdjustFigureLoDRenderDistance(u32),
|
||||||
|
|
||||||
ChangeMaxFPS(Fps),
|
ChangeMaxFPS(Fps),
|
||||||
|
ChangeMaxBackgroundFPS(Fps),
|
||||||
ChangeFOV(u16),
|
ChangeFOV(u16),
|
||||||
|
|
||||||
ChangeGamma(f32),
|
ChangeGamma(f32),
|
||||||
@ -346,6 +347,9 @@ impl SettingsChange {
|
|||||||
Graphics::ChangeMaxFPS(fps) => {
|
Graphics::ChangeMaxFPS(fps) => {
|
||||||
settings.graphics.max_fps = fps;
|
settings.graphics.max_fps = fps;
|
||||||
},
|
},
|
||||||
|
Graphics::ChangeMaxBackgroundFPS(fps) => {
|
||||||
|
settings.graphics.max_background_fps = fps;
|
||||||
|
},
|
||||||
Graphics::ChangeFOV(new_fov) => {
|
Graphics::ChangeFOV(new_fov) => {
|
||||||
settings.graphics.fov = new_fov;
|
settings.graphics.fov = new_fov;
|
||||||
session_state.scene.camera_mut().set_fov_deg(new_fov);
|
session_state.scene.camera_mut().set_fov_deg(new_fov);
|
||||||
|
@ -35,6 +35,7 @@ pub struct GraphicsSettings {
|
|||||||
pub lossy_terrain_compression: bool,
|
pub lossy_terrain_compression: bool,
|
||||||
pub figure_lod_render_distance: u32,
|
pub figure_lod_render_distance: u32,
|
||||||
pub max_fps: Fps,
|
pub max_fps: Fps,
|
||||||
|
pub max_background_fps: Fps,
|
||||||
pub fov: u16,
|
pub fov: u16,
|
||||||
pub gamma: f32,
|
pub gamma: f32,
|
||||||
pub exposure: f32,
|
pub exposure: f32,
|
||||||
@ -54,6 +55,7 @@ impl Default for GraphicsSettings {
|
|||||||
lossy_terrain_compression: false,
|
lossy_terrain_compression: false,
|
||||||
figure_lod_render_distance: 300,
|
figure_lod_render_distance: 300,
|
||||||
max_fps: Fps::Max(60),
|
max_fps: Fps::Max(60),
|
||||||
|
max_background_fps: Fps::Max(30),
|
||||||
fov: 70,
|
fov: 70,
|
||||||
gamma: 1.0,
|
gamma: 1.0,
|
||||||
exposure: 1.0,
|
exposure: 1.0,
|
||||||
|
@ -386,7 +386,7 @@ pub struct Window {
|
|||||||
keypress_map: HashMap<GameInput, winit::event::ElementState>,
|
keypress_map: HashMap<GameInput, winit::event::ElementState>,
|
||||||
pub remapping_keybindings: Option<GameInput>,
|
pub remapping_keybindings: Option<GameInput>,
|
||||||
events: Vec<Event>,
|
events: Vec<Event>,
|
||||||
focused: bool,
|
pub focused: bool,
|
||||||
gilrs: Option<Gilrs>,
|
gilrs: Option<Gilrs>,
|
||||||
pub controller_settings: ControllerSettings,
|
pub controller_settings: ControllerSettings,
|
||||||
cursor_position: winit::dpi::PhysicalPosition<f64>,
|
cursor_position: winit::dpi::PhysicalPosition<f64>,
|
||||||
|
Loading…
Reference in New Issue
Block a user