Fix high CPU usage issue with emscripten demos.

This commit is contained in:
Martín Lucas Golini
2022-10-16 19:39:16 -03:00
parent 4b6ce692b9
commit 2d53c07c4b
6 changed files with 19 additions and 6 deletions

View File

@@ -116,7 +116,8 @@ if ( SceneManager::instance()->getUISceneNode()->invalidated() ) {
// Display the scene to the screen.
win->display();
} else {
Sys::sleep( Milliseconds( 8 ) );
// For for an input event or timeout after 16ms if has focus, otherwise wait 100ms.
win->getInput()->waitEvent( Milliseconds( win->hasFocus() ? 16 : 100 ) );
}
```

View File

@@ -23,9 +23,13 @@ void mainLoop() {
// Redraw the UI scene.
SceneManager::instance()->draw();
// Display the scene to the screen.
win->display();
} else {
Sys::sleep( Milliseconds( 8 ) );
#if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN
// For for an input event or timeout after 16ms if has focus, otherwise wait 100ms.
win->getInput()->waitEvent( Milliseconds( win->hasFocus() ? 16 : 100 ) );
#endif
}
}

View File

@@ -478,7 +478,9 @@ void App::mainLoop() {
firstFrame = false;
}
} else {
#if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN
mWindow->getInput()->waitEvent( Milliseconds( mWindow->hasFocus() ? 16 : 100 ) );
#endif
}
if ( mBenchmarkMode && mSecondsCounter.getElapsedTime() >= Seconds( 1 ) ) {

View File

@@ -69,7 +69,9 @@ void mainLoop() {
win->display();
} else {
Sys::sleep( Milliseconds( 8 ) );
#if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN
win->getInput()->waitEvent( Milliseconds( win->hasFocus() ? 16 : 100 ) );
#endif
}
}
@@ -91,7 +93,7 @@ EE_MAIN_FUNC int main( int, char*[] ) {
if ( win->isOpen() ) {
PixelDensity::setPixelDensity( eemax( win->getScale(), pixelDensity ) );
win->setCloseRequestCallback( cb::Make1( onCloseRequestCallback ) );
win->setCloseRequestCallback( onCloseRequestCallback );
UISceneNode* uiSceneNode = UISceneNode::New();

View File

@@ -69,7 +69,9 @@ void mainLoop() {
win->display();
} else {
Sys::sleep( Milliseconds( 8 ) );
#if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN
win->getInput()->waitEvent( Milliseconds( win->hasFocus() ? 16 : 100 ) );
#endif
}
}
@@ -91,7 +93,7 @@ EE_MAIN_FUNC int main( int, char*[] ) {
if ( win->isOpen() ) {
PixelDensity::setPixelDensity( eemax( win->getScale(), pixelDensity ) );
win->setCloseRequestCallback( cb::Make1( onCloseRequestCallback ) );
win->setCloseRequestCallback( onCloseRequestCallback );
UISceneNode* uiSceneNode = UISceneNode::New();

View File

@@ -937,7 +937,9 @@ void App::mainLoop() {
mWindow->display();
} else {
#if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN
mWindow->getInput()->waitEvent( Milliseconds( mWindow->hasFocus() ? 16 : 100 ) );
#endif
}
}