Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

I'm having an issue whenever I unfocus the tab where my game is running, units spreading across the map randomly. But when I focus the tab again they start to get to their position again.

I have it very exaggerated, but the demo also has the problem.

Just after focusing
image

After some time
image

You must be logged in to vote

Replies: 1 comment · 6 replies

Comment options

Hi @FrameMuse, I believe this issue is caused by calling crowd.update with a large delta time.

This should be addressed (in the examples too!) by either, clamping the delta time to some value, e.g. Math.min(delta, 0.1), or by pausing calling update based on page visibility.

You must be logged in to vote
6 replies
@isaac-mason
Comment options

Hey @FrameMuse, some combination of clamping the delta time and the page visibility API sounds like a good idea.

Calling crowdAgent.resetMoveTarget when the agent is sufficiently close to the target may help with this situation too.

You could also try doing fixed time stepping with interpolation. This would mean in the worst case where the visibility API doesn't work correctly multiple stable fixed sized steps would be performed.

See the "Fixed time stepping with interpolation" section in the readme 🙂

@GGAlanSmithee
Comment options

I whish Chromium would allow you to run RAF in a non-focused tab. I understand the reason to not, but they could allow it behind user consent (like audio, etc). In my experience, it is very hard to get this perfect without it, because there will always be some form of discrepancy when re-focusing.

In theory, you could override / create your own RAF which is paused/unpaused when unfocusing/focusing, but as you point out yourself, it's not 100% reliable, and practically impossible to monkey patch third party packages, like for exampl r3f's useFrame, etc.

Electron does allow for this with backgroundThrottling: false, but this is unfortunately not possible in a pure web context.

@FrameMuse
Comment options

@isaac-mason Yes, I investigated this approach just before you mentioned it. It seems it makes it MUCH reliable.

Thanks @GGAlanSmithee for inspiration, now I'd like to experiment with background-sync, Service Workers and Web Workers to see if I can run the game there smoothly there. Or at least dedicate some logic of synchronization there (not sure though, that's just an idea).

I will share everything when I finish with all my investigations.

@GGAlanSmithee
Comment options

Nice @FrameMuse!

Just to add to the discussion, I have done some experiments with using Web Workers in the context of three.js and recast-navigation, but often the overhead of passing buffers and other information back and forth negates most of the potential wins. However, I didn't really do a deep enough dive for anything conclusive, so would be nice to see what you come up with!

@GGAlanSmithee
Comment options

I recently had a very positive experience moving some navigation mesh creating code over to a worker (copied from one of the examples), as I explained here: #405

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #392 on June 23, 2024 01:57.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.