1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#![doc(html_logo_url = "https://rin.rs/logo.svg")]
#![doc(html_favicon_url = "https://rin.rs/favicon.ico")]
pub use lazy_value::Lazy;
pub use autoloader::AutoLoader;
pub use value_cache::*;
pub use error::Error;
pub use error::Result;
mod lazy_value;
pub mod autoloader;
pub mod idtree;
mod value_cache;
mod error;
pub fn ns_to_s(ns: u64) -> f64{
(ns as f64) / 1000000000.0
}
pub fn s_to_ns(s: f64) -> u64{
(s * 1000000000.0) as u64
}
pub fn calc_fps(curr_time: u64, prev_time: u64, frames: u64) -> f64{
frames as f64 / ns_to_s(curr_time - prev_time)
}
#[macro_export]
macro_rules! to_c_str{
($string: expr) => (
{
use std::ffi::CString;
CString::new($string).unwrap().as_ptr()
}
);
}
#[macro_export]
macro_rules! from_c_str{
($c_string: expr) => (
{
use std::ffi::CStr;
use std::str;
str::from_utf8(CStr::from_ptr($c_string).to_bytes()).unwrap()
}
);
}
#[macro_export]
macro_rules! time{
($descr: expr, $func: block) => (
{
use time;
let then = time::precise_time_ns() as f32/1000000f32;
let ret = $func;
let now = time::precise_time_ns() as f32/1000000f32;
println!("{} time: {}ms", $descr, now - then);
ret
}
);
}
#[macro_export]
macro_rules! time_ns{
($descr: expr, $func: block) => (
{
use time;
let then = time::precise_time_ns();
let ret = $func;
let now = time::precise_time_ns();
println!("{} time: {}ns", $descr, now - then);
ret
}
);
}
#[macro_export]
macro_rules! dont_time{
($descr: expr, $func: block) => ( $func );
}