Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sound Listener ignores the autoRender property #7406

Open
LeXXik opened this issue Mar 5, 2025 · 8 comments
Open

Sound Listener ignores the autoRender property #7406

LeXXik opened this issue Mar 5, 2025 · 8 comments

Comments

@LeXXik
Copy link
Contributor

LeXXik commented Mar 5, 2025

I was looking at why we keep losing frame time in our app when the application is paused from rendering (hidden from view). We pause it using app.autoRender = false. However it looks like Sound Listener is ignoring the property, because its update is triggered before that, when application.update(dt) is called:

application.update(dt);
application.fire('framerender');
if (application.autoRender || application.renderNextFrame) {

Image

@LeXXik
Copy link
Contributor Author

LeXXik commented Mar 5, 2025

It is not technically rendering, but we want to stop any kind of application updates without destroying the app, as it is not in the view. Wish there would be some sort of a paused property guard at the very beginning of the tick function.

@mvaligursky
Copy link
Contributor

If we ship over the update part, the scripts would not execute, and it'd be tricky to wake up your application again. That would need some special callback maybe or something.

@LeXXik
Copy link
Contributor Author

LeXXik commented Mar 5, 2025

If we add AppBase.paused and return early here, then it would be a noop call. Not sure about scripts executing / waking up concern here. What would happen if the update is called after skipping say 100 frames?

if (!application.graphicsDevice || applicaiton.paused) { 
    return;
}

const makeTick = function (_app) {
const application = _app;
/**
* @param {number} [timestamp] - The timestamp supplied by requestAnimationFrame.
* @param {XRFrame} [frame] - XRFrame from requestAnimationFrame callback.
*/
return function (timestamp, frame) {
if (!application.graphicsDevice) {
return;
}

@mvaligursky
Copy link
Contributor

I mean, how would you set this AppBase.paused to true? Your scripts would not execute, so not from a script.

maybe we need call back at the start of tick, where you supply true of false to pause the current frame .. so this callback would execute always, the rest of the frame skipped based on what this evaluates to.

@LeXXik
Copy link
Contributor Author

LeXXik commented Mar 5, 2025

Ah, I see what you mean. Right, we don't do it from the application script assets, but externally.

@LeXXik
Copy link
Contributor Author

LeXXik commented Mar 5, 2025

Our app has multiple views. In some views, the app is only temporarily hidden. In such views we do need autoRender set to false, but still update the application, as it loads stuff while in background. In other views, the app would remain hidden and not going to show up at all - then we do need a noop tick. I am considering this workaround for now, let me know if I am missing something:

Image

@willeastcott
Copy link
Contributor

Doesn't requestAnimationFrame only get called when a canvas element is visible?

@Maksims
Copy link
Collaborator

Maksims commented Mar 5, 2025

Doesn't requestAnimationFrame only get called when a canvas element is visible?

No, as requestAnimationFrame is bound to window. It only stops triggering if the browser is minified or tab is hidden.

It is a valid case when Application needs to be completely paused, and usually it is an external need. With some callbacks and up to a user to wake it up in the way they feel needed.
Paused rendering - is useful for GPU heavy apps, such as configurators, we pause rendering, but keep update running and queue rendering frames when e.g. camera is rotated, and other cases.

While complete pause of application is useful for external needs, when whole app needs to be paused.
It is not a game pause - this is up to a dev to implement it on app logic level.

When app is paused, and then resumed, dt - can still be as is, as when app is paused, just an early return from rAF is sufficient, but rAF still needs to run. It is possible to implement it so rAF would be stopped, but that can create complications when it is resumed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants