Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Simulator CPU Usage up to 50%. #45

Merged
merged 6 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

## [Unreleased] - ReleaseDate

### Added

- [#45](https://github.com/embedded-graphics/simulator/pull/45) Added `OutputSettingsBuilder::max_fps` to set the maximum FPS of the simulator.

### Changed

- [#45](https://github.com/embedded-graphics/simulator/pull/45) Limit simulator to 60FPS by default.

## [0.4.0] - 2022-09-19

### Changed
Expand Down
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ image = "0.23.14"
base64 = "0.13.0"
embedded-graphics = "0.7.1"
sdl2 = { version = "0.35.1", optional = true }
ouroboros = { version = "0.15.5", optional = true }

[features]
default = [ "with-sdl" ]
fixed_point = [ "embedded-graphics/fixed_point" ]
with-sdl = [ "sdl2" ]
default = ["with-sdl"]
fixed_point = ["embedded-graphics/fixed_point"]
with-sdl = ["sdl2", "ouroboros"]
12 changes: 12 additions & 0 deletions src/output_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pub struct OutputSettings {
pub pixel_spacing: u32,
/// Binary color theme.
pub theme: BinaryColorTheme,
/// Maximum frames per second shown in the window.
pub max_fps: u32,
}

impl OutputSettings {
Expand Down Expand Up @@ -51,6 +53,7 @@ pub struct OutputSettingsBuilder {
scale: Option<u32>,
pixel_spacing: Option<u32>,
theme: BinaryColorTheme,
max_fps: Option<u32>,
}

impl OutputSettingsBuilder {
Expand All @@ -60,6 +63,7 @@ impl OutputSettingsBuilder {
scale: None,
pixel_spacing: None,
theme: BinaryColorTheme::Default,
max_fps: None,
}
}

Expand Down Expand Up @@ -112,12 +116,20 @@ impl OutputSettingsBuilder {
self
}

/// Sets the FPS limit of the window.
pub fn max_fps(mut self, max_fps: u32) -> Self {
self.max_fps = Some(max_fps);

self
}

/// Builds the output settings.
pub fn build(self) -> OutputSettings {
OutputSettings {
scale: self.scale.unwrap_or(1),
pixel_spacing: self.pixel_spacing.unwrap_or(0),
theme: self.theme,
max_fps: self.max_fps.unwrap_or(60),
}
}
}
Loading