From 703087fd88601d997a822ce550686f02e7aec89b Mon Sep 17 00:00:00 2001 From: Keith Simmons Date: Tue, 4 Feb 2020 20:46:46 -0800 Subject: [PATCH] set buffer frames to 1 and add extra buffer startup command. Fix bug where mouse position is improperly scaled --- .gitignore | 1 + src/main.rs | 3 +++ src/redraw_scheduler.rs | 7 ++++--- src/settings.rs | 18 ++++++++++++++---- src/window.rs | 3 ++- 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 53eaa21..cce2d15 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target **/*.rs.bk +*.log diff --git a/src/main.rs b/src/main.rs index 13a9528..c6eef01 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,6 +35,9 @@ fn main() { } else if arg == "--noIdle" { SETTINGS.no_idle.store(true, Ordering::Relaxed); false + } else if arg == "--extraBufferFrames" { + SETTINGS.buffer_frames.store(60, Ordering::Relaxed); + false } else { true } diff --git a/src/redraw_scheduler.rs b/src/redraw_scheduler.rs index 70d1d0c..8ca30e7 100644 --- a/src/redraw_scheduler.rs +++ b/src/redraw_scheduler.rs @@ -4,12 +4,12 @@ use std::time::Instant; use log::trace; +use crate::settings::SETTINGS; + lazy_static! { pub static ref REDRAW_SCHEDULER: RedrawScheduler = RedrawScheduler::new(); } -const BUFFER_FRAMES: u16 = 60; - pub struct RedrawScheduler { frames_queued: AtomicU16, scheduled_frame: Mutex> @@ -38,7 +38,8 @@ impl RedrawScheduler { pub fn queue_next_frame(&self) { trace!("Next frame queued"); - self.frames_queued.store(BUFFER_FRAMES, Ordering::Relaxed); + let buffer_frames = SETTINGS.buffer_frames.load(Ordering::Relaxed); + self.frames_queued.store(buffer_frames, Ordering::Relaxed); } pub fn should_draw(&self) -> bool { diff --git a/src/settings.rs b/src/settings.rs index 6717b6a..d79717f 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -1,13 +1,23 @@ -use std::sync::atomic::AtomicBool; +use std::sync::atomic::{AtomicBool, AtomicU16}; use crossbeam::atomic::AtomicCell; lazy_static! { - pub static ref SETTINGS: Settings = Settings::default(); + pub static ref SETTINGS: Settings = Settings::new(); } -#[derive(Default)] pub struct Settings { pub neovim_arguments: AtomicCell>>, - pub no_idle: AtomicBool + pub no_idle: AtomicBool, + pub buffer_frames: AtomicU16 +} + +impl Settings { + pub fn new() -> Settings { + Settings { + neovim_arguments: AtomicCell::new(None), + no_idle: AtomicBool::new(false), + buffer_frames: AtomicU16::new(1), + } + } } diff --git a/src/window.rs b/src/window.rs index a858f19..ac30734 100644 --- a/src/window.rs +++ b/src/window.rs @@ -4,7 +4,7 @@ use std::time::{Duration, Instant}; use image::{load_from_memory, GenericImageView, Pixel}; use skulpin::{CoordinateSystem, RendererBuilder, PresentMode}; -use skulpin::winit::dpi::LogicalSize; +use skulpin::winit::dpi::{LogicalSize, LogicalPosition}; use skulpin::winit::event::{ElementState, Event, MouseScrollDelta, StartCause, WindowEvent, ModifiersState}; use skulpin::winit::event_loop::{ControlFlow, EventLoop}; use skulpin::winit::window::{Icon, WindowBuilder}; @@ -138,6 +138,7 @@ pub fn ui_loop() { }, .. } => { + let position: LogicalPosition = position.to_logical(window.scale_factor()); let grid_y = (position.x / renderer.font_width as f64) as i64; let grid_x = (position.y / renderer.font_height as f64) as i64; let (old_x, old_y) = mouse_pos;