-
-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Further fixes and improvements related to WebAssembly (#9444)
- Loading branch information
1 parent
6f55a58
commit 2498a89
Showing
12 changed files
with
136 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/*************************************************************************** | ||
* fheroes2: https://github.com/ihhub/fheroes2 * | ||
* Copyright (C) 2019 - 2024 * | ||
* Copyright (C) 2019 - 2025 * | ||
* * | ||
* Free Heroes2 Engine: http://sourceforge.net/projects/fheroes2 * | ||
* Copyright (C) 2008 by Andrey Afletdinov <[email protected]> * | ||
|
@@ -1237,16 +1237,19 @@ bool LocalEvent::HandleEvents( const bool sleepAfterEventProcessing, const bool | |
|
||
renderRoi = fheroes2::getBoundaryRect( renderRoi, _mouseCursorRenderArea ); | ||
|
||
static_assert( globalLoopSleepTime == 1, "Since you have changed the sleep time, make sure that the sleep does not last too long." ); | ||
|
||
if ( sleepAfterEventProcessing ) { | ||
if ( renderRoi != fheroes2::Rect() ) { | ||
display.render( renderRoi ); | ||
} | ||
|
||
#ifndef __EMSCRIPTEN__ | ||
// Make sure not to delay any further if the processing time within this function was more than the expected waiting time. | ||
if ( eventProcessingTimer.getMs() < globalLoopSleepTime ) { | ||
static_assert( globalLoopSleepTime == 1, "Make sure that you sleep for the difference between times since you change the sleep time." ); | ||
EventProcessing::EventEngine::sleep( globalLoopSleepTime ); | ||
} | ||
#endif | ||
} | ||
else { | ||
// Since rendering is going to be just after the call of this method we need to update rendering area only. | ||
|
@@ -1255,6 +1258,14 @@ bool LocalEvent::HandleEvents( const bool sleepAfterEventProcessing, const bool | |
} | ||
} | ||
|
||
#ifdef __EMSCRIPTEN__ | ||
// When a WebAssembly app is running in a browser, the sleep time is used to perform various "background" operations on the main thread (such | ||
// as feeding the audio streams) by yielding to the browser's event loop using the Emscripten Asyncify mechanism. Therefore, it is preferable | ||
// to always force the main thread to fall asleep, otherwise, for example, the following deadlock is possible: the main thread waits in a loop | ||
// for an audio playback to finish, but it never finishes because new chunks are not feeded to it, because the main thread never goes to sleep. | ||
EventProcessing::EventEngine::sleep( globalLoopSleepTime ); | ||
#endif | ||
|
||
return true; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/*************************************************************************** | ||
* fheroes2: https://github.com/ihhub/fheroes2 * | ||
* Copyright (C) 2019 - 2024 * | ||
* Copyright (C) 2019 - 2025 * | ||
* * | ||
* Free Heroes2 Engine: http://sourceforge.net/projects/fheroes2 * | ||
* Copyright (C) 2009 by Andrey Afletdinov <[email protected]> * | ||
|
@@ -489,16 +489,18 @@ void Interface::StatusPanel::TimerEventProcessing() | |
|
||
void Interface::StatusPanel::drawAITurnProgress( const uint32_t progressValue ) | ||
{ | ||
// Even if there is no need to draw anything, we still need to pump the event queue to | ||
// update the position of the software-emulated mouse cursor, feed the music player by | ||
// another music chunk on some platforms (e.g. WebAssembly), etc. | ||
LocalEvent::Get().HandleEvents( false ); | ||
|
||
const bool updateProgress = ( progressValue != _aiTurnProgress ); | ||
const bool isMapAnimation = Game::validateAnimationDelay( Game::MAPS_DELAY ); | ||
|
||
if ( !updateProgress && !isMapAnimation ) { | ||
return; | ||
} | ||
|
||
// Process events if any before rendering a frame. For instance, updating a mouse cursor position. | ||
LocalEvent::Get().HandleEvents( false ); | ||
|
||
if ( updateProgress ) { | ||
if ( progressValue == 0 ) { | ||
// If turn progress is just started start the grain animation from the beginning. | ||
|