Skip to content

Commit

Permalink
dont set cursor every frame
Browse files Browse the repository at this point in the history
  • Loading branch information
Uriopass committed Jul 3, 2024
1 parent b2d7541 commit 7d26de0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
5 changes: 4 additions & 1 deletion engine/src/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ async fn run<S: State>(el: EventLoop<()>, window: Arc<Window>) {
});

ctx.gfx.finish_frame(enc);
ctx.gfx.window.set_cursor_icon(get_cursor_icon());
let (icon, changed) = get_cursor_icon();
if changed {
ctx.gfx.window.set_cursor_icon(icon);
}
ctx.input.end_frame();
ctx.times.total_cpu_time = last_update.elapsed().as_secs_f32();

Expand Down
13 changes: 9 additions & 4 deletions engine/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ use winit::platform::scancode::PhysicalKeyExtScancode;
use winit::window::CursorIcon;

lazy_static! {
static ref CURSOR_ICON: Arc<Mutex<CursorIcon>> = Arc::new(Mutex::new(CursorIcon::Default));
static ref CURSOR_ICON: Arc<Mutex<(CursorIcon, bool)>> =
Arc::new(Mutex::new((CursorIcon::Default, false)));
}

pub fn set_cursor_icon(icon: CursorIcon) {
*CURSOR_ICON.lock().unwrap() = icon;
let old = &mut *CURSOR_ICON.lock().unwrap();
*old = (icon, old.1 || (old.0 != icon));
}

pub fn get_cursor_icon() -> CursorIcon {
*CURSOR_ICON.lock().unwrap()
pub fn get_cursor_icon() -> (CursorIcon, bool) {
let v = &mut *CURSOR_ICON.lock().unwrap();
let to_ret = *v;
v.1 = false;
to_ret
}

#[derive(Default)]
Expand Down

0 comments on commit 7d26de0

Please sign in to comment.