Skip to content

Commit

Permalink
Changed ScreenDimensions to contain only LogicalSize instead of Physi…
Browse files Browse the repository at this point in the history
…calSize
  • Loading branch information
AnneKitsune committed Dec 5, 2018
1 parent 3991a7a commit 5c67819
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
26 changes: 10 additions & 16 deletions amethyst_renderer/src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ impl WindowMessages {
#[derive(Debug)]
pub struct ScreenDimensions {
/// Screen width in pixels (px).
w: f32,
pub(crate) w: f64,
/// Screen height in pixels (px).
h: f32,
pub(crate) h: f64,
/// Width divided by height.
aspect_ratio: f32,
/// The ratio between the backing framebuffer resolution and the window size in screen pixels.
Expand All @@ -79,30 +79,24 @@ pub struct ScreenDimensions {

impl ScreenDimensions {
/// Creates a new screen dimensions object with the given width and height.
pub fn new(w: u32, h: u32, hidpi: f64) -> Self {
pub fn new(w: f64, h: f64, hidpi: f64) -> Self {
ScreenDimensions {
w: w as f32,
h: h as f32,
w,
h,
aspect_ratio: w as f32 / h as f32,
hidpi,
dirty: false,
}
}

/// Returns the current width of the window.
///
/// This is returned as a float for user convenience, as this is typically used with other
/// float values. This will only ever be a non-negative integer though.
pub fn width(&self) -> f32 {
self.w * self.hidpi_factor() as f32
self.w as f32
}

/// Returns the current height of the window.
///
/// This is returned as a float for user convenience, as this is typically used with other
/// float values. This will only ever be a non-negative integer though.
pub fn height(&self) -> f32 {
self.h * self.hidpi_factor() as f32
self.h as f32
}

/// Returns the current aspect ratio of the window.
Expand All @@ -122,9 +116,9 @@ impl ScreenDimensions {
/// Only use this if you need to programmatically set the resolution of your game.
/// This resource is updated automatically by the engine when a resize occurs so you don't need
/// this unless you want to resize the game window.
pub fn update(&mut self, w: u32, h: u32) {
self.w = w as f32;
self.h = h as f32;
pub fn update(&mut self, w: f64, h: f64) {
self.w = w;
self.h = h;
self.aspect_ratio = w as f32 / h as f32;
self.dirty = true;
}
Expand Down
10 changes: 6 additions & 4 deletions amethyst_renderer/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct RenderSystem<P> {
pipe: P,
#[derivative(Debug = "ignore")]
renderer: Renderer,
cached_size: (u32, u32),
cached_size: (f64, f64),
// This only exists to allow the system to re-use a vec allocation
// during event compression. It's length 0 except during `fn render`.
event_vec: Vec<Event>,
Expand Down Expand Up @@ -116,8 +116,8 @@ where
command(self.renderer.window());
}

let width = screen_dimensions.width() as u32;
let height = screen_dimensions.height() as u32;
let width = screen_dimensions.w;
let height = screen_dimensions.h;

// Send resource size changes to the window
if screen_dimensions.dirty {
Expand All @@ -128,11 +128,13 @@ where
}

if let Some(size) = self.renderer.window().get_inner_size() {
let (window_width, window_height): (u32, u32) = size.into();
let (window_width, window_height): (f64, f64) = size.into();

// Send window size changes to the resource
if (window_width, window_height) != (width, height) {
info!("resized. screendim {} {} winsize {} {}.", width, height, window_width, window_height);
screen_dimensions.update(window_width, window_height);
info!("done resizing {} {}", screen_dimensions.w, screen_dimensions.h);

// We don't need to send the updated size of the window back to the window itself,
// so set dirty to false.
Expand Down

0 comments on commit 5c67819

Please sign in to comment.