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

Compensate for time drift, for when window is backgrounded #30

Open
ajmas opened this issue Dec 19, 2023 · 1 comment
Open

Compensate for time drift, for when window is backgrounded #30

ajmas opened this issue Dec 19, 2023 · 1 comment

Comments

@ajmas
Copy link
Owner

ajmas commented Dec 19, 2023

In order to reduce the CPU load, the SatCrunchWorker is paused when the "StuffInSpace" window is backgrounded. The side effect of this, is that when the SatCrunchWorker is unpaused there will be a time drift.

We should add logic to address this issues. Likely, basing this on the time delta between pause and unpaused time.

@thkruz
Copy link

thkruz commented Dec 19, 2023

I don't think you need to figure out the time delta, just get the current time and resync with the worker.

If the delta between drawing frames is more than 500ms (definitely more elegant solutions later) then resync times. If the main thread realizes it hasn't been drawing frames then it passes the current time to the worker. When received by the worker it immediately stops the current propagation loop, syncs its current time, and then restarts the propagation. If you are only interested in running real-time, then you can just pass a boolean and have the worker make a new date object.

It is important that it stops propagation and restarts because there is no time element in the position/velocity buffers so they all need to be aligned to the same reference time.

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

2 participants