@@ -24,53 +24,6 @@ mod shaders {
2424 include ! ( concat!( env!( "OUT_DIR" ) , "/entry_points.rs" ) ) ;
2525}
2626
27- /// Abstraction for getting timestamps even when `std::time` isn't supported.
28- enum PortableInstant {
29- #[ cfg( not( target_arch = "wasm32" ) ) ]
30- Native ( std:: time:: Instant ) ,
31-
32- #[ cfg( target_arch = "wasm32" ) ]
33- Web {
34- performance_timestamp_ms : f64 ,
35-
36- // HACK(eddyb) cached `window().performance()` to speed up/simplify `elapsed`.
37- cached_window_performance : web_sys:: Performance ,
38- } ,
39- }
40-
41- impl PortableInstant {
42- fn now ( ) -> Self {
43- #[ cfg( not( target_arch = "wasm32" ) ) ]
44- {
45- Self :: Native ( std:: time:: Instant :: now ( ) )
46- }
47- #[ cfg( target_arch = "wasm32" ) ]
48- {
49- let performance = web_sys:: window ( )
50- . expect ( "missing window" )
51- . performance ( )
52- . expect ( "missing window.performance" ) ;
53- Self :: Web {
54- performance_timestamp_ms : performance. now ( ) ,
55- cached_window_performance : performance,
56- }
57- }
58- }
59-
60- fn elapsed_secs_f32 ( & self ) -> f32 {
61- match self {
62- #[ cfg( not( target_arch = "wasm32" ) ) ]
63- Self :: Native ( instant) => instant. elapsed ( ) . as_secs_f32 ( ) ,
64-
65- #[ cfg( target_arch = "wasm32" ) ]
66- Self :: Web {
67- performance_timestamp_ms,
68- cached_window_performance,
69- } => ( ( cached_window_performance. now ( ) - performance_timestamp_ms) / 1000.0 ) as f32 ,
70- }
71- }
72- }
73-
7427fn mouse_button_index ( button : MouseButton ) -> usize {
7528 match button {
7629 MouseButton :: Left => 0 ,
@@ -243,7 +196,7 @@ async fn run(
243196 compiled_shader_modules,
244197 ) ;
245198
246- let start = PortableInstant :: now ( ) ;
199+ let start = web_time :: Instant :: now ( ) ;
247200
248201 let ( mut cursor_x, mut cursor_y) = ( 0.0 , 0.0 ) ;
249202 let ( mut drag_start_x, mut drag_start_y) = ( 0.0 , 0.0 ) ;
@@ -363,7 +316,7 @@ async fn run(
363316 ..Default :: default ( )
364317 } ) ;
365318
366- let time = start. elapsed_secs_f32 ( ) ;
319+ let time = start. elapsed ( ) . as_secs_f32 ( ) ;
367320 for ( i, press_time) in mouse_button_press_time. iter_mut ( ) . enumerate ( ) {
368321 if ( mouse_button_press_since_last_frame & ( 1 << i) ) != 0 {
369322 * press_time = time;
0 commit comments