Merge branch 'pizzaluc/unlimited_FPS' into 'master'

Implemented #896 - Added option for Unlimited FPS

Closes #896

See merge request veloren/veloren!1713
This commit is contained in:
Imbris 2021-01-23 08:34:38 +00:00
commit 7cbbb70c42
5 changed files with 49 additions and 11 deletions

View File

@ -51,6 +51,7 @@ use crate::{
i18n::{LanguageMetadata, Localization}, i18n::{LanguageMetadata, Localization},
render::{Consts, Globals, RenderMode, Renderer}, render::{Consts, Globals, RenderMode, Renderer},
scene::camera::{self, Camera}, scene::camera::{self, Camera},
settings::Fps,
ui::{fonts::Fonts, img_ids::Rotations, slot, Graphic, Ingameable, ScaleMode, Ui}, ui::{fonts::Fonts, img_ids::Rotations, slot, Graphic, Ingameable, ScaleMode, Ui},
window::{Event as WinEvent, FullScreenSettings, GameInput}, window::{Event as WinEvent, FullScreenSettings, GameInput},
GlobalState, GlobalState,
@ -349,7 +350,7 @@ pub enum Event {
AdjustMusicVolume(f32), AdjustMusicVolume(f32),
AdjustSfxVolume(f32), AdjustSfxVolume(f32),
//ChangeAudioDevice(String), //ChangeAudioDevice(String),
ChangeMaxFPS(u32), ChangeMaxFPS(Fps),
ChangeFOV(u16), ChangeFOV(u16),
ChangeGamma(f32), ChangeGamma(f32),
ChangeExposure(f32), ChangeExposure(f32),

View File

@ -10,6 +10,7 @@ use crate::{
AaMode, CloudMode, FluidMode, LightingMode, RenderMode, ShadowMapMode, ShadowMode, AaMode, CloudMode, FluidMode, LightingMode, RenderMode, ShadowMapMode, ShadowMode,
UpscaleMode, UpscaleMode,
}, },
settings::Fps,
ui::{fonts::Fonts, ImageSlider, ScaleMode, ToggleButton}, ui::{fonts::Fonts, ImageSlider, ScaleMode, ToggleButton},
window::{FullScreenSettings, FullscreenMode, GameInput}, window::{FullScreenSettings, FullscreenMode, GameInput},
GlobalState, GlobalState,
@ -27,7 +28,20 @@ use itertools::Itertools;
use std::iter::once; use std::iter::once;
use winit::monitor::VideoMode; use winit::monitor::VideoMode;
const FPS_CHOICES: [u32; 11] = [15, 30, 40, 50, 60, 90, 120, 144, 240, 300, 500]; const FPS_CHOICES: [Fps; 12] = [
Fps::Max(15),
Fps::Max(30),
Fps::Max(40),
Fps::Max(50),
Fps::Max(60),
Fps::Max(90),
Fps::Max(120),
Fps::Max(144),
Fps::Max(240),
Fps::Max(300),
Fps::Max(500),
Fps::Unlimited,
];
widget_ids! { widget_ids! {
struct Ids { struct Ids {
@ -298,7 +312,7 @@ pub enum Event {
AdjustMusicVolume(f32), AdjustMusicVolume(f32),
AdjustSfxVolume(f32), AdjustSfxVolume(f32),
//ChangeAudioDevice(String), //ChangeAudioDevice(String),
MaximumFPS(u32), MaximumFPS(Fps),
CrosshairTransp(f32), CrosshairTransp(f32),
CrosshairType(CrosshairType), CrosshairType(CrosshairType),
UiScale(ScaleChange), UiScale(ScaleChange),
@ -1794,7 +1808,7 @@ impl<'a> Widget for SettingsWindow<'a> {
.position(|&x| x == self.global_state.settings.graphics.max_fps) .position(|&x| x == self.global_state.settings.graphics.max_fps)
.unwrap_or(5), .unwrap_or(5),
0, 0,
10, FPS_CHOICES.len() - 1,
self.imgs.slider_indicator, self.imgs.slider_indicator,
self.imgs.slider, self.imgs.slider,
) )
@ -1808,7 +1822,7 @@ impl<'a> Widget for SettingsWindow<'a> {
events.push(Event::MaximumFPS(FPS_CHOICES[which])); events.push(Event::MaximumFPS(FPS_CHOICES[which]));
} }
Text::new(&format!("{}", self.global_state.settings.graphics.max_fps)) Text::new(&self.global_state.settings.graphics.max_fps.to_string())
.right_from(state.ids.max_fps_slider, 8.0) .right_from(state.ids.max_fps_slider, 8.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)

View File

@ -9,7 +9,7 @@ use veloren_voxygen::{
logging, logging,
profile::Profile, profile::Profile,
run, run,
settings::{AudioOutput, Settings}, settings::{get_fps, AudioOutput, Settings},
window::Window, window::Window,
GlobalState, GlobalState,
}; };
@ -180,7 +180,7 @@ fn main() {
profile, profile,
window, window,
clock: Clock::new(std::time::Duration::from_secs_f64( clock: Clock::new(std::time::Duration::from_secs_f64(
1.0 / settings.graphics.max_fps as f64, 1.0 / get_fps(settings.graphics.max_fps) as f64,
)), )),
settings, settings,
info_message: None, info_message: None,

View File

@ -1,5 +1,6 @@
use crate::{ use crate::{
menu::main::MainMenuState, menu::main::MainMenuState,
settings::get_fps,
ui, ui,
window::{Event, EventLoop}, window::{Event, EventLoop},
Direction, GlobalState, PlayState, PlayStateResult, Direction, GlobalState, PlayState, PlayStateResult,
@ -177,7 +178,7 @@ fn handle_main_events_cleared(
// Wait for the next tick. // Wait for the next tick.
span!(guard, "Main thread sleep"); span!(guard, "Main thread sleep");
global_state.clock.set_target_dt(Duration::from_secs_f64( global_state.clock.set_target_dt(Duration::from_secs_f64(
1.0 / global_state.settings.graphics.max_fps as f64, 1.0 / get_fps(global_state.settings.graphics.max_fps) as f64,
)); ));
global_state.clock.tick(); global_state.clock.tick();
drop(guard); drop(guard);

View File

@ -8,7 +8,7 @@ use crate::{
use directories_next::UserDirs; use directories_next::UserDirs;
use hashbrown::{HashMap, HashSet}; use hashbrown::{HashMap, HashSet};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{fs, path::PathBuf}; use std::{fmt, fs, path::PathBuf};
use tracing::warn; use tracing::warn;
use vek::*; use vek::*;
use winit::event::{MouseButton, VirtualKeyCode}; use winit::event::{MouseButton, VirtualKeyCode};
@ -622,6 +622,28 @@ impl Default for Log {
} }
} }
#[derive(Copy, Clone, Serialize, Deserialize, Debug, PartialEq)]
pub enum Fps {
Max(u32),
Unlimited,
}
pub fn get_fps(max_fps: Fps) -> u32 {
match max_fps {
Fps::Max(x) => x,
Fps::Unlimited => u32::MAX,
}
}
impl fmt::Display for Fps {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Fps::Max(x) => write!(f, "{}", x),
Fps::Unlimited => write!(f, "Unlimited"),
}
}
}
/// `GraphicsSettings` contains settings related to framerate and in-game /// `GraphicsSettings` contains settings related to framerate and in-game
/// visuals. /// visuals.
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
@ -631,7 +653,7 @@ pub struct GraphicsSettings {
pub sprite_render_distance: u32, pub sprite_render_distance: u32,
pub particles_enabled: bool, pub particles_enabled: bool,
pub figure_lod_render_distance: u32, pub figure_lod_render_distance: u32,
pub max_fps: u32, pub max_fps: Fps,
pub fov: u16, pub fov: u16,
pub gamma: f32, pub gamma: f32,
pub exposure: f32, pub exposure: f32,
@ -649,7 +671,7 @@ impl Default for GraphicsSettings {
sprite_render_distance: 100, sprite_render_distance: 100,
particles_enabled: true, particles_enabled: true,
figure_lod_render_distance: 300, figure_lod_render_distance: 300,
max_fps: 60, max_fps: Fps::Max(60),
fov: 70, fov: 70,
gamma: 1.0, gamma: 1.0,
exposure: 1.0, exposure: 1.0,