@@ -33,8 +33,7 @@ export default class WebPlatform {
3333 // Alternative handler to avoid RAF when idle
3434 this . _loopHandler = null ;
3535 this . _idleLoopCounter = 0 ;
36- this . _idleLoopDelay = 60 ;
37- this . _onIdle = false ;
36+ this . _idleLoopDelay = 30 ;
3837
3938 if ( this . stage . getOption ( "useImageWorker" ) ) {
4039 if ( ! window . createImageBitmap || ! window . Worker ) {
@@ -52,6 +51,7 @@ export default class WebPlatform {
5251 this . _imageWorker . destroy ( ) ;
5352 }
5453
54+ this . _looping = false ;
5555 clearInterval ( this . _loopHandler ) ;
5656
5757 this . _removeKeyHandler ( ) ;
@@ -75,44 +75,41 @@ export default class WebPlatform {
7575 this . _looping = false ;
7676 }
7777
78- switchLoop ( ) {
79- if ( this . _onIdle === false ) {
80- this . _onIdle = true ;
81- this . stage . onIdle ( ) ;
82- }
83-
84- if ( this . _idleLoopCounter < this . _idleLoopDelay ) {
85- this . _idleLoopCounter ++ ;
86- return ;
87- }
88- if ( ! this . stage . ctx . hasRenderUpdates ( ) ) {
89- this . stopLoop ( ) ;
90- this . _loopHandler = setInterval ( ( ) => {
91- this . stage . updateFrame ( ) ;
92- this . stage . idleFrame ( ) ;
93- if ( this . stage . ctx . hasRenderUpdates ( ) ) {
94- clearInterval ( this . _loopHandler ) ;
95- this . startLoop ( ) ;
96- } ;
97- } , 1000 / 60 ) ;
98- } else {
78+ switchLoop ( hasChanges ) {
79+ if ( hasChanges ) {
9980 this . _idleLoopCounter = 0 ;
81+ return false ;
10082 }
83+ if ( ++ this . _idleLoopCounter < this . _idleLoopDelay ) {
84+ return false ;
85+ }
86+
87+ this . stopLoop ( ) ;
88+ this . _loopHandler = setInterval ( ( ) => {
89+ this . stage . updateFrame ( ) ;
90+ const hasChanges = this . stage . renderFrame ( ) ;
91+ if ( hasChanges ) {
92+ clearInterval ( this . _loopHandler ) ;
93+ this . startLoop ( ) ;
94+ }
95+ } , 1000 / 30 ) ;
96+
97+ this . stage . onIdle ( ) ;
98+ return true ;
10199 }
102100
103101 loop ( ) {
104- let self = this ;
105- let lp = function ( ) {
106- self . _awaitingLoop = false ;
107- self . _onIdle = false ;
108- if ( self . _looping ) {
109- self . stage . updateFrame ( ) ;
110- if ( self . stage . getOption ( "pauseRafLoopOnIdle" ) ) {
111- self . switchLoop ( ) ;
102+ const pauseRafLoopOnIdle = this . stage . getOption ( "pauseRafLoopOnIdle" ) ;
103+ const lp = ( ) => {
104+ this . _awaitingLoop = false ;
105+ if ( this . _looping ) {
106+ this . stage . updateFrame ( ) ;
107+ const hasChanges = this . stage . renderFrame ( ) ;
108+ if ( pauseRafLoopOnIdle && this . switchLoop ( hasChanges ) ) {
109+ return ;
112110 }
113- self . stage . renderFrame ( ) ;
114111 requestAnimationFrame ( lp ) ;
115- self . _awaitingLoop = true ;
112+ this . _awaitingLoop = true ;
116113 }
117114 }
118115 requestAnimationFrame ( lp ) ;
0 commit comments