1
This commit is contained in:
parent
797e1d0184
commit
984d5c3acf
63
src/timer.rs
63
src/timer.rs
@ -1,6 +1,7 @@
|
|||||||
use std::rc::{Rc, Weak};
|
use std::rc::{Rc, Weak};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
|
use std::cmp;
|
||||||
|
|
||||||
const TVN_BITS: usize = 6;
|
const TVN_BITS: usize = 6;
|
||||||
const TVR_BITS: usize = 8;
|
const TVR_BITS: usize = 8;
|
||||||
@ -367,23 +368,58 @@ impl Timer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn fire_event(&mut self,
|
pub fn fire_event(&mut self,
|
||||||
_timer_wp: TimerWp,
|
timer_wp: TimerWp,
|
||||||
_e: i32,
|
e: TimerEvent,
|
||||||
_args: Option<Vec<Rc::<dyn Any>>>) {
|
args: Option<Vec<Rc::<dyn Any>>>) {
|
||||||
|
match timer_wp.upgrade() {
|
||||||
|
Some(t) => {
|
||||||
|
match &mut t.borrow_mut().cb {
|
||||||
|
Some(cb) => {
|
||||||
|
(*cb)(e, args);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn modify(&mut self, _timer_wp: TimerWp, _expire_time: i32) {
|
pub fn modify(&mut self, timer_wp: TimerWp, expire_time: i32) {
|
||||||
|
match timer_wp.upgrade() {
|
||||||
|
Some(_) => {
|
||||||
|
self.modify(timer_wp, expire_time);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete_current_timer(&mut self) {
|
pub fn delete_current_timer(&mut self) {
|
||||||
|
match self.running_timer.upgrade() {
|
||||||
|
Some(v) => {
|
||||||
|
self.internal_delete(Rc::downgrade(&v.borrow().wp), false);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_running(&self) {
|
pub fn is_running(&self) -> bool {
|
||||||
|
match self.running_timer.upgrade() {
|
||||||
|
Some(_) => {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete(&mut self, timer_wp: TimerWp) {
|
pub fn delete(&mut self, timer_wp: TimerWp) {
|
||||||
match timer_wp.upgrade() {
|
match timer_wp.upgrade() {
|
||||||
Some(v) => {
|
Some(_) => {
|
||||||
self.internal_delete(timer_wp, false);
|
self.internal_delete(timer_wp, false);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
@ -391,11 +427,16 @@ impl Timer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reset(&mut self, _timer_wp: TimerWp) {
|
pub fn get_remain_time(&mut self, timer_wp: TimerWp) -> i64 {
|
||||||
}
|
match timer_wp.upgrade() {
|
||||||
|
Some(t) => {
|
||||||
pub fn get_remain_time(&mut self, _timer_wp: TimerWp) -> i64 {
|
let remain_time = t.borrow().expires - (self.get_tick_count)();
|
||||||
return 0;
|
return cmp::max(remain_time, 0);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_idle_time(&self) -> i64 {
|
pub fn get_idle_time(&self) -> i64 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user