1
0
Fork 0

macOS: remove runtime timer, use frame timer instead

This commit is contained in:
Joakim Frostegård 2020-11-29 16:23:58 +01:00
parent 1ea32123ed
commit 99fdbff4e2
2 changed files with 2 additions and 48 deletions

View file

@ -21,8 +21,7 @@ use crate::{
use crate::MouseEvent::{ButtonPressed, ButtonReleased};
use super::window::{
WindowState, WINDOW_STATE_IVAR_NAME, FRAME_TIMER_IVAR_NAME,
RUNTIME_TIMER_IVAR_NAME
WindowState, WINDOW_STATE_IVAR_NAME, FRAME_TIMER_IVAR_NAME
};
@ -70,10 +69,6 @@ unsafe fn create_view_class<H: WindowHandler>() -> &'static Class {
accepts_first_mouse::<H> as extern "C" fn(&Object, Sel, id) -> BOOL
);
class.add_method(
sel!(runtimeTick:),
runtime_tick::<H> as extern "C" fn(&Object, Sel, id)
);
class.add_method(
sel!(triggerOnFrame:),
trigger_on_frame::<H> as extern "C" fn(&Object, Sel, id)
@ -157,7 +152,6 @@ unsafe fn create_view_class<H: WindowHandler>() -> &'static Class {
class.add_ivar::<*mut c_void>(WINDOW_STATE_IVAR_NAME);
class.add_ivar::<*mut c_void>(FRAME_TIMER_IVAR_NAME);
class.add_ivar::<*mut c_void>(RUNTIME_TIMER_IVAR_NAME);
class.register()
}
@ -197,20 +191,8 @@ extern "C" fn trigger_on_frame<H: WindowHandler>(
WindowState::from_field(this)
};
state.trigger_frame();
}
extern "C" fn runtime_tick<H: WindowHandler>(
this: &Object,
_sel: Sel,
_event: id
){
let state: &mut WindowState<H> = unsafe {
WindowState::from_field(this)
};
state.handle_messages();
state.trigger_frame();
}
@ -231,12 +213,6 @@ extern "C" fn release<H: WindowHandler>(this: &Object, _sel: Sel) {
);
let _: () = msg_send![frame_timer_ptr as id, invalidate];
// Invalidate runtime timer
let frame_timer_ptr: *mut c_void = *this.get_ivar(
RUNTIME_TIMER_IVAR_NAME
);
let _: () = msg_send![frame_timer_ptr as id, invalidate];
// Drop WindowState
let state_ptr: *mut c_void = *this.get_ivar(
WINDOW_STATE_IVAR_NAME

View file

@ -31,7 +31,6 @@ use super::keyboard::KeyboardState;
pub(super) const WINDOW_STATE_IVAR_NAME: &str = "WINDOW_STATE_IVAR_NAME";
pub(super) const FRAME_TIMER_IVAR_NAME: &str = "FRAME_TIMER";
pub(super) const RUNTIME_TIMER_IVAR_NAME: &str = "RUNTIME_TIMER";
pub struct Window {
@ -222,27 +221,6 @@ impl Window {
)
}
// Setup runtime timer once window state is stored
unsafe {
let timer_interval = 0.01;
let selector = sel!(runtimeTick:);
let timer: id = msg_send![
::objc::class!(NSTimer),
scheduledTimerWithTimeInterval:timer_interval
target:window_state_arc.window.ns_view
selector:selector
userInfo:nil
repeats:YES
];
// Store pointer to timer for invalidation when view is released
(*window_state_arc.window.ns_view).set_ivar(
RUNTIME_TIMER_IVAR_NAME,
timer as *mut c_void,
)
}
crate::WindowHandle(WindowHandle {
message_tx
})