-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option for configuring fps limit.
- Loading branch information
Showing
5 changed files
with
103 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use std::time::Duration; | ||
|
||
use bevy::prelude::*; | ||
use num_traits::FromPrimitive; | ||
|
||
#[derive(Default, Clone, Copy, FromPrimitive, Resource)] | ||
pub enum FPSLimiter { | ||
#[default] | ||
Auto, | ||
Unlimited, | ||
F60, | ||
F144, | ||
F240, | ||
F360, | ||
F480, | ||
} | ||
|
||
impl FPSLimiter { | ||
pub fn enum_prev(&mut self) -> Option<Self> { | ||
FromPrimitive::from_i8(*self as i8 - 1).map(|n| std::mem::replace(self, n)) | ||
} | ||
|
||
pub fn enum_next(&mut self) -> Option<Self> { | ||
FromPrimitive::from_i8(*self as i8 + 1).map(|n| std::mem::replace(self, n)) | ||
} | ||
|
||
pub fn get_limiter(&self) -> bevy_framepace::Limiter { | ||
let ft = |fps| Duration::from_secs_f32(1.0 / fps as f32); | ||
match self { | ||
FPSLimiter::Auto => bevy_framepace::Limiter::Auto, | ||
FPSLimiter::Unlimited => bevy_framepace::Limiter::Off, | ||
FPSLimiter::F60 => bevy_framepace::Limiter::Manual(ft(60)), | ||
FPSLimiter::F144 => bevy_framepace::Limiter::Manual(ft(144)), | ||
FPSLimiter::F240 => bevy_framepace::Limiter::Manual(ft(240)), | ||
FPSLimiter::F360 => bevy_framepace::Limiter::Manual(ft(360)), | ||
FPSLimiter::F480 => bevy_framepace::Limiter::Manual(ft(480)), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
mod fps_limiter; | ||
pub mod plugin; | ||
pub mod transform; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters