davethomas11 / V_Is_For_Vince

1 stars 0 forks source link

Add system for low update rates #15

Closed Tsmith18256 closed 7 years ago

Tsmith18256 commented 7 years ago

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 call update less often. Since the browsers seem to like multiples of 15 for framerates, maybe we should have 4 buckets:

  1. Update 15 times per second
  2. Update 30 times per second
  3. Update 45 times per second
  4. Update every frame (once we are at 60, no reason for more buckets)
Tsmith18256 commented 7 years ago

We also might want to look into handling odd frame rate division.

There are two ways this could go.

  1. 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).

  2. 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.

davethomas11 commented 7 years ago

Closing this issue, as we currently are not in immediate need of this. This could be re-opened in the future.