Implemented #896 - Added option for Unlimited FPS

This commit is contained in:
Lucas Vulpius 2021-01-23 08:34:38 +00:00 committed by Imbris
parent 4b4504a3a3
commit 43b5559325
5 changed files with 49 additions and 11 deletions

View File

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

View File

@ -10,6 +10,7 @@ use crate::{
AaMode, CloudMode, FluidMode, LightingMode, RenderMode, ShadowMapMode, ShadowMode,
UpscaleMode,
},
settings::Fps,
ui::{fonts::Fonts, ImageSlider, ScaleMode, ToggleButton},
window::{FullScreenSettings, FullscreenMode, GameInput},
GlobalState,
@ -27,7 +28,20 @@ use itertools::Itertools;
use std::iter::once;
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! {
struct Ids {
@ -298,7 +312,7 @@ pub enum Event {
AdjustMusicVolume(f32),
AdjustSfxVolume(f32),
//ChangeAudioDevice(String),
MaximumFPS(u32),
MaximumFPS(Fps),
CrosshairTransp(f32),
CrosshairType(CrosshairType),
UiScale(ScaleChange),
@ -1794,7 +1808,7 @@ impl<'a> Widget for SettingsWindow<'a> {
.position(|&x| x == self.global_state.settings.graphics.max_fps)
.unwrap_or(5),
0,
10,
FPS_CHOICES.len() - 1,
self.imgs.slider_indicator,
self.imgs.slider,
)
@ -1808,7 +1822,7 @@ impl<'a> Widget for SettingsWindow<'a> {
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)
.font_size(self.fonts.cyri.scale(14))
.font_id(self.fonts.cyri.conrod_id)

View File

@ -9,7 +9,7 @@ use veloren_voxygen::{
logging,
profile::Profile,
run,
settings::{AudioOutput, Settings},
settings::{get_fps, AudioOutput, Settings},
window::Window,
GlobalState,
};
@ -180,7 +180,7 @@ fn main() {
profile,
window,
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,
info_message: None,

View File

@ -1,5 +1,6 @@
use crate::{
menu::main::MainMenuState,
settings::get_fps,
ui,
window::{Event, EventLoop},
Direction, GlobalState, PlayState, PlayStateResult,
@ -177,7 +178,7 @@ fn handle_main_events_cleared(
// Wait for the next tick.
span!(guard, "Main thread sleep");
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();
drop(guard);

View File

@ -8,7 +8,7 @@ use crate::{
use directories_next::UserDirs;
use hashbrown::{HashMap, HashSet};
use serde::{Deserialize, Serialize};
use std::{fs, path::PathBuf};
use std::{fmt, fs, path::PathBuf};
use tracing::warn;
use vek::*;
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
/// visuals.
#[derive(Clone, Debug, Serialize, Deserialize)]
@ -631,7 +653,7 @@ pub struct GraphicsSettings {
pub sprite_render_distance: u32,
pub particles_enabled: bool,
pub figure_lod_render_distance: u32,
pub max_fps: u32,
pub max_fps: Fps,
pub fov: u16,
pub gamma: f32,
pub exposure: f32,
@ -649,7 +671,7 @@ impl Default for GraphicsSettings {
sprite_render_distance: 100,
particles_enabled: true,
figure_lod_render_distance: 300,
max_fps: 60,
max_fps: Fps::Max(60),
fov: 70,
gamma: 1.0,
exposure: 1.0,