@@ -224,6 +224,7 @@ struct Context {
224
224
quad_context : Box < dyn miniquad:: RenderingBackend > ,
225
225
226
226
textures : crate :: texture:: TexturesContext ,
227
+ update_on : conf:: UpdateTrigger ,
227
228
}
228
229
229
230
#[ derive( Clone ) ]
@@ -350,6 +351,7 @@ impl Context {
350
351
351
352
quad_context : ctx,
352
353
textures : crate :: texture:: TexturesContext :: new ( ) ,
354
+ update_on : Default :: default ( ) ,
353
355
}
354
356
}
355
357
@@ -554,7 +556,7 @@ impl EventHandler for Stage {
554
556
context. mouse_position = Vec2 :: new ( x, y) ;
555
557
}
556
558
557
- if miniquad :: window :: blocking_event_loop ( ) {
559
+ if context . update_on . mouse_down {
558
560
miniquad:: window:: schedule_update ( ) ;
559
561
}
560
562
}
@@ -573,7 +575,7 @@ impl EventHandler for Stage {
573
575
if !context. cursor_grabbed {
574
576
context. mouse_position = Vec2 :: new ( x, y) ;
575
577
}
576
- if miniquad :: window :: blocking_event_loop ( ) {
578
+ if context . update_on . mouse_up {
577
579
miniquad:: window:: schedule_update ( ) ;
578
580
}
579
581
}
@@ -639,7 +641,12 @@ impl EventHandler for Stage {
639
641
repeat,
640
642
} )
641
643
} ) ;
642
- if miniquad:: window:: blocking_event_loop ( ) {
644
+ if context
645
+ . update_on
646
+ . specific_key
647
+ . as_ref ( )
648
+ . map_or ( context. update_on . key_down , |keys| keys. contains ( & keycode) )
649
+ {
643
650
miniquad:: window:: schedule_update ( ) ;
644
651
}
645
652
}
@@ -655,7 +662,7 @@ impl EventHandler for Stage {
655
662
. for_each ( |arr| arr. push ( MiniquadInputEvent :: KeyUp { keycode, modifiers } ) ) ;
656
663
657
664
if miniquad:: window:: blocking_event_loop ( ) {
658
- miniquad:: window:: schedule_update ( ) ;
665
+ // miniquad::window::schedule_update();
659
666
}
660
667
}
661
668
@@ -755,6 +762,36 @@ impl EventHandler for Stage {
755
762
}
756
763
}
757
764
765
+ pub mod conf {
766
+ #[ derive( Default , Debug ) ]
767
+ pub struct UpdateTrigger {
768
+ pub resize : bool ,
769
+ pub key_down : bool ,
770
+ pub mouse_down : bool ,
771
+ pub mouse_up : bool ,
772
+ pub specific_key : Option < Vec < crate :: KeyCode > > ,
773
+ }
774
+
775
+ #[ derive( Default , Debug ) ]
776
+ pub struct Conf {
777
+ pub miniquad_conf : miniquad:: conf:: Conf ,
778
+ /// With miniquad_conf.platform.blocking_event_loop = true,
779
+ /// next_frame().await will never finish and will wait forever with
780
+ /// zero CPU usage.
781
+ /// update_on will tell macroquad when to proceed with the event loop.
782
+ pub update_on : Option < UpdateTrigger > ,
783
+ }
784
+ }
785
+
786
+ impl From < miniquad:: conf:: Conf > for conf:: Conf {
787
+ fn from ( conf : miniquad:: conf:: Conf ) -> conf:: Conf {
788
+ conf:: Conf {
789
+ miniquad_conf : conf,
790
+ update_on : None ,
791
+ }
792
+ }
793
+ }
794
+
758
795
/// Not meant to be used directly, only from the macro.
759
796
#[ doc( hidden) ]
760
797
pub struct Window { }
@@ -763,21 +800,30 @@ impl Window {
763
800
pub fn new ( label : & str , future : impl Future < Output = ( ) > + ' static ) {
764
801
Window :: from_config (
765
802
conf:: Conf {
766
- window_title : label. to_string ( ) ,
767
- //high_dpi: true,
803
+ miniquad_conf : miniquad:: conf:: Conf {
804
+ window_title : label. to_string ( ) ,
805
+ //high_dpi: true,
806
+ ..Default :: default ( )
807
+ } ,
768
808
..Default :: default ( )
769
809
} ,
770
810
future,
771
811
) ;
772
812
}
773
813
774
- pub fn from_config ( config : conf:: Conf , future : impl Future < Output = ( ) > + ' static ) {
775
- miniquad:: start ( config, move || {
814
+ pub fn from_config ( config : impl Into < conf:: Conf > , future : impl Future < Output = ( ) > + ' static ) {
815
+ let conf:: Conf {
816
+ miniquad_conf,
817
+ update_on,
818
+ } = config. into ( ) ;
819
+ miniquad:: start ( miniquad_conf, move || {
776
820
thread_assert:: set_thread_id ( ) ;
777
821
unsafe {
778
822
MAIN_FUTURE = Some ( Box :: pin ( future) ) ;
779
823
}
780
- unsafe { CONTEXT = Some ( Context :: new ( ) ) } ;
824
+ let mut context = Context :: new ( ) ;
825
+ context. update_on = update_on. unwrap_or_default ( ) ;
826
+ unsafe { CONTEXT = Some ( context) } ;
781
827
782
828
Box :: new ( Stage { } )
783
829
} ) ;
0 commit comments