Closed Tsmith18256 closed 7 years ago
We also might want to look into handling odd frame rate division.
There are two ways this could go.
It just rounds every time. EG: If the browser is rendering at 45 fps and you want something to update 30 times per second, this would cause it to either round up or down (since you are asking it to update every frame and a half). This will either lead to it rendering every frame (45 fps) or every second frame (~23 fps).
It tries to average out with modulus. EG: instead of comparing to the last time each bucket updated, the system could take the remainder of dividing the current time by seconds (only milliseconds matter). If we wanted to update a bucket 4 times per second (really low for simple example), we would wait until we pass 250 milliseconds and then update. It would remember it did that update and not do another until it reached 500 milliseconds, at which point it would repeat the process. In the example above (45 fps with 30 updates per second), this would lead to the object updating at the closest frames; it would update on the first frame, the third frame, the fourth frame, the sixth frame, etc. Making the following pattern (X = frame that updates): X_XX_XX_XX_XX_XX_XX_XX.
Neither solution seems great, but we need to figure something out.
Closing this issue, as we currently are not in immediate need of this. This could be re-opened in the future.
We should have a system where we can add a game object and say that it only needs to update every X milliseconds. We were leaning towards a buckets system for this.
Objects will still have to have
render
called every frame, or they will disappear! 😨 We could make the system callupdate
less often. Since the browsers seem to like multiples of 15 for framerates, maybe we should have 4 buckets: